Skip to content

fix: set isError on failed API calls - #334

Open
AlexRixten wants to merge 1 commit into
makenotion:mainfrom
AlexRixten:fix/set-iserror-on-failed-api-call
Open

fix: set isError on failed API calls#334
AlexRixten wants to merge 1 commit into
makenotion:mainfrom
AlexRixten:fix/set-iserror-on-failed-api-call

Conversation

@AlexRixten

@AlexRixten AlexRixten commented Jul 22, 2026

Copy link
Copy Markdown

Problem

When a Notion API call fails, the tool result carries the error in its text content but leaves isError unset. Per the MCP schema, an unset isError is "assumed to be false (the call was successful)" — so a client that branches on isError treats the failure as a success and parses the error body as if it were data.

Calling API-retrieve-a-page with 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:

  • before: 12 tools return an error body flagged as success
  • after: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant