Skip to content

Commit 89be0b7

Browse files
Merge pull request modelcontextprotocol#32 from modelcontextprotocol/justin/tool-call-errors
Recommend errors in tool calls be reported inline
2 parents 8be71ae + 5732219 commit 89be0b7

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

docs/spec/tools.md

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,17 @@ Upon receiving this notification, clients SHOULD request an updated tool list us
274274

275275
## Error Handling
276276

277-
Clients MUST be prepared to handle cases where listed tools become unavailable between listing and invocation attempts. Servers SHOULD provide appropriate error responses in such scenarios.
277+
Error handling for tools follows two distinct paths depending on the type of error:
278278

279-
Servers MUST return error responses when:
279+
1. Protocol-level errors (like unknown tools or invalid parameters) MUST be reported as JSON-RPC error responses
280+
2. Tool execution errors SHOULD be reported inside successful CallToolResult responses
281+
282+
For protocol-level errors, servers MUST return error responses when:
280283
- An unknown tool is requested
281284
- Invalid arguments are provided
282-
- The tool execution fails
285+
- The server does not support tool calls
283286

284-
Example error response:
287+
Example protocol error response for invalid parameters:
285288
```json
286289
{
287290
"jsonrpc": "2.0",
@@ -296,6 +299,36 @@ Example error response:
296299
}
297300
```
298301

302+
Example protocol error response for an unknown tool:
303+
```json
304+
{
305+
"jsonrpc": "2.0",
306+
"id": 4,
307+
"error": {
308+
"code": -32602,
309+
"message": "Invalid params",
310+
"data": {
311+
"reason": "Unknown tool: invalid_tool_name"
312+
}
313+
}
314+
}
315+
```
316+
317+
For errors that occur during tool execution (like API failures or invalid data), servers SHOULD return these as part of a successful `CallToolResult`. This allows the LLM to see and potentially handle the error condition:
318+
319+
```json
320+
{
321+
"jsonrpc": "2.0",
322+
"id": 5,
323+
"result": {
324+
"toolResult": {
325+
"error": "No search results found for query: 'widgets manufactured in 1972'",
326+
"status": "empty_results"
327+
}
328+
}
329+
}
330+
```
331+
299332
## Security Considerations
300333

301334
Implementations MUST carefully consider the security implications of exposing tools, especially when dealing with sensitive data or external services. Proper authentication and authorization mechanisms SHOULD be in place to prevent unauthorized access to tools.

schema/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"type": "object"
5555
},
5656
"CallToolResult": {
57-
"description": "The server's response to a tool call.",
57+
"description": "The server's response to a tool call.\n\nAny errors that originate from the tool SHOULD be reported inside the result\nobject—i.e., as part of an MCP successful result, not as an MCP error\nresponse. Otherwise, the LLM would not be able to see that an error occurred\nand self-correct.\n\nHowever, any errors in _finding_ the tool, an error indicating that the\nserver does not support tool calls, or any other exceptional conditions,\nshould be reported as an MCP error response.",
5858
"properties": {
5959
"_meta": {
6060
"additionalProperties": {},

schema/schema.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,15 @@ export interface ListToolsResult extends PaginatedResult {
578578

579579
/**
580580
* The server's response to a tool call.
581+
*
582+
* Any errors that originate from the tool SHOULD be reported inside the result
583+
* object—i.e., as part of an MCP successful result, not as an MCP error
584+
* response. Otherwise, the LLM would not be able to see that an error occurred
585+
* and self-correct.
586+
*
587+
* However, any errors in _finding_ the tool, an error indicating that the
588+
* server does not support tool calls, or any other exceptional conditions,
589+
* should be reported as an MCP error response.
581590
*/
582591
export interface CallToolResult extends Result {
583592
toolResult: unknown;

0 commit comments

Comments
 (0)