Skip to content
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

Add ResourceTemplate and related attribute(s) for implementing resource template handlers #74

Open
Redth opened this issue Mar 23, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@Redth
Copy link
Contributor

Redth commented Mar 23, 2025

Is your feature request related to a problem? Please describe.
Just like McpToolType and McpTool 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?

[ResourceTemplateType]
public static class SampleResourceTemplates {

  // RFC6570 URI Template
  [ResourceTemplate("nuget://{packageId}/{version}")]
  public static byte[] NuGetPackage(string packageId, string version) {
    // Implement Handler logic to fetch and return
  }

}

// in Program.cs
builder.Services
  .AddMcpServer()
  .WithStdioServerTransport()
  .WithTools()
  .WithResourceTemplates();

Additional context
This probably should be considered with #72 so that methods could return actual types marked as ResourceType and have that handled automatically.

@Redth
Copy link
Contributor Author

Redth commented Mar 23, 2025

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.

@PederHP
Copy link
Collaborator

PederHP commented Apr 1, 2025

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?

@IvanMurzak
Copy link

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?

@stephentoub
Copy link
Contributor

We just haven't got to it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants