MCP context
Themcp context object is available in CEL expressions when processing Model Context Protocol (MCP) requests. It identifies which MCP resource — a tool, prompt, or resource — is being accessed, and which backend target it belongs to.
The
mcp object is only present when the request is an MCP request. Exactly one of mcp.tool, mcp.prompt, or mcp.resource will be set, depending on the type of MCP operation being performed.mcp.tool
Present when the MCP request is invoking a tool (for example, tools/call or tools/list).
The name of the MCP backend target that provides the tool. This corresponds to the
name field of the target in your Agentgateway configuration.The name of the tool being invoked.
mcp.prompt
Present when the MCP request is accessing a prompt (for example, prompts/get or prompts/list).
The name of the MCP backend target that provides the prompt.
The name of the prompt being accessed.
mcp.resource
Present when the MCP request is accessing a resource (for example, resources/read or resources/list).
The name of the MCP backend target that provides the resource.
The name or URI of the resource being accessed.
Using MCP context in authorization rules
MCP authorization rules are CEL expressions configured undermcpAuthorization.rules. A request is allowed if any rule evaluates to true.
Examples
Allow access to specific tools
Allow access to specific tools
Allow a caller to invoke only a safe subset of tools:
Restrict by backend target
Restrict by backend target
Only allow access to tools on a specific MCP server:Combine target and tool name for fine-grained control:
Allow access to public resources only
Allow access to public resources only
Allow any caller to read resources under a
public/ prefix:Combine MCP context with JWT claims
Combine MCP context with JWT claims
Admins can call any tool; other users can only call read-only tools:Allow a specific user to call a specific tool:Allow tool access based on a custom JWT claim:
Allow a prompt for verified users
Allow a prompt for verified users
Only allow a named prompt for users with a verified identity:
Read-only access pattern
Read-only access pattern
Allow read-only operations across tools and resources, deny writes:
Restrict by source IP and MCP tool
Restrict by source IP and MCP tool
Allow a sensitive tool only from internal networks:
Real-world authorization configuration
The following example is taken from the Agentgateway authorization example. It shows how to configure multiple MCP authorization rules that combinemcp and jwt context: