Skip to content

fix(mcp): report SDK errors to MCP clients instead of a generic message - #2524

Open
acodercat wants to merge 2 commits into
opensandbox-group:mainfrom
acodercat:fix/mcp-sdk-errors-as-tool-errors
Open

acodercat wants to merge 2 commits into
opensandbox-group:mainfrom
acodercat:fix/mcp-sdk-errors-as-tool-errors

Conversation

@acodercat

Copy link
Copy Markdown
Contributor

On MCP 2.x, a tool that raises anything other than ToolError is reported to the client as just Error executing tool <name>, with no detail. ee9630b ("preserve expected tool errors on MCP 2.x") wrapped the server's own validation failures in ToolError for that reason. But the errors that come from the OpenSandbox SDK were left as they were, and those are the most common expected failures: a sandbox that doesn't exist, a rejected API key, a failed connect.

On current main, sandbox_kill for a sandbox the server reports as missing (SandboxApiException("Sandbox sbx-missing not found", status_code=404)) returns is_error=True with only Error executing tool sandbox_kill. The same happens for every other tool, so an agent using the MCP server can't tell a missing sandbox from an auth problem or a bug.

Summary

  • The shared tool() decorator wraps each tool and converts a SandboxException into ToolError(str(exc)), chaining the original. Every tool reports the SDK message the same way, including connect failures from connect_if_missing.
  • Exceptions that are not SDK errors are still reported with the generic message, as MCP 2.x intends for unexpected failures. A ToolError raised by a tool passes through unchanged.
  • The wrapper uses functools.wraps. The tools/list output (names, input and output schemas) is byte-for-byte the same as on main, and Context injection still works.

Testing

  • Not run (explain why)

  • Unit tests

  • Integration tests

  • e2e / manual verification

  • New test_mcp2_sandbox_errors_keep_actionable_message, at the protocol level: sandbox_kill with a manager that raises SandboxApiException(..., 404) must return an error result containing Sandbox sbx-missing not found. It fails on current main with Error executing tool sandbox_kill.

  • Compared the tools/list dump with and without the change: identical.

  • All MCP tests pass (27 passed). ruff is clean, and pyright reports the same 3 existing errors as on main.

Breaking Changes

  • None
  • Yes (describe impact and migration path)

Checklist

  • Linked Issue or clearly described motivation
  • Added/updated docs (if needed)
  • Added/updated tests (if needed)
  • Security impact considered
  • Backward compatibility considered

ee9630b wrapped the server's own validation failures in ToolError so
MCP 2.x clients see their message. Errors raised by the OpenSandbox SDK
were left as they were, and MCP 2.x reports any exception other than
ToolError as just "Error executing tool <name>". A missing sandbox, a
rejected API key or a failed connect all looked the same to the client.

Convert SandboxException to ToolError in the shared tool decorator, so
every tool reports the SDK message. Other exceptions are still hidden
behind the generic message, and the tool schemas are unchanged.
@github-actions github-actions Bot added sdk/python size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 31, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T08:57:05.158858Z 4c5b3dc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch has not been deployed

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

Labels

sdk/python size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant