Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
Return -32602 for resource not found (SEP-2164)#2920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -31,7 +31,7 @@ | ||
| from mcp.server.lowlevel.server import LifespanResultT, Server | ||
| from mcp.server.lowlevel.server import lifespan as default_lifespan | ||
| from mcp.server.mcpserver.context import Context | ||
| from mcp.server.mcpserver.exceptions import ResourceError | ||
| from mcp.server.mcpserver.exceptions import ResourceError, ResourceNotFoundError | ||
| from mcp.server.mcpserver.prompts import Prompt, PromptManager | ||
| from mcp.server.mcpserver.resources import FunctionResource, Resource, ResourceManager | ||
| from mcp.server.mcpserver.tools import Tool, ToolManager | ||
| @@ -44,6 +44,8 @@ | ||
| from mcp.server.transport_security import TransportSecuritySettings | ||
| from mcp.shared.exceptions import MCPError | ||
| from mcp.types import ( | ||
| INTERNAL_ERROR, | ||
| INVALID_PARAMS, | ||
| Annotations, | ||
| BlobResourceContents, | ||
| CallToolRequestParams, | ||
| @@ -341,7 +343,12 @@ async def _handle_read_resource( | ||
| self, ctx: ServerRequestContext[LifespanResultT], params: ReadResourceRequestParams | ||
| ) -> ReadResourceResult: | ||
| context = Context(request_context=ctx, mcp_server=self) | ||
| results = await self.read_resource(params.uri, context) | ||
| try: | ||
| results = await self.read_resource(params.uri, context) | ||
| except ResourceNotFoundError as err: | ||
| raise MCPError(code=INVALID_PARAMS, message=str(err), data={"uri": str(params.uri)}) | ||
| except ResourceError as err: | ||
| raise MCPError(code=INTERNAL_ERROR, message=str(err), data={"uri": str(params.uri)}) | ||
Kludex marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| contents: list[TextResourceContents | BlobResourceContents] = [] | ||
| for item in results: | ||
| if isinstance(item.content, bytes): | ||
| @@ -442,13 +449,15 @@ async def list_resource_templates(self) -> list[MCPResourceTemplate]: | ||
| async def read_resource( | ||
| self, uri: AnyUrl | str, context: Context[LifespanResultT, Any] | None = None | ||
| ) -> Iterable[ReadResourceContents]: | ||
| """Read a resource by URI.""" | ||
| """Read a resource by URI. | ||
| Raises: | ||
| ResourceNotFoundError: If no resource or template matches the URI. | ||
| ResourceError: If template creation or resource reading fails. | ||
| """ | ||
| if context is None: | ||
| context = Context(mcp_server=self) | ||
| try: | ||
| resource = await self._resource_manager.get_resource(uri, context) | ||
| except ValueError as exc: | ||
| raise ResourceError(f"Unknown resource: {uri}") from exc | ||
| resource = await self._resource_manager.get_resource(uri, context) | ||
| try: | ||
| content = await resource.read() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.