Skip to content
agentgateway has joined the Agentic AI Foundation — Learn more

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

About MCP guardrails

Page as Markdown

Control MCP server access, authorize individual tools, and inspect request and response content.

Agentgateway provides three ways to filter Model Context Protocol (MCP) traffic through a virtual MCP server. Use them separately or together:

  • Filter a request with guardrail processors (mcpGuardrails). Inspect tool arguments and results to reject disallowed calls or mask sensitive data. Use a remote processor to call an external policy service.
  • Filter a target with a target condition. Exclude an upstream MCP server before agentgateway contacts it.
  • Filter tools and other resources with MCP authorization (mcpAuthorization). Hide individual tools, prompts, and resources from list responses, and reject calls to them. Rules evaluate each item separately, so you can allow some tools and hide the rest.

All three support Common Expression Language (CEL) expressions that read request attributes, such as headers and JWT claims. Their scope and timing differ.

Compare the options

Use this table to compare what each option filters, when it runs, and whether agentgateway contacts upstream servers.

Filter a requestFilter a targetFilter tools and other resources
Configure withmcpGuardrails policycondition on an MCP targetmcpAuthorization policy
What it filtersOne MCP request or response, for the methods that you selectOne upstream MCP serverOne tool, prompt, or resource at a time
When it runsBefore forwarding the request, after receiving the response, or bothAt session initialization (stateful), or on every request (stateless)On each listed item or call to an individual item
What it can readThe full request parameters (mcp.params) or response result (mcp.result), plus the request contextThe request context and the name of the target (mcp.target.name)The item, such as mcp.tool.name and mcp.tool.target, plus the request context. Tool arguments are not available.
Can rewrite contentYes. Mask or replace fields with a CEL transform or a remote ExtMCP server.NoNo
Contacts the upstream serverNo, for a rejected requestNo, for an excluded targetYes. Agentgateway initializes and lists every included target, then removes denied items.
What the client seesAn error with your rejection message. For tools/call, a tool result with isError: true.A virtual MCP server without that target’s tools, prompts, or resourcesLists without the denied items. Denied tools appear not to exist.

Example: Keep a client away from an MCP server

The following authorization rule hides the admin-tools target’s tools from clients without the admin role. Agentgateway still initializes the target and sends it tools/list requests for those clients.

mcpAuthorization:
  rules:
  - 'mcp.tool.target != "admin-tools" || (has(jwt.roles) && "admin" in jwt.roles)'

To exclude admin-tools before agentgateway contacts it, move the role check to the target’s condition:

targets:
- name: public-tools
  mcp:
    host: http://public-tools:8080/mcp
- name: admin-tools
  mcp:
    host: http://admin-tools:8080/mcp
  condition: 'has(jwt.roles) && "admin" in jwt.roles'

Both examples require an authenticated request with claims in the jwt variable. Do not base access decisions on a header that the client controls.

How the options work together

When a client sends a request to a virtual MCP server, agentgateway applies the options in the following order.

  1. Authentication: If you configure MCP authentication or JWT authentication, agentgateway validates the client’s token first. The resulting claims are available to all three options as jwt.
  2. Target conditions: Agentgateway includes only targets whose condition returns true. Evaluation errors exclude the target. Conditions run once at initialization for stateful sessions (the default), or on every request in stateless mode.
  3. Request-phase guardrail processors: Agentgateway runs the processors for the request’s method in order. The first processor that rejects the request stops the chain, and agentgateway does not contact any target. For a fanout method such as tools/list, the processors run once for the whole request.
  4. Authorization of calls: For a call to a single tool, prompt, or resource, such as tools/call, MCP authorization checks the item. If the item is not allowed, agentgateway rejects the call.
  5. Upstream request: Agentgateway forwards the request to the selected target, or fans it out to every selected target.
  6. Authorization of lists: For methods such as tools/list, MCP authorization removes denied items from each target’s response. Agentgateway then merges the responses and adds target-name prefixes.
  7. Response-phase guardrail processors: Agentgateway runs the processors on the response. For a fanout method, the processors run once, on the merged response.

Next steps

Was this page helpful?
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate ↵ select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.