fix: do not expose internal error details to clients#1851
Open
lexwhiting wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix: do not expose internal error details to clients#1851lexwhiting wants to merge 1 commit intomodelcontextprotocol:mainfrom
lexwhiting wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
…tocol#1429) Tool handlers that throw unhandled errors now return a generic "Internal error" message instead of leaking the raw error.message to the client. This prevents exposing stack traces, connection strings, internal hostnames, or other sensitive information. - Add ToolError class for intentional client-visible errors - Add McpServerOptions.onToolError callback for server-side logging - ProtocolError messages (validation, invalid params) remain visible - Generic Error/unknown exceptions are sanitized to "Internal error" Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1429. Tool handlers that throw unhandled errors now return a generic "Internal error" message instead of leaking the raw
error.messageto the client.Before: Any thrown error (including stack traces, connection strings, internal hostnames) was serialized and sent to the client as a
CallToolResultwithisError: true.After:
ToolError— a new error class for intentional client-visible messages. Thrownew ToolError('Invalid input: ...')and the message is returned to the client.ProtocolError— SDK-internal errors (validation, invalid params) remain visible, as they contain no sensitive information."Internal error". The real error is passed to an optionalonToolErrorcallback for server-side logging.Changes
ToolErrorclass exported from@modelcontextprotocol/serverMcpServerOptionsinterface with optionalonToolErrorcallbacktools/callhandler to sanitize unhandled errors"Internal error"instead of raw messagesUsage
Test plan
ToolErrormessages are returned to the clientToolErrorexceptions return "Internal error" and triggeronToolErrorcallbackProtocolError) still return descriptive messagesUrlElicitationRequiredErrorstill re-throws correctly