Skip to content

fix(mcp): include exception type in error messages when str(exc) is empty (salvage #19425) - #21292

Merged
teknium1 merged 1 commit into
mainfrom
salvage/pr-19425
May 7, 2026
Merged

fix(mcp): include exception type in error messages when str(exc) is empty (salvage #19425)#21292
teknium1 merged 1 commit into
mainfrom
salvage/pr-19425

Conversation

@teknium1

@teknium1 teknium1 commented May 7, 2026

Copy link
Copy Markdown
Contributor

Closes #19425 via salvage. Fixes #19417.

Summary

anyio.ClosedResourceError and some other exceptions are raised with no message — str(exc) is "". The existing error format produces MCP call failed: ClosedResourceError: with nothing after the colon. Add _exc_str() helper that falls back to repr(exc) when str(exc) is empty. Apply to all 6 MCP error formatting sites.

Validation

scripts/run_tests.sh tests/tools/test_mcp_empty_error_message.py → 6 passed.

Original author: @liuhao1024.

…mpty

Some exception classes (e.g. anyio.ClosedResourceError) are raised without
a message argument, so str(exc) returns an empty string. The existing error
format f'{type(exc).__name__}: {exc}' would produce messages like
'MCP call failed: ClosedResourceError: ' with nothing after the colon.

Add _exc_str() helper that falls back to repr(exc) when str(exc) is empty,
and apply it to all 6 MCP error formatting sites (5 tool/prompt/resource
handlers + 1 sampling handler).

Fixes #19417
@teknium1
teknium1 merged commit f9b4b8a into main May 7, 2026
7 of 11 checks passed
@teknium1
teknium1 deleted the salvage/pr-19425 branch May 7, 2026 13:34
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage/pr-19425 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 7532 on HEAD, 7531 on base (🆕 +1)

🆕 New issues (1):

Rule Count
unresolved-import 1
First entries
tests/tools/test_mcp_empty_error_message.py:14: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`

✅ Fixed issues: none

Unchanged: 3954 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have tool/mcp MCP client and OAuth labels May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low — cosmetic, nice to have tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MCP tool calls fail with ClosedResourceError and empty error message

3 participants