Classify the error first
This distinction matters. Protocol errors indicate that the MCP message itself cannot be processed. Tool execution errors describe a failure that the model may be able to correct.
Return actionable tool errors
An expected operation failure should normally return a tool result that explains the safe next step:- What failed
- Which input or state caused it
- Whether retrying is useful
- A safe corrective action
Use protocol errors correctly
Standard JSON-RPC errors include:
Use these for failures at the protocol layer. For example, an unknown MCP method is a protocol error. Invalid business input passed to a known tool is usually a tool execution error.
Preserve a private diagnostic record
Return a safe message to the client and log the detailed failure internally:Follow a repeatable debugging workflow
- Reproduce the smallest failing request.
- Confirm the server process or remote endpoint is reachable.
- Inspect the
initializeexchange and negotiated capabilities. - Test the server with MCP Inspector.
- Check client, server, and upstream logs using one correlation ID.
- Identify whether the failure is protocol, transport, auth, execution, or dependency related.
- Add a regression test before fixing the behavior.
- Retest in the target MCP client.
Common connection failures
The local server does not start
Check:- The command and executable exist.
- File paths are absolute.
- The working directory is not assumed.
- Required environment variables are present.
- The server has permission to access required files.
- Dependencies are installed for the correct runtime.
stdio, never write ordinary logs to stdout. Use stderr.
The client connects but sees no tools
Check:- The server declared the
toolscapability. tools/listreturns valid JSON-RPC.- Tool schemas are valid JSON Schema objects.
- Tool names are unique.
- Client and server protocol versions are compatible.
- A startup exception did not stop tool registration.
A remote server disconnects
Check HTTP status codes, TLS, proxy timeouts,Origin validation, session identifiers, authentication expiry, SSE handling, and load-balancer affinity if session state is local.
Debug authentication and authorization
Separate identity failures from permission failures:- Authentication: Who is the caller?
- Authorization: May that caller perform this operation on this object?
Handle upstream API failures
Normalize upstream behavior into stable MCP errors:
Retry only operations that are safe to repeat. Use idempotency keys for supported write operations.
Prevent error loops
Models may repeatedly retry a tool when its error is vague. To prevent loops:- Say when retrying with the same input will not work.
- Return field-specific validation guidance.
- Include rate-limit timing when safe.
- Limit retries at the server and upstream client.
- Use stable error categories for client policy.
- Require fresh confirmation before retrying a sensitive write.
Use 0mcp logs during debugging
For hosted 0mcp servers, review Logs to trace calls from generated tools to the upstream API. Use the Playground to reproduce a failure with controlled input. If a newly published configuration introduces failures, compare it with the previous version and use version rollback when needed.Debugging checklist
- Failure reproduced with a minimal request
- Error class identified
- Initialization and capability negotiation checked
- Client, server, and upstream logs correlated
- Sensitive data removed from logs and responses
- Retry behavior reviewed for side effects
- Root cause covered by a regression test
- Fix verified in Inspector and a target client