As AI assistants evolve from answering questions to performing real business operations, authorization becomes one of the most critical aspects of AI system design. An AI agent that can access customer records, generate reports, update inventory, or approve workflows should never have unrestricted access to enterprise resources.
The Model Context Protocol (MCP) standardizes how AI applications interact with external tools, while OAuth 2.0 provides a secure framework for delegated authorization. Together, they enable organizations to expose AI tools securely, ensuring that every action is performed according to the user's identity and permissions.
In this article, you'll learn how to implement fine-grained authorization for MCP tools using OAuth, design secure permission models, and apply production-ready security practices for enterprise AI applications.
Why Authorization Matters for AI Tools
Consider an AI assistant connected to multiple enterprise systems.
User
|
AI Assistant
|
--------------------------
| CRM |
| HR System |
| Finance |
| Inventory |
--------------------------
Without authorization, the AI assistant could potentially access every available tool regardless of the user's permissions.
Instead, every tool invocation should be evaluated against the user's identity and allowed permissions.
Authentication vs Authorization
These terms are often confused.
| Authentication | Authorization |
|---|---|
| Verifies identity | Determines permissions |
| "Who are you?" | "What can you do?" |
| Uses identity providers | Uses roles, scopes, or policies |
| Happens first | Happens after authentication |
Both are required for secure AI systems.
OAuth 2.0 Overview
OAuth enables applications to access resources on behalf of users without exposing passwords.
A simplified flow:
User
|
Identity Provider
|
Access Token
|
AI Client
|
MCP Server
|
Enterprise Tool
The access token contains claims that describe what the user is allowed to do.
Typical Enterprise Architecture
User
|
Identity Provider
|
OAuth Token
|
AI Client
|
MCP Client
|
----------------------------
| MCP Server |
----------------------------
| |
CRM API HR API
The MCP server validates the token before allowing any tool execution.
Configuring OAuth in ASP.NET Core
Register JWT Bearer authentication.
builder.Services
.AddAuthentication("Bearer")
.AddJwtBearer(options =>
{
options.Authority =
"https://identity.example.com";
options.Audience = "mcp-api";
});
The identity provider issues access tokens, while the MCP server validates them before processing requests.
Enabling Authorization
Add authorization services.
builder.Services.AddAuthorization();
Configure middleware.
app.UseAuthentication();
app.UseAuthorization();
Authentication must always execute before authorization.
Protecting MCP Tools
Secure tools using authorization attributes.
[Authorize]
[McpServerTool]
public Customer GetCustomer(int id)
{
...
}
Only authenticated users can invoke the tool.
Role-Based Authorization
Many enterprise applications already use role-based access control (RBAC).
Example:
[Authorize(Roles = "Sales")]
[McpServerTool]
public Customer GetCustomer(int id)
{
...
}
Administrative operations can require stronger permissions.
[Authorize(Roles = "Administrator")]
[McpServerTool]
public void DeleteCustomer(int id)
{
...
}
This prevents unauthorized users from performing privileged actions through AI agents.
Scope-Based Authorization
OAuth scopes provide finer control than roles.
Example access token:
Scopes
customer.read
orders.read
inventory.update
Policy example:
builder.Services.AddAuthorization(options =>
{
options.AddPolicy(
"CustomerRead",
policy =>
policy.RequireClaim(
"scope",
"customer.read"));
});
Protect a tool.
[Authorize(Policy = "CustomerRead")]
Scopes allow applications to grant only the permissions required for a specific task.
Resource-Level Authorization
Sometimes users should only access their own resources.
Example:
User A
Orders:
1001
1002
User B
Orders:
2001
2002
Even if both users have the same role, they should not access each other's data.
Example service:
public bool CanAccessOrder(
string userId,
int orderId)
{
...
}
Resource-level checks should be performed inside business services rather than relying solely on controller attributes.
Tool-Level Permissions
Different MCP tools may require different permissions.
| Tool | Required Permission |
|---|---|
| GetCustomer | customer.read |
| UpdateCustomer | customer.write |
| CreateInvoice | invoice.create |
| DeleteInvoice | invoice.delete |
| ViewReports | reports.read |
Grant only the permissions needed for each operation.
Validating Claims
Claims provide additional authorization information.
Example:
var department =
User.FindFirst("department")?.Value;
Applications can use claims to implement business-specific authorization rules.
Join the conversation! Your thoughts help the community grow.