Invisible Threats from Model Context Protocol: Generating Stealthy Injection Payload via Tree-based Adaptive Search

Yulin Shen, Xudong Pan, Geng Hong, Min YangarXiv 2026

TL;DR

The open-source Model Context Protocol (MCP) standardizes how LLM agents interact with external tools, but it introduces a massive supply-chain vulnerability. This paper presents Tree-structured Injection for Payloads (TIP), a black-box attack that generates highly stealthy, semantically natural prompt injections from compromised tool servers, successfully hijacking advanced LLM agents even when protected by modern defenses.

What Problem Does This Paper Address?

As Large Language Models (LLMs) transition from standalone chatbots into autonomous agents, they increasingly rely on external tools (like weather plugins, code interpreters, and databases) to execute complex workflows. Anthropic's recently released Model Context Protocol (MCP) has rapidly become the industry standard for decoupling an LLM client from these third-party tool servers using structured JSON responses.

However, this architecture relies on an implicit trust assumption: the LLM client trusts the semantic integrity of the server's output. The authors identify a critical vulnerability in the temporal gap between tool installation and invocation, formalizing a stealthy update attack. In this scenario, an adversary publishes a legitimate tool to pass initial registration audits, but later modifies the backend server logic to inject malicious instructions into dynamic response fields.

Existing Indirect Prompt Injection (IPI) methods fail to exploit this effectively. Gradient-based methods (like GCG) generate high-perplexity gibberish strings that trigger anomaly filters and raise human suspicion, while existing black-box methods are computationally expensive and easily neutralized by modern defenses like recursive rewriting or perplexity gating.

Fig. 1: Attack scenario overview. A client relies on a third- party Model Context Protocol (MCP) server to provide struc- tured inputs to its locally deployed LLM-based tool. An adversary compromising the MCP server delivers a stealthy update containing a semantically coherent prompt injection embedded within legitimate response fields. The local LLM interprets this adversarial context as trusted input, executing malicious instructions while bypassing client-side defenses due to the payload’s syntactic and semantic plausibility.

Methods

The authors propose Tree-structured Injection for Payloads (TIP), a black-box framework that treats payload generation as an adaptive, coarse-to-fine tree search problem. Guided by a surrogate LLM acting as a mutable attacker agent, TIP optimizes malicious JSON payloads through three iterative stages:

  1. Branch Phase (Strategy-Guided Generation): Instead of guessing blindly, the attacker LLM first simulates a benign tool response based on the tool's metadata to ensure the payload blends in naturally. It then employs a Dual Coarse-to-Fine Strategy that separates high-level semantic intent (implicit induction vs. explicit control) from fine-grained structural adjustments (modifying JSON keys vs. values).
  2. Path-Aware Feedback: To prevent the search from getting trapped in local optima, TIP feeds the attacker model a chronological path of its highest-scoring historical trajectories, allowing it to recognize global optimization patterns. It also incorporates Defense-Aware Adaptation, dynamically mutating payloads based on observed defense failure modes (e.g., making payloads more concise if a summarization filter is detected).
  3. Prune Phase (Quality-Driven Selection): Candidate payloads are rigorously evaluated using a Monte Carlo approximation across a diverse batch of user instructions and victim models. Only the top-$K$ most transferable nodes are retained for the next generation, and the search terminates early once a predefined success threshold is met.
Fig. 2: Overview of the TIP framework for generating stealthy, transferable JSON payloads through a tree-based search. It includes three main stages: Branch, where tool response simulation and a dual coarse-to-fine strategy refine payload intent and structure; Prune, which evaluates candidates via transferability checks (e.g., Monte Carlo scoring) across diverse instructions and models; and Feedback & Iteration, optimizing payloads using path-aware feedback from historical high-scoring nodes.

Datasets

The authors evaluated TIP by extending the benchmark tools introduced in InjecAgent. They designed experiments around two high-impact adversarial objectives across four specific tools:

  • Fraud (Social Engineering/Phishing): Utilizing GetWeather and GetProduct tools, where success means the agent proactively recommends a malicious phishing URL to the user.
  • Data Steal (Context Exfiltration): Utilizing ExpediaBooking and ShipManager tools, where success means the agent extracts sensitive data (like tracking numbers or itineraries) and silently transmits it via an external tool call.

Payloads were trained on a small ensemble of open-source models (Qwen2.5-7B-Instruct, InternLM2.5-7B-Instruct, and GLM4-9B-Instruct) to simulate a strict black-box environment, and tested against major commercial and open-source victim backends (Qwen2.5-7B/72B-Instruct, Llama3.1-8B-Instruct, and Llama3.3-70B-Instruct).

Key Insights and Ideas

  • The Vulnerability of Unified Context: LLMs still process structured tool outputs within the same unified context window as trusted system prompts. Because they cannot inherently separate control from data, semantically plausible data can easily hijack the execution flow.
  • Global History Beats Local Gradients: Traditional black-box optimization often suffers from path degeneration. Presenting the LLM attacker with its own historical trajectory of improvement allows it to learn which semantic modifications correlate with success, leading to a steady upward optimization curve.
  • Stealth via Statistical Mimicry: By conditioning payload generation on simulated benign responses, TIP payloads achieve high semantic similarity to legitimate data, effectively neutralizing classification-based defenses like perplexity filters.

Key Results

  • High Efficacy & Efficiency: In undefended settings, TIP achieved a 100% Attack Success Rate (ASR) across three out of four tools. Crucially, it required an order of magnitude fewer queries than prior adaptive attacks (e.g., converging in just 100 queries on GetProduct compared to 2,580 queries for the TAP baseline).
  • Defense Evasion: Against rigorous defenses—including perplexity filtering, finetuned detectors, and sandwich prevention—TIP sustained an ASR above 50% (and up to 97.8% against finetuned detectors on ExpediaBooking), dramatically outperforming baseline methods which frequently dropped to 0%.
  • Real-World Exploitation: The authors successfully demonstrated the attack in end-to-end applications, including a local consumer setup using LM Studio (Qwen2.5-7B) and an enterprise developer setup using VS Code with GPT-4o. Despite GPT-4o's robust safety alignment, it succumbed to the injection and embedded malicious phishing links directly into the developer's workspace.
Fig. 3: Cosine similarity between generated payloads and legitimate responses. TIP payloads exhibit higher semantic similarity to benign data, reducing the likelihood of detection.

Limitations and Future Work

  • Optimization Latency: Although TIP's generated payloads are "universal" and instantly deployable once trained offline, the initial tree search still requires iterative querying of a victim model during the setup phase.
  • Single-Turn Constraints: The current framework focuses on immediate hijacking within the next turn. Future work will explore planting dormant, multi-turn persistent instructions that survive over extended sessions or within long-term memory banks.
  • Dynamic Arms Race: As defenses evolve toward active re-paraphrasing of all tool outputs via separate trusted LLMs, the authors envision extending TIP into a continuous game-theoretic learning framework that adapts to defense updates in real-time.

Summary updated

BibTeX
@misc{shen2026invisible,
  author = {Yulin Shen and Xudong Pan and Geng Hong and Min Yang},
  title = {{Invisible Threats from Model Context Protocol: Generating Stealthy Injection Payload via Tree-based Adaptive Search}},
  year = {2026},
  eprint = {2603.24203},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.24203},
}
Figure