Skip to content

Keep MCP tool errors on the connection#218

Merged
samrusani merged 1 commit into
mainfrom
codex/mcp-tool-error-hardening
May 15, 2026
Merged

Keep MCP tool errors on the connection#218
samrusani merged 1 commit into
mainfrom
codex/mcp-tool-error-hardening

Conversation

@samrusani
Copy link
Copy Markdown
Owner

Upgrade Overview

Protected Areas

  • continuity APIs
  • memory schema
  • evidence pipeline
  • trust rules
  • promotion logic

Compatibility Impact

This preserves the existing MCP tool response shape for known validation and policy errors while adding a defensive boundary for unexpected runtime failures. MCP clients should now receive a normal tool isError response instead of losing the stdio connection when a backend dependency fails during tools/call.

Migration / Rollout

No migration is required. Restart any running Alice MCP server or connected agent process after deploying so it picks up the patched mcp_server.py.

Operator Action

After merge, restart the local Alice MCP server/agent and retry the memory commit. If the underlying issue is environmental, such as a database connection problem, the agent will now see a structured tool error instead of MCP connection closed during the call.

Validation

Validated locally with the targeted MCP unit suite, Python compile check, whitespace check, MCP stdio failure reproduction, and an MCP trusted commit plus undo smoke against local Postgres.

Rollback

Rollback is a normal revert of this PR. The change only affects MCP JSON-RPC error containment and does not alter memory data, schemas, or commit policy.

What Changed

  • Catches unexpected exceptions at the MCP tools/call JSON-RPC boundary.
  • Returns a structured isError tool result instead of letting the MCP server process terminate.
  • Logs the exception type to stderr without exposing full internals to the client payload.
  • Adds unit coverage for unexpected tool failures so future MCP tools cannot regress back to connection-closing behavior.

Validation Evidence

Passed locally:

  • ./.venv/bin/pytest tests/unit/test_mcp.py -q (15 passed)
  • ./.venv/bin/python -m py_compile apps/api/src/alicebot_api/mcp_server.py
  • git diff --check
  • MCP stdio repro returns structured isError instead of crashing on an injected database connection failure.
  • MCP trusted commit plus undo smoke completed against local Postgres.

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@samrusani samrusani merged commit 32c7606 into main May 15, 2026
5 checks passed
@samrusani samrusani deleted the codex/mcp-tool-error-hardening branch May 15, 2026 10:26
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