Skip to content

fix: return resource-not-found code from MCPServer#2814

Open
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/resource-not-found-code
Open

fix: return resource-not-found code from MCPServer#2814
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/resource-not-found-code

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

  • add the MCP resource-not-found error code constant (-32002)
  • distinguish unknown resources from other resource read failures in MCPServer
  • keep resource function failures on the existing generic error path
  • update the interaction requirement now that the divergence is removed

Closes #1579.

To verify

  • uv run --frozen pytest tests/server/mcpserver/test_server.py::TestServerResources::test_read_unknown_resource tests/server/mcpserver/test_server.py::TestServerResources::test_read_resource_error tests/interaction/mcpserver/test_resources.py::test_read_unknown_uri_is_error -q
  • uv run --frozen ruff check src/mcp/types/jsonrpc.py src/mcp/types/__init__.py src/mcp/server/mcpserver/exceptions.py src/mcp/server/mcpserver/server.py tests/interaction/mcpserver/test_resources.py tests/server/mcpserver/test_server.py tests/interaction/_requirements.py
  • uv run --frozen pyright src/mcp/types/jsonrpc.py src/mcp/types/__init__.py src/mcp/server/mcpserver/exceptions.py src/mcp/server/mcpserver/server.py tests/interaction/mcpserver/test_resources.py tests/server/mcpserver/test_server.py tests/interaction/_requirements.py
  • python -m py_compile src\mcp\types\jsonrpc.py src\mcp\types\__init__.py src\mcp\server\mcpserver\exceptions.py src\mcp\server\mcpserver\server.py tests\interaction\mcpserver\test_resources.py tests\server\mcpserver\test_server.py
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FastMCP read_resource() returns incorrect error code when resource not found

1 participant