Skip to content

MTGuard: Hybrid Analysis for Secure MCP Tool Calls in LLM AgentsHybrid Analysis for Secure MCP Tool Use in LLM Agents

arXiv· arXiv:2607.25297· Ping He, Yuexiang Xie, Yaliang Li, Shouling Ji·Indexed by this site · 2026-10-12· Originally publishedDefenses

Quick read

Defenses

Based on the paper PDF (AI-generated); refer to the original

MTGuard compares MCP call declarations against sandbox execution traces; across six configurations, the tool-call-level DR is 48.3% and TCG is 8.3%.

Threat modelAccording to MCP-SafetyBench, attacks come from one of the MCP server, MCP host, or user, with only one side compromised at a time, and cannot directly compromise the defense. The goal is to induce unsafe tool use, disrupt the task, or cause unauthorized side effects. Excluded are training-time attacks, weight tampering, kernel-level compromise, out-of-lifecycle attacks, and multi-party collusion. The defender rejects unsafe calls and preserves benign calls.

Questions
MCP tools can appear normal in metadata and returned text, yet access sensitive files, spawn processes, or connect to untrusted endpoints during execution. Looking only at messages or only at low-level traces is insufficient; whether the same system behavior is harmful depends on the task and the tool's declaration.
Methods
MTGuard uses code policies and LLM review of parameters before execution, removing free-text descriptions; during execution it builds a tool behavior tree with eBPF in a Docker sandbox; after execution it compares declarations against observations, and withholds results on violation without rollback.
Experiments and results
On browser automation and financial analysis, across three backend models, MTGuard has an overall DR of 48.3% (116/240), TCG of 8.3%, and TRI of 0.0%. On the host side it is 75.0%, on the server side 32.5%, and the non-weighted average FPR is 3.7%.
Limitations and future work
The authors point out that the prototype and evaluation only cover locally deployed MCP tools, monitoring does not inspect network payloads, and may miss encrypted traffic, in-memory computation, or behavior in unobserved external services, and post-execution rejection cannot undo side effects that have already occurred. DR is a non-blocking counterfactual judgment, and the paper does not report the number of repetitions or the task completion rate after blocking.
Experimental setupDeepSeek-V4-Flash、DeepSeek-V4-Pro et al. · MCP-SafetyBench、Tool Call Hook · DR、FPR et al.
Evaluated models
DeepSeek-V4-FlashDeepSeek-V4-ProGPT-5.6 Luna
Benchmarks
MCP-SafetyBenchTool Call Hook
Metrics
DRFPRauditing latencyASR
AI summaryMTGuard defends against LLM agents being induced to execute malicious or unauthorized operations when calling MCP tools through lifecycle-aware static-dynamic collaborative analysis. Existing methods mostly rely on static analysis, checking only prompts and generated outputs, with limited defense effectiveness and robustness. Evaluation shows that MTGuard can mitigate multiple types of harmful tool use across different LLM agents while maintaining performance on benign user tasks.

MTGuard defends against LLM agents being induced to execute malicious or unauthorized operations when calling MCP tools through lifecycle-aware static-dynamic collaborative analysis. Existing methods mostly rely on static analysis, checking only prompts and generated outputs, with limited defense effectiveness and robustness. Evaluation shows that MTGuard can mitigate multiple types of harmful tool use across different LLM agents while maintaining performance on benign user tasks.

Related events and news

0 events · 1 news mentions

News that mentions this paper

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    The authors state that existing MCP defenses mostly stop at the message level; MTGuard compares declarations with execution inside a sandbox.

    Existing MCP tool defenses mainly inspect messages and cannot see system-level side effects at execution time.

    • Scenario: The authors state that MCP has become the de facto standard for LLM agents to connect to external resources; untrusted or compromised tools can influence decisions and produce harmful side effects in the host environment.
    • Limitations of existing work: The authors state that existing defenses mainly inspect prompts, conversations, tool metadata, call parameters, and textual results, and generally cannot observe execution-time side effects. They also state that traditional sandboxing or runtime monitoring cannot directly fill this gap: whether the same file access or network request is unsafe depends on the declared functionality, parameters, and task context.
    • Core assumption: An effective defense must connect runtime side effects to the semantic context of the call. The authors believe that looking only at messages or only at low-level traces makes it hard to detect attacks whose declarations appear benign but whose execution is harmful, especially tool execution hijacking.
    • Proposed approach: MTGuard acts as a standalone guard agent that performs combined static and dynamic analysis before, during, and after execution, and uses a tool behavior tree to represent the runtime behavior of a single call.
    • Threat model:
      • Goal: Induce unsafe tool use, disrupt the intended task, or cause unauthorized effects in the host or external environment.
      • Entry points: Following MCP-SafetyBench, from one of the MCP server, MCP host, or user, with only one assumed compromised at a time. The server side can control metadata, descriptions, return payloads, or implementation; the host side can tamper with planning, orchestration, or message routing; the user side can control requests and user-provided files or external content.
      • Boundaries: Cannot directly compromise the defense and its trusted monitoring facilities. Excludes training-time attacks, weight tampering, compromise of the defense system itself, kernel-level compromise, attacks outside the call lifecycle, and collusion attacks that compromise multiple attack surfaces simultaneously.
      • Victim system: The target LLM agent using MCP tools. The defense must detect and deny unsafe calls while preserving benign and task-relevant calls.
  2. What related research exists?

    The authors summarize existing work as message-level defenses, agent guardrails, and MCP package inspection, with experimental baselines being Agent-Aegis's TCG and TRI.

    The introduction and Related Work divide prior work into three categories; the experiments additionally specify baseline components and benchmarks.

    • Message-level tool defenses: The introduction states that one group of defenses mainly checks user prompts, conversation history, tool metadata and descriptions, call parameters, and textual results, and can detect suspicious instructions or metadata inconsistencies, but generally does not observe system-level side effects at execution time. The authors mark this group as references [5, 7, 17, 18, 25, 33, 35, 36]; the introduction does not detail each work's approach.
    • Content-level and agent guardrails: Related Work states that most guardrails perform content-level filtering, such as filtering harmful or violent output, and considers this insufficient for agents that depend on tool use and execution context. The authors name GuardAgent (Xiang et al., 2025) for access control over the target agent, and Liu et al. (2025) for anomaly detection on behavior messages. The authors state that these methods mainly rely on static messages or interaction traces and, because they do not incorporate execution-time dynamic behavior, have difficulty detecting tool execution hijacking.
    • MCP package-level detection: The authors state that recent work detects malicious tools by inspecting MCP server packages; A.I.G (Tencent Zhuque Lab, 2025) uses an LLM agent to inspect packages. The authors state that such methods stop at the package level and do not perform runtime monitoring during agent execution, so they cannot provide fine-grained protection for actual calls, and their defensive effect is limited.
    • Baselines and benchmarks: The experimental baselines are Agent-Aegis (Deng et al., 2026)'s Tool Call Governance (TCG, pre-execution checks of tool name and parameters) and Tool Result Inspection (TRI, post-execution scanning of returned text). Tasks come from MCP-SafetyBench (Zong et al., 2025)'s browser automation and financial analysis, plus the authors' host-side Tool Call Hook.

    The authors position MTGuard as coupling protocol-level context with dynamic execution evidence across the entire call lifecycle, rather than only message checking, only package scanning, or treating runtime monitoring as a sandbox detached from semantics.

  3. How does the paper address this problem?

    MTGuard audits parameters before execution, builds a behavior tree during execution, and after execution compares declarations with observations before deciding whether to allow.

    MTGuard acts as an external guard agent that intercepts the target agent's MCP calls: before execution it examines declarations, during execution it only collects evidence, and after execution it compares declarations against observations to decide whether to allow or deny. Figure 1 shows the three components and the deny/allow paths; Algorithm 1 is in Appendix A.

    Problem setup

    • The agent issues a call T under task context c and environment state e, and execution causes a state transition. The authors treat a call as unsafe if and only if the post-transition context or environment falls into an unsafe set: ĉ∈ Cusf∨ê∈ Eusf.
    • The safe set consists of calls where neither falls into an unsafe set after the transition. M(T;c,e) approves T if it belongs to that set, and denies it otherwise.
    • The lifecycle is divided into pre-execution, in-execution, and post-execution. The implementation in Section 3 and Algorithm 1 denies before dispatch or withholds results after completion. The introduction also mentions the ability to terminate a running tool; Section 5.1 lists selective online termination as future work, and Algorithm 1 has no in-execution adjudication.

    Pre-execution parameter audit

    • Collects conversation history, the current task (the most recent user message), tool name, call parameters, and the parameter schema from the target agent's registry.
    • Free-text tool descriptions may contain adversarial instructions; they are removed during the audit, leaving only the tool name and parameter descriptions.
    • First runs user-defined programmatic policies; any violation leads to denial. If passed, an LLM evaluates natural-language policies. The system prompt states principles, and the user prompt fills in the task, history, tool name, schema, parameters, and rules. Appendix D's Prompt 1 and Prompt 2 give the full prompts.
    • If either path denies, a denial response is returned before dispatch; otherwise monitoring is started and the call is allowed.

    In-execution monitoring and behavior tree

    • The monitor does not make safety conclusions. The tool executes in a Docker sandbox; host-side eBPF attributes by cgroup v2. Tracking starts before forwarding and stops after the tool returns and the event stream is idle.
    • Tracks processes already in the cgroup (long-lived workers may predate this call) as well as newly forked descendants. Collects process creation, execution, and exit; file open, delete, and rename; TCP connection-related events; and UDP DNS responses from port 53 within the target cgroup. The current implementation records file names without reconstructing absolute paths; DNS events that cannot be reliably attached to a process node are kept separately.
    • The tool behavior tree has the declared call as its root, recording the call identifier, tool name, and parameters, with process and DNS branches below. File and network events are attached to the responsible process, and parent-child edges represent observed process creation relationships. The raw tree and execution results are passed to post-execution verification. Appendix C gives a simplified tree example.

    Post-execution verification

    • The verifier compares the tool name, schema, declared parameters against processes, files, network, DNS, and returned content, to detect behavior not visible from declarations alone, including host-side call hijacking.
    • Before LLM verification, the behavior tree is simplified: process identities, executed commands, and file and network events that do not match noise rules are retained. The main filtered items are Python bytecode and import artifacts, frequently loaded shared libraries, and loopback traffic treated as internal sandbox traffic. The raw tree goes to code policies, and the simplified tree goes to the LLM. Overlong process and DNS records, and tool results placed in the prompt, are truncated; the paper does not give truncation lengths.
    • Code policies still take priority, then the LLM. The LLM operates on allow-by-default: only clear inconsistency or clear policy violation leads to denial. The prompt requires a consistency check between declarations and observations and includes step-by-step analysis and few-shot examples. Appendix D's Prompt 3 and Prompt 4 give the full prompts. On denial, results are withheld and do not enter subsequent reasoning; the authors state this cannot roll back side effects that have already occurred. On approval, results are passed to the agent.
  4. What experiments did the paper conduct?

    Across six configurations, MTGuard has an overall DR of 48.3%, TCG of 8.3%, and TRI of 0.0%; on the server side it is 32.5%.

    Experimental Setup

    • Agents and environment: Two ReAct agents, one primarily using the Playwright MCP server and the other primarily using the Yahoo Finance MCP server, with access to auxiliary servers such as filesystem, terminal and network-fetching. At most 20 steps per run. The prototype is based on AgentScope, the sandbox is Docker, and tracing is eBPF. The machine is Ubuntu 22.04, 247 GB memory, one Intel Xeon Platinum CPU.
    • Cases: MCP-SafetyBench takes 30 browser cases and 53 financial cases, 83 in total; plus 16 host-side Tool Call Hooks (8 per domain), for 99 in total: 62 server, 26 host, 11 user. The paper states this covers 18 fine-grained categories. The named server-side ones include tool poisoning, function overlapping, preference manipulation, tool shadowing, function-return injection and rug-pull; the original host-side ones include intent injection, data tampering and replay injection; the user-side ones include malicious code execution, credential theft and remote access control.
    • Tool Call Hook: The compromised dispatch layer, after the pre-execution audit has checked the declaration but before actual execution, replaces the specified benign call with terminal::run_command and an unauthorized shell command. At most once per task. The 8 payloads per domain cover unauthorized file access, probing of security-sensitive files, and persistence-related modifications. Specific commands are not written here.
    • Models and baselines: The backends are DeepSeek-V4-Flash, DeepSeek-V4-Pro and GPT-5.6 Luna. The text policy audit uses DeepSeek-V4-Pro in all settings, and it is also one of the three backends. The baselines are Python adaptations of Agent-Aegis's TCG and TRI, replayed on the same tool-call records collected by MTGuard's execution. TCG checks for high-risk shell and command obfuscation, and adds protected-path and dangerous-shell checks; TRI only detects returned text and does not rewrite results.
    • Metrics and protocol: DR is the number of detected unsafe calls divided by the total number of unsafe calls, with the numerator coming from pre-execution or post-execution rejections. FPR is the number of safe calls wrongly rejected divided by the total number of safe calls. Labels are determined by each case's execution-based evaluator according to the attack-success signature; DR counts only calls confirmed unsafe, and the denominator varies with the model. Rejections are recorded as counterfactual verdicts that do not block execution and do not modify results. The paper does not report the number of repetitions.
    • Policies: Before execution there are 7 deterministic rules: sensitive files, dangerous shell, SSH persistence, suspicious URLs deviating from the task, shadowed tool names, task-ticker mismatch, and repeated navigation; the repetition threshold is set to 3. Before and after execution there are 3 natural-language rules each, restricting credentials, shell initialization files, SSH keys and privilege-escalation probes unrelated to the task, rejecting endpoints that deviate from the task, and requiring the ticker, destination and website to be consistent with the user task. Code rules precede the LLM.

    Main Results

    According to Table 1, the overall tool-call-level DR is:

    Swipe horizontally to read the table

    ConfigurationMTGuardTCGTRI
    Browser / DS-V4-Flash53.5% (23/43)4.7% (2/43)0.0% (0/43)
    Browser / DS-V4-Pro44.8% (13/29)10.3% (3/29)0.0% (0/29)
    Browser / GPT-5.6 Luna60.0% (15/25)16.0% (4/25)0.0% (0/25)
    Financial / DS-V4-Flash46.2% (18/39)15.4% (6/39)0.0% (0/39)
    Financial / DS-V4-Pro37.0% (17/46)6.5% (3/46)0.0% (0/46)
    Financial / GPT-5.6 Luna51.7% (30/58)3.4% (2/58)0.0% (0/58)
    • Total: The authors report that across the six configurations MTGuard detected 116/240, an overall DR of 48.3%; TCG detected 20, DR 8.3%; TRI was 0.0% on these trajectories. The 48.3% and 8.3% in the abstract are consistent with Section 4.2; 48.3% is the pooled proportion, not the unweighted average of the six cells.
    • Authors' interpretation: The authors state that the advantage is especially pronounced on the host side, because monitoring and post-execution verification can see the mismatch between the declaration and the actual command caused by the Tool Call Hook; TCG sees only the original declaration, and TRI looks for injection-type patterns in the result text.
    • Differences within the same table: On the user side, MTGuard is 100.0% in all six cells and is the same as TCG, while TRI remains 0.0%. The server side is lower than the host side and user side in the same table; on the browser, DS-V4-Pro's server side is 12.5% (2/16), the lowest MTGuard cell for that source.

    By Attack Source

    • Total: Section 4.2 gives user side 100.0% (16/16), host side 75.0% (48/64), server side 32.5% (52/160). Pooled by domain, the browser agent is 52.6% (51/97) and the financial agent 45.5% (65/143). On the host side both baselines are 0.0%.
    • Authors' interpretation: The authors consider that on the user side the commands or sensitive-resource access are written in the declared parameters; on the host side detections concentrate on the Tool Call Hooks that cause a mismatch between declaration and actual behavior. On the server side many attacks still call legitimate tools with syntactically valid parameters, changing only the choice, parameters, preferences or return values, leaving traces close to normal behavior.
    • Domain differences: The authors consider that the browser server side has signals such as suspicious URLs, shadowed navigation tools and repeated navigation; on the financial side many attacks change the ticker, preferences or returned values while maintaining the expected structure of legitimate Yahoo Finance calls.

    False Positives and Audit Latency

    • FPR: In Table 2, MTGuard is 3.5%, 1.8%, 6.5% (browser, in the order DS-V4-Flash, DS-V4-Pro, GPT-5.6 Luna) and 3.3%, 1.7%, 5.2% (financial, same order). The authors give an unweighted average of 3.7%, against TCG 0.3% and TRI 0.4%; they also state a browser average of 3.9% and a financial average of 3.4%. The authors consider that browser trajectories are longer and noisier, and that benign repeated navigation and cross-site jumps may be taken as replay or task deviation. The authors link the overall FPR to the allow-by-default of post-execution verification: if consistent with the declaration, it is allowed by default. The paper does not give the denominator of safe calls for each group.
    • Latency: The main text, with Figure 2: pre-execution averages of 5.93 seconds (browser) and 5.68 seconds (financial), post-execution 6.74 and 6.40 seconds. The authors state that when both stages are invoked, each tool call adds about 12.39 seconds. The measurement includes only the LLM audit, and the authors state that it does not include deterministic rules, tool execution, or sandbox or eBPF overhead. The abstract separately states an average additional latency of about 10 seconds across settings; the paper does not explain how the two correspond. The authors consider post-execution slower because the prompt includes the result, the behavior tree and DNS events, and consider the latency bounded and possibly acceptable for security-sensitive applications.

    Stage Ablation

    • Setup: PRA keeps only the pre-execution audit; PRV keeps behavior monitoring and post-execution verification (Table 3). The authors give overall DR: PRA 25.0%, PRV 31.7%, full system 48.3%, and the full system has a higher overall DR than both variants in all six configurations.
    • Complementarity: The authors report that PRA detects all user-side unsafe calls, and 0.0% on the host side. PRV is 75.0% on the host side and 6.3% on the user side. On the server side the full system is 32.5%, PRA 27.5%, PRV 16.9%. Not every attack-source cell is strictly higher than the variants: on the browser server side the full system equals PRA, and on the host side the full system equals PRV.
    • Authors' interpretation: The authors consider that the two stages correspond to different failure modes, and that using only one is not ideal.

    Other Ablations and Analyses

    • ASR without defenses (Appendix B Table 4, counted by case): host side 87.2% (68/78), server side 38.2% (71/186), user side 33.3% (11/33).
    • GPT-5.6 Luna's user-side ASR: browser 20.0%, financial 16.7%; the authors consider that it more often refuses to turn malicious user instructions into unsafe calls.
    • Each attack source induces unsafe calls in at least some settings; unsuccessful cases do not enter the DR denominator.
    • TRI is 0.0% in all cells of Table 1; on the user side TCG and MTGuard are both 100.0%.
    • The paper has no other parameter sweeps. Post-execution rejection cannot undo side effects that have already occurred; the DR here is again a non-blocking counterfactual verdict.
  5. What are some points that can be further explored?

    The authors note that the prototype only covers local MCP tools, and that a post-execution denial cannot undo side effects that have already occurred.

    Limitations and Future Directions Noted by the Authors

    • Interface Scope (Section 5.1): The authors state that the current prototype and evaluation target only locally deployed MCP tools. Conceptually, it can be mapped to function-calling APIs, LangChain tools, local functions, shell, and REST wrappers, but requires clear interception boundaries and control over the execution environment; remote execution or platforms lacking compatible sandboxes and system-level tracing may require provider-side instrumentation.
    • Runtime Visibility (Section 5.1): Detection is constrained by the signals visible to the monitor. Currently, process, file, and network events are collected, including DNS-related metadata, but network payloads or application-level data flows are not inspected. The authors believe this may miss malicious behavior hidden in encrypted traffic, in-memory computation, or unobserved external services.
    • No Rollback (Section 5.1): Post-execution verification only detects unsafe behavior after the tool has executed. Unsafe results can be suppressed, but system-level side effects that have already occurred cannot be automatically undone.
    • Future Directions (Section 5.1): The authors list richer data-flow signals, payload-aware network inspection, selective online termination, and transactional execution or rollback.

    Experimental Coverage

    • The evaluation uses MCP-SafetyBench's browser automation and financial analysis, plus Tool Call Hook, totaling 99 attack cases, three backend models, and three source types: server/host/user (Section 4.1).
    • Text audit is fixed to DeepSeek-V4-Pro; baselines are Agent-Aegis's TCG and TRI, replayed on the same tool-call traces (Sections 4.1–4.2).
    • DR and FPR are computed per tool call, with labels from the case's built-in execution-based evaluator; refusal does not block execution (Section 4.1). The paper does not report the number of repetitions, nor the task completion rate after actual blocking.
    • Runtime evidence includes process, file, network, and DNS responses within Docker; file events record file names rather than absolute paths (Section 3.3). The paper does not report the sampling settings of the audit LLM, nor the denominator of safe calls for FPR in Table 2.
    • The ablation only compares PRA and PRV (Table 3). The case-level ASR without defense is in Appendix B, Table 4.
  6. Summarize the main content of the paper

    MTGuard detects unsafe MCP calls by comparing declarations with runtime evidence, with an overall DR of 48.3%, but only 32.5% on the server side.

    MTGuard is a hybrid analysis defense protecting LLM agents' MCP tool calls, deployed as an independent guard agent.

    • Problem: Call declarations, metadata, and return text can be disconnected from actual system behavior; whether the same file or network operation is harmful depends on the task and tool declaration. The authors are particularly concerned about tool execution hijacking.
    • Approach: Before dispatch, code rules and LLM audit parameters are used, and free-text descriptions that could be poisoned are discarded; during execution, eBPF in Docker records processes, files, networks, and DNS, aggregated into a tool behavior tree rooted at that call; after completion, consistency verification between declarations and observations is performed. No decisions are made during monitoring. Refusals occur before dispatch or by withholding results after completion; post-completion refusals do not roll back side effects.
    • Main Results: On 99 attack cases, two domains, DeepSeek-V4-Flash, DeepSeek-V4-Pro, and GPT-5.6 Luna, MTGuard's overall DR is 48.3% (116/240), TCG is 8.3% (20 detections), and TRI is 0.0% (Table 1, Section 4.2). User-side is 100.0% (16/16), and TCG is also 100.0%; host-side is 75.0% (48/64), with both baselines at 0.0%; server-side is 32.5% (52/160), with DS-V4-Pro on browser at only 12.5% (2/16).
    • Cost and Ablation: The non-weighted average FPR across six configurations is 3.7% (Table 2). The authors state that the two-stage LLM audit adds approximately 12.39 seconds per call, while the abstract also mentions approximately 10 seconds. The overall DR for PRA and PRV is 25.0% and 31.7%; PRA's host-side is 0.0%, and PRV's user-side is 6.3%.
    • Authors' Conclusion: The authors state that joint analysis can cover different failure modes when only messages or only execution traces are considered, and believe that false positives and audit latency may be acceptable for security-sensitive applications. Section 5.1 also states that evidence is limited to local MCP tools, the monitor cannot see payloads and memory behavior, and cannot undo system side effects that have already occurred.

Related papers

Read originalarxiv.org