modelcontextprotocol / modelcontextprotocol/csharp-sdk

Access to HttpContext within handler delegates like ListToolsHandler for authentication-aware logic

Open
#520 6 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement needs confirmation
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.
I'm currently working with the Model Context Protocol in .NET and would like to dynamically filter the tools returned by the ListToolsHandler based on the current user's authentication context. However, it doesn't seem possible to access the current HTTP context inside the ListToolsHandler or similar delegate handlers. This limits the ability to tailor tool availability based on user identity or permissions.

Describe the solution you'd like
I would like to be able to access the current HttpContext (or any equivalent user context) from within handlers like ListToolsHandler, CallToolHandler, etc. This would allow implementing features like per-user tool availability or custom authorization logic.

Describe alternatives you've considered
I haven't found a clear alternative to accessing the HTTP context directly from these handlers. Most approaches seem like workarounds and don't offer a clean or reliable way to integrate authentication data.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how ListToolsHandler and CallToolHandler are invoked in the C# SDK and where the current request context is available. Compare the requested HttpContext or equivalent user context with the existing handler API. Done should establish a documented, reliable way for handlers to apply per-user authentication or authorization logic.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, authentication
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.