modelcontextprotocol / modelcontextprotocol/csharp-sdk
Add client-side tool call interceptor (annotation-aware policy enforcement)
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 814
- Avg merge
- 9d 19h
- Merged PRs (30d)
- 4
Description
The MCP C# SDK v1.1.0 exposes ToolAnnotations via McpClientTool.ProtocolTool.Annotations, but provides no built-in mechanism for a host to inspect those annotations and decide whether to allow invocation.
The server-side filter pipeline (WithRequestFilters(f => f.AddCallToolFilter(...))) has no client-side equivalent. McpClientOptions has no ToolCallPolicy or BeforeToolCall hook. McpClientHandlers only handles server→client requests (Sampling, Elicitation).
Proposed API
var client = await McpClient.CreateAsync(transport, new McpClientOptions
{
ToolCallFilter = async (toolName, annotations, args, next, ct) =>
{
if (annotations?.DestructiveHint == true)
throw new ToolBlockedException("Requires confirmation");
return await next(toolName, args, ct);
}
});
Without this, hosts must manually wrap every McpClientTool before passing to an IChatClient, and any unwrapped path bypasses policy entirely.
See also: https://modelcontextprotocol.io/blog/2026-03-16-tool-annotations (lethal trifecta attack pattern)
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 reading McpClientTool.ProtocolTool.Annotations and the McpClientOptions and McpClientHandlers APIs, then compare them with the server-side AddCallToolFilter pipeline. Define how the proposed ToolCallFilter can inspect annotations and enforce policy across client tool invocation paths, with tests showing blocked destructive calls and allowed calls proceeding through next.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, security
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100