fix: Raise resource not found error#1582
fix: Raise resource not found error#1582vincent0426 wants to merge 4 commits intomodelcontextprotocol:mainfrom
Conversation
|
Related: modelcontextprotocol/modelcontextprotocol#1545 Due to ongoing discussions around exactly what errors to use here we should wait on that before merging any fixes for this. |
FWIW, the protocol spec discussion acknowledges that At least that way, clients developing against the reference server implementations will be 100% consistent (and, ultimately, correct, if not for the spec documentation issue)? |
Introduce resource not found error handling following the MCP specification.
This change ensures that when a resource is not found, the server returns error code
-32002(RESOURCE_NOT_FOUND) as specified in the Resources Error Handling.Concern:
There is currently no explicit error handling for FastMCP exceptions in the low-level server. I'm not sure if we want to wrap fastmcp exceptions under
McpErrorto raise the correct error code which avoid changing the low-level server code, otherwise, sdk might need to create a new exception type to handle non-connection error?Motivation and Context
Closes #1579
Previously, when a resource was not found, the server returned error code
0(generic error) instead of the spec-compliant-32002(RESOURCE_NOT_FOUND).Root Cause:
ValueErrorwhen a resource is not founderrorattribute were converted toErrorData(code=0, ...)python-sdk/src/mcp/server/lowlevel/server.py
Lines 705 to 708 in 3390e49
Solution:
ResourceErrorexception class with anerrorattribute containingErrorDatawith the appropriate error codeResourceManagerto raiseResourceErrorwithRESOURCE_NOT_FOUNDcode for unknown resourcesHow Has This Been Tested?
Breaking Changes
Types of changes
Checklist
Additional context