Microsoft Just Shipped MCP Governance for .NET. Here's What It Actually Enforces. On May 21, Microsoft released the **Microsoft.AgentGovernance.Extensions.ModelContextProtocol** NuGet package (Public Preview for .NET 8+), which adds a `WithGovernance(...)` method to the official MCP C# SDK. This package enforces two-phase governance: a startup gate that scans tool definitions for attacks like typosquatting and prompt injection before they are exposed, and a runtime phase that applies YAML-based policies for tool access control and response sanitization to filter out credential leaks and malicious instructions. The package addresses the gap where most MCP SDKs delegate security responsibilities to the host application, providing built-in enforcement for tool registration, execution, and output validation. MCP adoption is accelerating fast enough that "connect your tools to an agent" is now a one-afternoon task. Governing what those tools are actually allowed to do - that part is still largely left to the developer. Microsoft just made that problem significantly smaller. The Problem It's Solving The Model Context Protocol https://modelcontextprotocol.io/ has made it much easier to connect tools and resources to AI applications. But once those tools are exposed to agents, you also need a reliable way to govern what gets registered, what gets executed, and what comes back from tool calls. This is the unglamorous underside of the MCP ecosystem. Every guide shows you how to register tools and wire up a server. Almost none of them show you how to make sure a registered tool isn't embedding a prompt-injection payload in its own description. Or that tool output doesn't quietly carry credential strings back into your model's context. Or that a typosquatted tool name doesn't fool your agent into calling the wrong thing entirely. The MCP specification https://modelcontextprotocol.io/specification/2025-06-18/server/tools security-considerations says that clients should prompt for user confirmation on sensitive operations, show tool inputs to the user before calling the server, and validate tool results before passing them to the LLM. Most MCP SDKs don't implement these behaviors by default - they delegate that responsibility to the host application. That gap is exactly what this package fills. How It Actually Works On May 21, Microsoft shipped Microsoft.AgentGovernance.Extensions.ModelContextProtocol https://www.nuget.org/packages/Microsoft.AgentGovernance.Extensions.ModelContextProtocol - a Public Preview NuGet package for .NET 8+ that extends the official MCP C SDK https://modelcontextprotocol.github.io/csharp-sdk/api/ModelContextProtocol.html with a single builder method: WithGovernance ... .That single call registers startup and runtime governance controls in one place: tool-definition scanning before exposure, identity-aware policy enforcement on each call, response sanitization before model return, and audit plus metrics instrumentation. dotnet add package Microsoft.AgentGovernance.Extensions.ModelContextProtocol js builder.Services .AddMcpServer .WithGovernance options = { options.PolicyPaths.Add "policies/mcp.yaml" ; options.DefaultAgentId = "did:mcp:server"; options.ServerName = "contoso-support"; } ; The governance flow has two distinct phases. First, a startup gate: when MCP server options are materialized, the package scans registered tools before they are exposed. By default, unsafe tools fail startup. This is not a per-call runtime check - it's a hard gate that runs before any tool becomes visible to any client. The built-in scanner targets a specific set of attack categories: tool poisoning, typosquatting, hidden instructions, rug pulls, schema abuse, cross-server attacks, and description injection. In practice, this means it's looking for prompt-like control text in descriptions, suspiciously similar tool names, hidden Unicode characters, and schema fields that request sensitive values like token , password , or system prompt . The second phase is runtime. Governance decisions are applied when tools are invoked, using YAML-backed policies to decide which tools are allowed, denied, or rate-limited - and those rules live outside of application code. A denied tool call returns a governed error result rather than proceeding to execution. Response sanitization is the third control layer. The sanitizer scans for prompt-injection tags like