fix: set isError on failed API calls - #334
Open
AlexRixten wants to merge 1 commit into
Open
Conversation
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.
Problem
When a Notion API call fails, the tool result carries the error in its text content but leaves
isErrorunset. Per the MCP schema, an unsetisErroris "assumed to be false (the call was successful)" — so a client that branches onisErrortreats the failure as a success and parses the error body as if it were data.Calling
API-retrieve-a-pagewith a valid but nonexistent UUID (authenticated,@notionhq/notion-mcp-server@2.4.1) returns:{ "content": [ { "type": "text", "text": "{\"status\":404,\"object\":\"error\",\"code\":\"object_not_found\",\"message\":\"Could not find page with ID: …\"}" } ] }No isError field. The server already knows the call failed — it has the 404, it labels the payload "object": "error", and it writes a helpful message. Only the protocol-level signal is missing.
This is not specific to object_not_found; it is the shared HttpClientError path. Probing the 12 read-only tools: with a valid token, 10 return validation_error / object_not_found this way; with no token, all 12 return unauthorized the same way. The two that behave correctly (API-get-self, API-get-users) are the ones that genuinely succeeded.
Fix
Set isError: true on the result returned from the HttpClientError branch in MCPProxy. The text content is unchanged — it is useful and well-formed; this only adds the missing flag.
The spec (https://modelcontextprotocol.io/specification/2025-06-18/server/tools#error-handling) classifies API failures, invalid input data, and business logic errors as Tool Execution Errors, reported in the result with isError: true. The schema gives the reason: errors originating from the tool SHOULD be reported this way, "otherwise, the LLM would not be able to see that an error occurred and self-correct."
Verification
Added a unit test covering the HttpClientError path (isError: true, error body preserved). Full suite passes: 110 tests, 12 files.
End to end against the built server, probing every read-only tool without a token: