Commit c215aef
committed
fix: propagate MCPError from tool handlers as JSON-RPC error
Previously, only UrlElicitationRequiredError was re-raised; any other
MCPError raised inside a tool function was caught by the bare
'except Exception' clause and wrapped into a ToolError, which then
surfaced as a CallToolResult(isError=True) instead of a structured
JSON-RPC error response.
Since UrlElicitationRequiredError is a subclass of MCPError,
broadening the guard to 'except MCPError' covers all cases including
the original one.
Fixes #27701 parent 7267818 commit c215aef
2 files changed
Lines changed: 19 additions & 4 deletions
File tree
- src/mcp/server/mcpserver/tools
- tests/server/mcpserver
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | | - | |
116 | | - | |
| 114 | + | |
117 | 115 | | |
118 | 116 | | |
119 | 117 | | |
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
93 | 110 | | |
94 | 111 | | |
95 | 112 | | |
| |||
0 commit comments