Skip to main content

Sensitive Data on MCP

The project's sensitive-data policy covers a gateway's MCP traffic too, in both directions:

  • Tool arguments: what agents send to the servers.
  • Tool results: what the servers send back.

The same types, actions (Off, Flag, Block), likelihoods, counts, allow lists and maxScanBytes apply as for model requests. The policy's scope means nothing here (MCP messages have no conversation roles). Requires AI gateway v0.4.0 or later on every edge, which MCP itself requires.

Turn the directions on or off​

Both directions are on whenever the policy is active (at least one type flags or blocks). There is nothing to enable; you can only turn a direction off.

Project-wide (UI): AI Gateway → Sensitive data → section What is read, and what never counts → On MCP (gateways serving MCP tools): the switches Tool arguments and Tool results.

One gateway (UI): the gateway's page → Sensitive data → Override the project's policy → for a gateway that serves MCP, MCP tool arguments (What clients send to the servers) and MCP tool results (What the servers send back), each Project (inherit), Scan or Skip.

API / configuration: the policy's mcp block; a direction is written only when turned off:

sensitive:
types:
credit_card: { action: block }
email: { action: flag }
mcp: { arguments: true, results: false } # results not scanned

A gateway's override sets mcp.arguments / mcp.results direction by direction; what it leaves unset comes from the project.

Tool arguments: the MCP phase​

Read by the authorization's MCP phase on the gateway's /mcp route, after the tool grant check and before the call quota (a refused call uses no quota).

What is scanned: the whole request body when one of its messages carries users' data: tool and prompt arguments, completions, resource reads, the client's answers to a server's requests (sampling results, elicitation input), and methods the gateway does not know.

OutcomeWhat the agent getsReaches the server?
Nothing found / types offThe call goes on.Yes
A flag type foundThe call goes on; a decision is recorded.Yes
A block type foundHTTP 403, JSON-RPC error with data.code: "sensitive_data" for the message's id. The message names the blocked types, never the values.No
{"jsonrpc":"2.0","id":3,"error":{"code":-32000,
"message":"the request carries sensitive data the gateway agents does not allow: credit_card; remove it and retry",
"data":{"code":"sensitive_data","type":"permission_error","status":403}}}

Tool results: the result scan​

Read by the elchi-ai-gateway-mcp-guard filter, an Envoy ext_proc on the gateway's /mcp route served by the AI gateway's authorization socket. It is generated per gateway, only where the gateway's policy scans results; elsewhere the filter is inert and costs other traffic nothing.

The response streams through it: each SSE event is scanned on its own and passed on at once, so progress notifications are not held back. JSON answers are read whole.

What is scanned: tool results (content text, structuredContent, _meta, results with isError, embedded resources; a text blob decoded), JSON-RPC errors, the server's own requests (sampling, elicitation) and its log and progress notifications. Image and audio data and binary blobs are left out (base64 is not text).

What the server sentBlocked: what happens
An answer (a tool result, an error)Replaced by a JSON-RPC error sensitive_data for its id. HTTP stays 200: the tool ran, its result is withheld.
A request of the server (sampling, elicitation) on a call's streamThe call is answered with that error, and the call's own answer that follows is dropped (one answer per call). Dropping the request alone would leave the agent waiting.
A notification (log, progress)Dropped. The stream goes on.
A text/plain or untyped answer (the extproc's error carrying a server's non-2xx body; a server relaying under its own Content-Type)Read whole and scanned as text; blocked, it answers the call with the error.
An SSE event carrying several messagesScanned as text; blocked, it answers the call.

A flag lets the message through and records a decision.

Never scanned​

  • Protocol-only messages: initialize, ping, logging/setLevel, the listings (tools/list, prompts/list, resources/list, resources/templates/list, roots/list) and notifications/initialized, notifications/cancelled, notifications/*/list_changed. A tool's description must not drop a whole listing.
  • Image and audio data and binary blobs inside results (counted as binary_skipped).

When a message cannot be read​

Where the policy blocks a type, what cannot be checked is refused; where it only flags, it goes on unchecked (and is counted).

CaseWhere the policy blocksCode
Arguments larger than maxScanBytes (default 2 MiB)HTTP 413sensitive_scan_too_large
Arguments with more look-alike values than the scan checksHTTP 403sensitive_scan_overflow
No scan slot free in time (the gateway is busy)HTTP 503, retry-after: 1sensitive_scan_busy
The scan did not finish in timeHTTP 503, retry-after: 1sensitive_scan_incomplete
A result larger than maxScanBytesThe call's answer becomes the errorsensitive_scan_too_large (status 413 in data)
An oversized SSE eventThe event is dropped; the call is answered with the errorsensitive_scan_too_large
A compressed result body, or a content type that is no MCP messageThe call's answer becomes the errorsensitive_scan_unreadable (status 403 in data)

sensitive_scan_busy and sensitive_scan_incomplete refuse whatever the policy blocks, in both directions (an unread message may carry anything): for arguments as HTTP 503, for a result as the call's error in place of the answer.

The result scan unreachable. Where the policy blocks results, the /mcp route fails closed (failure_mode_allow: false: HTTP 500). Where it only flags, answers pass unscanned. An AI gateway restart cuts the calls in flight with a 500 whatever the failure mode, because the response has already started (Envoy's behaviour in this streaming mode).

Where to see the decisions​

  • Sensitive data tab, the decision list at the bottom (What the authorization refused or flagged — types and counts, never the data.; Owners and Admins): the Phase filter offers MCP arguments (mcp) and MCP result (mcp_result). The Model or tool column shows <server>__<tool> (or the method for a message that is no tool call). Types and counts only, never a value.
  • MCP calls → Tools: the Sensitive data column counts blocked and flagged decisions per tool in the window.
  • API: GET /api/v3/ai-gateway/decisions?project=&from=&to=&phase=mcp_result&sensitive=1.
  • Metrics on the edge (/metrics of the AI gateway): elchi_ai_gateway_mcp_result_scans_total{outcome} (clean, flagged, blocked, binary_skipped, unscanned_*) and elchi_ai_gateway_mcp_result_streams.

The sensitive-data tab The sensitive-data tab

Verify​

  1. Set a type to Block (for example credit_card) and save.
  2. Call a tool with a card number in its arguments: HTTP 403, sensitive_data; MCP calls shows no call for it (it never reached the server); the decision list of the Sensitive data tab shows it (phase MCP arguments, result Blocked).
  3. Call a tool whose result carries a card number: HTTP 200 with a JSON-RPC error sensitive_data in place of the result; the decision list shows it with phase MCP result; the call itself is in MCP calls with outcome 200 (the server answered).
  4. A tools/list whose descriptions contain such values still lists every tool.