modelcontextprotocol / modelcontextprotocol/csharp-sdk
[Proposal] Declarative tool registration & runtime filtering for version gating (#1557)
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 814
- Avg merge
- 9d 19h
- Merged PRs (30d)
- 4
Description
Proposal: Declarative Tool Versioning & Runtime Header/Endpoint Gating
Motivation & Context
Addressing https://github.com/modelcontextprotocol/csharp-sdk/issues/1557 in conjunction with https://github.com/modelcontextprotocol/csharp-sdk/issues/1216.
Currently, MCP tools registered in McpServerToolCollection lack built-in version metadata or request-scoped filtering capabilities. Developers needing phased canary/beta rollouts must manually intercept tools/list and mutate ServerOptions.ToolCollection at runtime, which is error-prone and causes concurrency/state-bleed issues across sessions.
Proposed Design Alignment
To bridge the static endpoint scoping (#1216) and runtime header gating (#1557), we propose:
-
[McpServerTool]Metadata Extension:- Add optional
string? Versionorstring? Group. - Add optional
string? RequiredHeaderandstring? HeaderPattern(or route constraints).
- Add optional
-
Scoped
IToolFilter/ Request Predicate:- Instead of mutating
ToolCollectionduringtools/list, introduce a non-destructive filter hookFunc<McpContext, ToolMetadata, bool>inMcpServerOptions. - When handling
tools/listandtools/call, evaluate the active request context against registered predicates. - Non-matching tools are excluded from the enumeration and return standard
MethodNotFound/-32601if called directly without the qualifying header.
- Instead of mutating
-
Coexistence with #1216:
- Static route-mapped toolsets and dynamic header-gated tools share the same underlying filter contract.
This avoids destructive list mutation and cleanly supports progressive opt-in deployments.
AI assistance disclosure: AI was used to discover this opportunity and draft the change or text. The submission was checked against the prepared artifact and recorded verification evidence.
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 McpServerToolCollection, McpServerOptions, and the handling of tools/list and tools/call. Review the related issues #1557 and #1216 to understand the intended filter contract and how static and request-scoped gating should coexist. Done means version or group metadata and request predicates support non-destructive filtering, direct calls reject unavailable tools, and shared state is not mutated across sessions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100