-
Notifications
You must be signed in to change notification settings - Fork 313
Add ResourceTemplate
and related attribute(s) for implementing resource template handlers
#74
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
Comments
For template parsing and wiring up to method calls, we could potentially use something like https://github.com/corvus-dotnet/Corvus.UriTemplates which already implements the RFC and has some patterns for programmatically extracting a dictionary of parameters given a URI template and URI. |
I really like this approach. I think it could work fine for Resource as well. Isn't a Resource effectively just a ResourceTemplate with no parameters? |
Thanks for this idea! I was expected for the same approach as with Tools, it was a surprise to see the existed implementation which doesn't have Attributes. @PederHP do you have any plans for this feature? |
We just haven't got to it yet. |
Is this why my MCP server logs go: My server:
I'm using my MCP-server together with Claude and it looks like it asks for resources every 5 seconds or so. Shutting down Claude, and the polling for resources/lists stops. Logs:
|
@johnkors I don't think so. You just need to set the handler. I made 3 static functions to make it pretty. builder.Services
.AddMcpServer()
.WithStdioServerTransport()
.WithPromptsFromAssembly()
.WithToolsFromAssembly()
.WithListResourceTemplatesHandler(ResourceRouter.ListResourceTemplates)
.WithListResourcesHandler(ResourceRouter.ListResources)
.WithReadResourceHandler(ResourceRouter.ReadResource); |
That looks like an issue with Claude. If the server doesn't advertise a resources capability, the client shouldn't be issuing requests to list resources. |
I don't have resources, so adding a resource handler would only avoid the error messages. Wouldn't it make more sense for the server to return an empty list if none defined instead of erroring out?
Yeah, Copilot in VS Code does not poll - so probably an issue with Claude. Didn't they invent the spec, though? :) |
It could, but the spec actually states it should be an error: "Error Handling |
They did, but the Python and TypeScript SDKs have a number of open issues, and there have been a few odd implementation choices (the initial prompt implementation in the app comes to mind) so the Claude desktop app should not be considered a reference client. The mcp-inspector is probably thing that exists to a reference client. |
I understand, but would it be too magic if there always were a default no-op implementation, so I don't need to do this to avoid error logs?
Or just lower the log level. Some client asking for resources when there aren't any, WRN instead of ERR? |
That's reasonable |
In your implementation, would you have to list each resource independently, or would you also be able to expose directories? As an aside, in python there is a package called fsspec that abstracts away the file-system being referenced (similar to the dotnet FileProvider APIs). This package implements the Composite Design Pattern for file-system-providers, allowing developers to specify fallback provider for file lookup (similar to the way dotnet Configurations allow for Composite configuration providers to specify that a secret could be in user-secrets, env vars, etc.). Would the pattern you use here prevent that from being implemented with dotnet File Providers? |
To me, the spec reads Check the example they follow that statement with: , they specifically link that to a
Are you sure you are not mixing the two concepts here? |
I was thinking either just logging and returning, Is notifying the client on par with the spec?: johnkors@ba89760 |
Is your feature request related to a problem? Please describe.
Just like
McpToolType
andMcpTool
works today, it would be great to have a way to use attributes to define resource templates.Describe the solution you'd like
Would be nice to annotate a type and method(s) to specify resource templates.
Resource URI Templates per the spec should conform to RFC6570. I'm not sure if this is what ASP.NET uses, but perhaps there is some way to leverage the route parsing logic within the SDK here?
Additional context
This probably should be considered with #72 so that methods could return actual types marked as
ResourceType
and have that handled automatically.The text was updated successfully, but these errors were encountered: