fix(server): sanitize unexpected tool errors - #3293
Conversation
There was a problem hiding this comment.
1 issue found across 35 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/server/mcpserver/test_resolve.py">
<violation number="1" location="tests/server/mcpserver/test_resolve.py:1435">
P2: These legacy-mode assertions codify the same client-caused, expected failure (empty accepted elicitation / schema-mismatched accepted answer) being surfaced as a generic "An unexpected error occurred while executing tool ...", while auto mode preserves the specific ToolError message ("received an accepted elicitation with no content" / "does not match the requested schema"). This contradicts the PR's stated goal of preserving explicit ToolError messages for expected, model-facing failures: in legacy mode a bad elicitation response is indistinguishable from a server crash, so the client gets no actionable feedback. The root cause is that the legacy path elicits via ctx.elicit()/elicit_with_validation() which raises a plain ValueError (src/mcp/server/elicitation.py:119,128) caught by the generic handler in tools/base.py:187-189, whereas >= 2026-07-28 raises ToolError in resolve.py:619/624. Consider raising ToolError (or a ValueError subclass the tool runner preserves) from elicit_with_validation so both transports surface the same explicit message.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| assert "Resolver" in text | ||
| else: | ||
| assert "Received an accepted elicitation" in text # the legacy path has no wire key to name | ||
| assert text == "An unexpected error occurred while executing tool whoami" |
There was a problem hiding this comment.
P2: These legacy-mode assertions codify the same client-caused, expected failure (empty accepted elicitation / schema-mismatched accepted answer) being surfaced as a generic "An unexpected error occurred while executing tool ...", while auto mode preserves the specific ToolError message ("received an accepted elicitation with no content" / "does not match the requested schema"). This contradicts the PR's stated goal of preserving explicit ToolError messages for expected, model-facing failures: in legacy mode a bad elicitation response is indistinguishable from a server crash, so the client gets no actionable feedback. The root cause is that the legacy path elicits via ctx.elicit()/elicit_with_validation() which raises a plain ValueError (src/mcp/server/elicitation.py:119,128) caught by the generic handler in tools/base.py:187-189, whereas >= 2026-07-28 raises ToolError in resolve.py:619/624. Consider raising ToolError (or a ValueError subclass the tool runner preserves) from elicit_with_validation so both transports surface the same explicit message.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/server/mcpserver/test_resolve.py, line 1435:
<comment>These legacy-mode assertions codify the same client-caused, expected failure (empty accepted elicitation / schema-mismatched accepted answer) being surfaced as a generic "An unexpected error occurred while executing tool ...", while auto mode preserves the specific ToolError message ("received an accepted elicitation with no content" / "does not match the requested schema"). This contradicts the PR's stated goal of preserving explicit ToolError messages for expected, model-facing failures: in legacy mode a bad elicitation response is indistinguishable from a server crash, so the client gets no actionable feedback. The root cause is that the legacy path elicits via ctx.elicit()/elicit_with_validation() which raises a plain ValueError (src/mcp/server/elicitation.py:119,128) caught by the generic handler in tools/base.py:187-189, whereas >= 2026-07-28 raises ToolError in resolve.py:619/624. Consider raising ToolError (or a ValueError subclass the tool runner preserves) from elicit_with_validation so both transports surface the same explicit message.</comment>
<file context>
@@ -1425,12 +1428,12 @@ async def whoami(login: Annotated[Login, Resolve(ask)]) -> str:
+ assert "Resolver" in text
else:
- assert "Received an accepted elicitation" in text # the legacy path has no wire key to name
+ assert text == "An unexpected error occurred while executing tool whoami"
+ assert "errors.pydantic.dev" not in text
</file context>
Signed-off-by: Ruiming Zhao <uuzzrm@gmail.com>
|
Thanks for the review. I addressed both findings in commit 5ebaf73.
Verification:
The full Pyright run still reports the repository's existing 34 platform-specific typing errors in POSIX/Windows utility and stdio files; none are in the changed files. AI assistance was used and the final diff and test results were reviewed. |
|
The latest CI failure was one stale documentation regression assertion in Updated in commit 3898b88 and pushed. Local verification: 179 affected tests passed; Ruff, format check, and AI assistance was used and the final diff and test results were reviewed. |
|
I also addressed the standards review findings in 47d4e09:
Verification: 131 affected tests passed; Ruff check, format check, and AI assistance was used and the final diff and test results were reviewed. |
|
The latest head also includes the standards-review follow-up in 47d4e09. The legacy elicitation behavior, stale docs expectation, and test-quality findings are now addressed. The latest CI run 31555163205 is green across the full Python 3.10–3.14 locked/lowest-direct Linux and Windows matrix, including docs, conformance, pre-commit, security analysis, and all-green. The PR remains open and awaits maintainer review; mergedAt is still null. AI assistance was used and the final diff and test results were reviewed. |
Fixes #698
Summary
Testing
AI-assisted contribution disclosure
I used AI assistance to inspect the issue and draft the implementation and tests. I reviewed the final diff, ran the checks above, and own the change for review.