Est.
MCP GatewayLong read

Runtime Threat Detection for MCP Tool Calls Using Behavioral Baselines and Anomaly Alerting

Session-level baselines catch tool-call sequences that static rules miss.

· 9 min read
Cover illustration for “Runtime Threat Detection for MCP Tool Calls Using Behavioral Baselines and Anomaly Alerting”
MCP Gateway · November 28, 2026 · 9 min read · 1,924 words

An MCP gateway sits between AI agents and MCP servers, inspecting tool requests and forwarding or blocking them under policy. For runtime threat detection, that gateway, or another control layer near the agent, needs more than request-level rules. Behavioral baselines show when tool calls that are allowed on their own form a dangerous sequence, which static analysis and pre-deployment scanning can miss.

Why static controls fail against MCP tool calls at runtime

Traditional security logging and analysis tools expect systems that are deterministic and have call graphs they can predict. Agents adapt execution to data, context, and intermediate results, so a single task may move from customer tickets to production databases to email. Each transition crosses a security boundary, but the reason for crossing it may emerge only during execution. The same tool call can therefore be legitimate in one session and evidence of compromise in another.

Static inspection cannot reconstruct that unfolding context. Huang et al. identify three protocol-level vulnerabilities in their study, arXiv 2601.17549, including absent capability attestation, bidirectional sampling without origin authentication, and implicit trust propagation across multiple servers. These weaknesses concern whether capabilities can be trusted, where instructions originate, and how trust spreads between systems. A scan of server source alone does not expose how those relationships behave in a live session.

The SAFE-MCP gap analysis in issue #189 describes a related detection boundary for threats including sandbox escape, proxy masquerade, version enumeration, and multimodal injection. Their evidence lies in live behavior. Some also need a view of what happens in the infrastructure beyond the agent’s interactions. Static scanning still has a role, but approval before deployment is not evidence of safe execution afterward. The missing evidence arrives when the system runs.

The runtime attack classes that only show up in behavior sequences

Tool-chaining exfiltration makes the gap easiest to see. An agent reads confidential data from an internal system, then requests access to email or another outbound channel. Each action could be permitted on its own. Across the session, however, they create a path from protected information to an external destination. Request-by-request inspection sees two permissions being exercised, while session-level analysis can see how they combine.

A rug pull exploits a different weakness in one-time approval. A previously approved MCP server changes its behavior without changing its name or version string. To detect the change, the system must compare what the server does now with its past behavior, because the server’s label alone cannot show that it is still safe.

Huang et al. examine another form of composition in From Component Manipulation to System Compromise: Understanding and Detecting Malicious MCP Servers. Their proof-of-concept dataset contains 114 malicious MCP servers, and their findings show that attacks distributed across tool descriptions, argument schemas, and tool responses outperform single-component attacks. Component position also shapes attack success. The malicious behavior need not reside in one conspicuous payload.

The scope extends beyond a single agent, too. In multi-agent collusion, one agent can generate distracting activity while another exfiltrates data. A model confined to each agent’s calls would miss the relationship between them. This makes the relevant unit of analysis broader than an isolated request, and sometimes broader than an isolated session.

What behavioral baselines for MCP tool calls actually model

A behavioral baseline is a model of normal agent execution built from logged session history. It is not another tool allowlist. An allowlist records whether an agent may use a tool, while a baseline describes how that agent ordinarily uses tools in context. Its subject is a pattern of activity attributable to an agent and its role.

That pattern has several dimensions. It includes the tools normally used, which tools follow which, and the volume of data handled per tool and session. Access times and session duration add a temporal dimension, while cross-domain transitions describe which security boundaries an agent normally traverses during a task. Inter-agent interaction patterns extend that view where coordinated behavior is a risk.

The same study proposes Connor, a two-stage behavioral deviation detector that compares what a tool does with what it is meant to do. Before execution, it extracts each tool’s declared function intent. During execution, it traces behavior step by step and looks for departures from that intent.

An agent that slowly raises its access privileges or extraction rates over weeks may change too slowly for the drift to be visible in a short observation window. A baseline therefore needs both a view of the current sequence and enough past behavior to distinguish a new pattern from a familiar one.

How deviation detection translates baselines into actionable alerts

Diagram: BLOCK vs. WARN: How Deviation Verdicts Route Alerts. Visualizes: Show the two-verdict decision flow from a detected behavioral deviation to its operational outcome.

Connor separates deviations into BLOCK and WARN verdicts. Critical deviations that directly indicate malicious intent, including credential exfiltration, destructive operations, reverse shells, and multi-step attack patterns, receive BLOCK. Actions that depart from function intent but have no clear malicious impact get WARN. The distinction gives uncertainty somewhere useful to go.

Operationally, BLOCK means an automated, immediate response. WARN routes the case to a human reviewer who can inspect the request in its session context. An unusual data-volume spike, after-hours activity, or repeated authentication failures can call for a closer look without proving malicious intent on its own. The alert becomes useful when the reviewer can see what preceded the deviation and which agent produced it.

False positives are the strongest objection to behavioral controls. Legitimate agent work varies, and a system that blocks every departure from its learned pattern can break workflows and erode confidence in its judgments. A WARN tier addresses that objection directly by keeping ambiguous cases out of the automatic blocking path. It does not make uncertainty disappear.

Machine learning can spot complex patterns that rule-based systems miss, including slow-burn privilege escalation over many sessions. More session history can also improve the baseline against which new activity is judged. Detection must distinguish evidence of malicious behavior from evidence that the model has encountered something new.

Where the runtime control layer should sit in the MCP architecture

An MCP gateway commonly inspects a request payload, applies allow or deny rules, and then forwards or blocks the request. That gives enterprises a place to enforce policy across MCP server access. It does not automatically provide session awareness. A gateway evaluating calls in isolation cannot infer the agent’s instructions, earlier actions, or historical behavior from the current payload alone.

Consider a file deletion request. It may be entirely appropriate during a user-directed cleanup task and deeply suspicious after indirect prompt injection hijacks an agent mid-conversation. The requested operation does not settle the question. Its relationship to the task and the preceding sequence does. Adding more request-level rules cannot substitute for access to that context.

Practitioners disagree about whether enforcement belongs at a gateway or in hooks closer to the agent’s reasoning loop. A gateway must get the context that it cannot get from inspecting traffic alone. Hooks position the control closer to agent execution, but the same detection requirements still apply.

The architectural requirement is access to conversation history, attributable agent identity, and prior tool-call sequences. For enterprises managing multiple MCP servers, those inputs are more useful evaluation criteria than the presence of a gateway alone. A private registry or gateway layer can support centralized governance, but routing and behavioral detection remain distinct functions. A single checkpoint is not necessarily an informed checkpoint.

Why agent identity is the prerequisite for meaningful behavioral baselines

A baseline needs a stable subject. If several agents share a service account, their different tool-call patterns merge into one signal. Behavior that is unusual for one agent can disappear into activity that is ordinary for another. After an incident, the same ambiguity prevents reliable attribution to a specific agent.

The identity supplies continuity across sessions, while task-scoped credentials limit the authority available during a particular piece of work. Ephemeral credentials without that stable binding do not provide a sound foundation for historical comparisons.

Shared static API keys create the opposite problem by making access durable without making the actor distinguishable. A server-level allowlist establishes which server was called while leaving unresolved which agent called it and whether the sequence departed from that agent’s normal behavior. Permission to reach a server is not accountability for actions taken through it.

The governance implication is to extend the company’s existing identity provider rather than establish a parallel identity system for agents. Agent identities can then inherit lifecycle management, revocation, and audit trails from the controls already used for people. A gateway and an agent-side hook both need to know whose behavior they are evaluating.

Shadow MCP as the baseline gap that governance programs overlook

Even a well-attributed baseline has a hard boundary. It covers only the activity that reaches its monitoring layer. Shadow MCP servers are unauthorized or unmanaged servers connected to enterprise AI workflows, and their calls may never enter the governed path.

These servers can bind to localhost, listen on random high ports, or sit behind reverse proxies. Inside IDE plugins, they may appear as routine production dependencies without any formal approval step. Organizations consequently discover more MCP deployments than IT expected. Without enrollment, a new server can become part of an agent’s workflow without becoming part of the security team’s view.

OWASP lists shadow MCP servers as MCP09 in its MCP Top 10. To find these servers, teams must bring together network traffic analysis, endpoint process monitoring, and identity and access telemetry in one risk score for each server they find. Discovery is a prerequisite for behavioral detection.

The July 28, 2026 protocol update shifted MCP to a stateless, per-request model with mandatory Mcp-Method and Mcp-Name headers. Those headers let gateways route and inspect MCP traffic without parsing JSON bodies. Together with MCP-Protocol-Version, they also provide a network-layer mechanism for discovering MCP traffic. Stateless protocol requests do not eliminate the detector’s need for session history.

The governance response is one official registry of MCP servers, with discovered shadow servers brought under it and into monitoring. Without that inventory, claims of enterprise-wide coverage describe only the governed subset.

Building and operating a behavioral baseline system in practice

Engineering and security teams should begin with instrumentation before a complete detection system is ready. Every tool call on the governed path needs a log containing agent identity, session ID, tool name, sequence position, data volume, and timestamp. Those records should flow into the existing observability stack, with OpenTelemetry as the natural integration point. Logging creates the history that later detection requires. Waiting for the finished model postpones the evidence needed to build it.

Each agent needs a stable identity tied to the existing identity provider before its records can support a reliable baseline. Teams can then model typical tool sequences, volumes, timing, and cross-domain access by agent and role. Early baselines will be thin. They should remain provisional while session history accumulates, rather than acquire authority simply because a dashboard displays them.

Graduated alerting can follow once the comparison has a usable foundation. Clear malicious indicators, including credential access outside declared function intent, destructive operations, and reverse shell patterns, belong in the BLOCK path. Deviations without a clear malicious signal belong in WARN, with full session context sent to a human reviewer. This preserves a distinction between stopping an attack and investigating an anomaly.

Teams should use network-layer detection, process monitoring, and identity and access telemetry to find unmanaged servers and bring more of them into monitoring. Enrolling those servers in the registry brings their traffic into the same baseline process. The rollout extends existing observability, identity, and network controls rather than replacing them with a separate security stack.

Sources

  1. From Component Manipulation to System Compromise: Understanding and Detecting Malicious MCP Servers
  2. Analysis: 6 SAFE-MCP techniques that require runtime detection (beyond static analysis) · Issue #189 · secure-agentic-framework/saf-mcp · GitHub
Filed underMCP Gateway

More in MCP Gateway