AI agents often work with several tools to complete a task. An enterprise application might provide tools to search documents, read customer information, update records, send emails, and generate reports. Different agents may need different levels of access to these operations.
For example, a customer support agent may need to search documents and retrieve customer information, while an administrative agent may also need to update customer records. Giving both agents access to every tool increases the risk of unauthorized operations.
Developers can enforce these permissions when an agent invokes a tool. However, waiting until runtime to discover a missing permission or an incorrect policy can create unnecessary failures. A deployment may succeed even though an agent cannot access a tool required by its workflow.
A better approach is to validate the tool catalog and permission configuration during application startup.
With .NET and Microsoft's Agent Governance Toolkit (AGT), developers can combine MCP governance policies with a startup validation step. The application can verify that its expected tools exist, agent permissions reference valid tools, and required access rules are configured before accepting requests.
In this article, we will build this validation approach for an MCP server using C#, YAML policies, and the Microsoft.AgentGovernance.Extensions.ModelContextProtocol package.
Why Validate Tool Permissions at Startup?
Consider an application that exposes the following MCP tools:
Tool | Purpose |
|---|---|
| Search internal documents |
| Retrieve customer information |
| Update customer records |
| Send an email |
| Generate business reports |
The application has two agents:
Support Agent: Can search documents and retrieve customer information.
Admin Agent: Can use all five tools.
The intended permission matrix looks like this:
Tool | Support Agent | Admin Agent |
|---|---|---|
Search documents | Allow | Allow |
Get customer | Allow | Allow |
Update customer | Deny | Allow |
Send email | Deny | Allow |
Generate report | Deny | Allow |
Now imagine that a developer adds a new tool called delete_customer but forgets to update the permission configuration.
The application may still start successfully. The new tool might be registered with the MCP server, but its authorization behavior may not match the organization's expectations.
Another problem occurs when a policy refers to a tool that no longer exists. For example, a rule may allow search_customer, while the actual registered tool is named get_customer. The policy may be syntactically valid but ineffective for the intended operation.
Startup validation helps identify these problems before the application begins processing requests.
It is useful for checking:
Whether all expected tools are registered.
Whether permission rules reference existing tools.
Whether every configured agent has an explicit permission profile.
Whether sensitive tools are restricted to approved agents.
Whether the policy configuration follows a deny-by-default approach.
Whether required permissions are missing or unexpectedly broad.
This is different from scanning tool descriptions for prompt injection. Tool scanning checks whether definitions contain suspicious metadata, while permission validation checks whether the application has the expected authorization configuration.
Understanding the Governance Architecture
The validation process should work alongside runtime policy enforcement rather than replacing it.
A practical architecture has two stages.
<text weight="semibold" size="sm">Startup validation</text>
Application Starts
|
v
Load Tool Catalog
|
v
Load Agent Permission Manifest
|
v
Validate Tool References
|
v
Validate Required Permissions
|
v
Check Governance Configuration
|
+------ Invalid ------> Stop Startup
|
v
Start MCP Server<text weight="semibold" size="sm">Runtime authorization</text>
Agent Requests a Tool
|
v
Authenticate Caller
|
v
Resolve Agent Identity
|
v
Evaluate Governance Policy
|
+------ Denied ------> Reject Tool Call
|
v
Execute MCP Tool
|
v
Return Governed ResultThe startup stage checks whether the application is configured correctly. The runtime stage makes the actual authorization decision for each tool call.
This distinction is important. A startup check cannot guarantee that every future request is authorized. The caller's identity, tool arguments, resource identifier, and other runtime conditions may affect the decision.
Installing the Required Packages
For an existing MCP server built with the official .NET SDK, install the governance extension:
dotnet add package Microsoft.AgentGovernance.Extensions.ModelContextProtocolFor a new project, install both packages:
dotnet add package ModelContextProtocol
dotnet add package Microsoft.AgentGovernance.Extensions.ModelContextProtocolThe MCP SDK provides the server and tool-registration functionality. The governance extension adds policy evaluation, startup tool scanning, runtime authorization, and response sanitization.
The extension targets .NET 8 and integrates with IMcpServerBuilder.
Defining the Tool Permission Manifest
Before implementing the validator, define the expected tools and agent permissions in a configuration file.
Create a file named agent-permissions.json:
{
"Tools": [
"search_documents",
"get_customer",
"update_customer",
"send_email",
"generate_report"
],
"Agents": [
{
"Id": "did:mcp:support-agent",
"Name": "Support Agent",
"AllowedTools": [
"search_documents",
"get_customer"
]
},
{
"Id": "did:mcp:admin-agent",
"Name": "Admin Agent",
"AllowedTools": [
"search_documents",
"get_customer",
"update_customer",
"send_email",
"generate_report"
]
}
],
"RequiredAgents": [
"did:mcp:support-agent",
"did:mcp:admin-agent"
]
}This file describes the expected permission structure of the application.
The Tools collection contains the known MCP tool names. The Agents collection defines which tools each agent is permitted to use. The RequiredAgents collection identifies agents that must have a permission profile before the application can start.
Keeping this information outside the application code makes it easier to review and update permissions without changing the validation logic.
For larger systems, this manifest can also be maintained as a deployment artifact and reviewed through source control.
Creating the Startup Permission Validator
Now create a C# class that checks the permission manifest.
The validator should verify three important things:
Every permission references a registered tool.
Every required agent has a permission profile.
Every configured agent has a valid identity and an explicit permission list.
Create AgentPermissionValidator.cs:
using Microsoft.Extensions.Configuration;
public sealed class AgentPermissionValidator
{
private readonly IConfiguration _configuration;
public AgentPermissionValidator(
IConfiguration configuration)
{
_configuration = configuration;
}
public void Validate()
{
var options = _configuration
.GetSection("AgentPermissions")
.Get<AgentPermissionOptions>();
if (options is null)
{
throw new InvalidOperationException(
"Agent permission configuration is missing.");
}
if (options.Tools.Count == 0)
{
throw new InvalidOperationException(
"No MCP tools are configured.");
}
if (options.Agents.Count == 0)
{
throw new InvalidOperationException(
"No agent permissions are configured.");
}
var registeredTools = new HashSet<string>(
options.Tools,
StringComparer.Ordinal);
foreach (var agent in options.Agents)
{
if (string.IsNullOrWhiteSpace(agent.Id))
{
throw new InvalidOperationException(
"An agent has an empty identity.");
}
if (string.IsNullOrWhiteSpace(agent.Name))
{
throw new InvalidOperationException(
$"Agent name is missing for {agent.Id}.");
}
if (!agent.Id.StartsWith(
"did:",
StringComparison.Ordinal))
{
throw new InvalidOperationException(
$"Invalid agent identifier: {agent.Id}");
}
if (agent.AllowedTools.Count == 0)
{
throw new InvalidOperationException(
$"No tools are assigned to {agent.Id}.");
}
foreach (var tool in agent.AllowedTools)
{
if (!registeredTools.Contains(tool))
{
throw new InvalidOperationException(
$"Agent {agent.Id} references " +
$"unknown tool '{tool}'.");
}
}
}
foreach (var requiredAgent in options.RequiredAgents)
{
bool exists = options.Agents.Any(
agent => agent.Id == requiredAgent);
if (!exists)
{
throw new InvalidOperationException(
$"Required agent '{requiredAgent}' " +
"has no permission profile.");
}
}
}
}
Join the conversation! Your thoughts help the community grow.