Use these patterns to keep Redop errors predictable for both clients and server operators.Documentation Index
Fetch the complete documentation index at: https://redop.useagents.site/docs/llms.txt
Use this file to discover all available pages before exploring further.
Where errors can happen
In Redop, failures usually come from two stages:- server setup and registration
- request-time execution
- invalid tool names
- invalid prompt names
- invalid resource URIs
- duplicate tool, prompt, or resource registrations
- input schema validation
- middleware
- the tool handler
- resource and prompt handlers
- auth and rate-limit plugins
What Redop does by default
- registration-time validation throws immediately and stops startup unless you catch it
- tool input validation runs before the handler
- tool input validation failures are returned as MCP tool errors with
isError: true - errors from middleware or the handler trigger
onError(...) - errors thrown inside local
after(...)hooks andonAfterHandle(...)are isolated so the successful result can still complete - errors thrown inside
afterResponse(...)hooks are isolated and cannot affect the already-sent response
Registration errors fail fast
Redop validates tool names, prompt names, group prefixes, and resource URIs when you register them. That means these errors are normal JavaScript errors thrown during setup, not request-time MCP responses.Validation errors are returned as tool errors
For tool calls, Redop validatesinputSchema before the handler runs.
If validation fails:
- the handler does not run
- Redop wraps the failure with the tool name
- the transport returns a tool error payload with
isError: true
search_docs without query, Redop returns a tool error result rather than crashing the server.
A typical message looks like:
Log failures with onError(...)
Use onError(...) when you want one place to observe failures across the server.
Throw clear errors from handlers
Prefer direct, specific error messages over vague messages like"failed".
Treat validation errors as input problems
Schema validation runs before the handler. If validation fails, Redop throws a validation error and the handler does not run. That means:- keep schema rules close to the tool definition
- use clear field names and constraints
- avoid repeating the same validation logic inside the handler unless the rule depends on external state
if checks when the rule is about input shape, required fields, string length, number ranges, or enum membership.
For registration-time naming problems, Redop throws direct setup errors such as:
Use middleware for policy errors
Middleware is the right place for:- auth failures
- rate limits
- tenant checks
- request-shape guards that depend on context
Use McpError when you need explicit protocol codes
Redop exports McpError and McpErrorCode when you need a specific MCP-style error code.
McpError. Redop already turns schema failures into tool error results in the MCP response flow.
Keep after hooks side-effect-safe
Localafter(...) hooks and onAfterHandle(...) run after a successful handler result. If they throw, Redop reports that failure to error hooks but still lets the original successful result complete.
That makes after hooks a good place for:
- analytics
- logging
- non-critical notifications
Use after-response hooks for post-response work
UseafterResponse(...) on a tool, resource, or prompt, or onAfterResponse(...) globally, when the work should happen after Redop has already written the response.
That makes them a good fit for:
- analytics
- logging
- impressions
- metrics
- audit events
afterResponse(...)cannot replace the client result- failures inside
afterResponse(...)do not change the client response - Redop still reports those failures to error hooks when possible
Practical rules
- let registration validation catch broken names and resource URIs early
- validate shape in schemas
- enforce policy in middleware
- throw specific application errors in handlers
- use
onError(...)for shared logging and observability - keep after hooks non-critical