Skip to content

fix(mcpserver): return resource not found code#2868

Open
go165 wants to merge 1 commit into
modelcontextprotocol:mainfrom
go165:go165/resource-not-found-error-code
Open

fix(mcpserver): return resource not found code#2868
go165 wants to merge 1 commit into
modelcontextprotocol:mainfrom
go165:go165/resource-not-found-error-code

Conversation

@go165

@go165 go165 commented Jun 14, 2026

Copy link
Copy Markdown

Fixes #1579.

Summary:

  • return JSON-RPC error code -32002 for MCPServer resources/read unknown URI
  • preserve direct MCPServer.read_resource() behavior as ResourceError while translating the protocol response at the request-handler boundary
  • keep resource handler failures on the existing generic ResourceError path
  • remove the interaction-suite divergence note for this requirement

Validation:

  • PYTHONPATH=src /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m pytest tests/server/mcpserver/test_server.py::TestServerResources::test_read_unknown_resource tests/issues/test_141_resource_templates.py::test_resource_template_edge_cases tests/interaction/mcpserver/test_resources.py -q: 20 passed
  • /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m ruff check src/mcp/server/mcpserver/server.py src/mcp/server/mcpserver/exceptions.py tests/interaction/mcpserver/test_resources.py tests/interaction/_requirements.py tests/server/mcpserver/test_server.py tests/issues/test_141_resource_templates.py: passed
  • /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m pyright --pythonpath /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python src/mcp/server/mcpserver/server.py src/mcp/server/mcpserver/exceptions.py: 0 errors
  • git diff --check: passed

Note: uv is not available on this machine, so I reused the existing local python-sdk virtualenv and set PYTHONPATH=src to test this worktree.

@go165 go165 force-pushed the go165/resource-not-found-error-code branch from 8348687 to 44d272e Compare June 14, 2026 19:17
@go165

go165 commented Jun 14, 2026

Copy link
Copy Markdown
Author

Validation update for latest head 44d272e: GitHub CI is now green across pre-commit, readme snippets, the Python test matrix, client/server conformance, zizmor, and all-green.

Local checks also passed:

  • pytest tests/interaction/mcpserver/test_resources.py tests/issues/test_141_resource_templates.py tests/server/mcpserver/resources/test_resource_manager.py tests/server/mcpserver/servers/test_file_server.py -q (36 passed)
  • ruff check src/mcp/server/mcpserver/server.py tests/interaction/mcpserver/test_resources.py tests/interaction/_requirements.py tests/issues/test_141_resource_templates.py
  • pyright src/mcp/server/mcpserver/server.py (0 errors)
  • 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