modelcontextprotocol / modelcontextprotocol/csharp-sdk
Resource-based authorization on tools
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 814
- Avg merge
- 9d 19h
- Merged PRs (30d)
- 4
Description
Is your feature request related to a problem? Please describe.
Some tools require a resource-based authorization to authorize the tool use, while other tools do not. In a web API, we can use the [Authorize("some policy")] attribute, but it is not possible (the handler is not called) with [McpServerTool] methods, the same authorization is applied to the entire group.
Describe the solution you'd like
Allow to specify the authorization policy for specific tools. Since the resource is identified in the tool's parameters, an access to RequestContext<CallToolRequestParams> would be best.
Describe alternatives you've considered
The only alternative I could think of is to check the RequestUri for "/message", parse the body to create a RequestContext<CallToolRequestParams>
Additional context
tl;dr; offer resource-based authorization on tools
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing authorization around McpServerTool methods and compare it with the mentioned Authorize policy behavior in the web API. Examine how RequestContext could expose tool parameters, and use the /message alternative as context. Done means a specific tool can apply a resource-based policy and access its request context without parsing RequestUri.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, authorization
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100