Skip to content

Add client-side tool call interceptor (annotation-aware policy enforcement) #1453

@ericstj

Description

@ericstj

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions