All posts
AI

How Prompt Injection Reaches Coding Agents Through MCP Tools

How Prompt Injection Reaches Coding Agents Through MCP Tools

Coding agents read a lot of text they didn’t write. Issues, pull request comments, README files, documentation pages, chat threads, log output, package metadata. Through MCP tools, they read it automatically, as part of doing their job. Any of that text can carry instructions. When it does, the agent may follow them with the developer’s own access to code, secrets, and the terminal.

This guide explains how MCP prompt injection reaches coding agents, what attackers try to make agents do, real cases that show the pattern, and the controls that stop it.

What is MCP prompt injection?

MCP prompt injection is an attack where malicious instructions reach an AI agent through an MCP tool, either in the tool’s own description or in the data the tool returns, and steer the agent into actions the user never asked for.

It’s a form of indirect prompt injection. The developer never types the malicious instruction. It arrives inside content the agent fetches while working, and the model can’t reliably tell data it’s reading from instructions it should follow.

Why coding agents are a prime target

Coding agents combine three things that make prompt injection dangerous:

  1. Untrusted input. They pull in issues, pull requests, docs, web pages, and messages written by anyone.
  2. Access to sensitive data. They run inside a developer’s environment, with access to source code, environment variables, credentials, and private repositories.
  3. The ability to act. They can edit files, run shell commands, push commits, open pull requests, and call other tools.

When one agent has all three, a single injected instruction can turn reading into acting. Security researchers often describe this combination as the core risk of agentic systems.

How injected instructions reach coding agents through MCP tools

Entry point How it reaches the agent Example
Issue and pull request content A code host MCP tool returns issue text or review comments An issue in a public repo tells the agent to read a private repo and post its contents
README and documentation files A file or docs MCP tool returns project docs Hidden text in a README tells the agent to run a setup command that sends secrets out
Chat messages A team chat MCP tool returns channel messages A message asks the agent to “fix” a config file by adding a new command
Web pages A browser or fetch MCP tool returns page content A docs page hides instructions in HTML comments or invisible text
Tickets and tasks A project tracker MCP tool returns ticket descriptions A ticket tells the agent to disable a test or change an access rule
Logs and error output A monitoring MCP tool returns log lines A log entry crafted by an attacker contains instructions to the agent
Tool descriptions The MCP server itself describes its tools A tool description tells the agent to read a private key before every call

The last row is tool poisoning, where the server itself is malicious or compromised. The others are content injection, where a trusted server returns content an attacker controls. Coding agents face both.

What attackers try to make coding agents do

  • Leak secrets. Read environment files, keys, or tokens and send them out through a web request, a commit, a comment, or another tool call.
  • Leak private code. Read a private repository and post its contents somewhere public.
  • Run commands. Execute shell commands on the developer’s machine or in CI.
  • Change the agent’s own setup. Edit MCP configuration files to add a malicious server, which then runs with the developer’s privileges.
  • Plant code. Add a backdoor, weaken a check, or change a dependency, hidden inside an otherwise normal change.
  • Spread. Write new injected instructions into issues, docs, or code so the next agent picks them up.

Real cases that show the pattern

A public issue that leaked private repositories (2025). Security researchers at Invariant Labs showed that a malicious issue in a public repository could hijack an agent using the GitHub MCP server. When a user asked the agent to look at open issues, the injected text led the agent to read the user’s private repositories and publish their contents in a pull request on the public repo. The MCP server worked as designed. The problem was what the agent did with the data it read.

A chat message that rewrote an agent’s config (CVE-2025-54135). Researchers at Aim Labs found that the Cursor code editor wrote suggested edits to its MCP configuration file to disk before the user approved them. A prompt injection delivered through a chat MCP server could get the agent to add a new “server” to that file, which ran attacker-chosen commands. The issue was fixed in Cursor 1.3.

A shared config that changed after approval (CVE-2025-54136). Check Point Research showed that once a project’s MCP configuration was approved, it could later be changed in a shared repository to run different commands without asking again. Also fixed in Cursor 1.3.

These cases share a lesson: the danger comes from the combination of untrusted content, broad access, and tools that act, not from any single bug.

Why prompts and model training aren’t enough

Models are getting better at resisting injected instructions, and system prompts can warn them not to follow text in tool results. Both help. Neither is a guarantee. An attacker only needs one phrasing that works, and injected text can be hidden in formats people never look at.

The controls that hold up are the ones that don’t depend on the model’s judgment: limiting what the agent can reach, checking what comes back from tools, and stopping risky actions before they run.

How to stop MCP prompt injection in coding agents

Limit what each coding agent can reach

  • Connect only approved MCP servers.
  • Give each agent the fewest tools it needs. An agent triaging issues doesn’t need push access.
  • Scope tools to specific repositories, projects, and channels, not everything the developer can see.
  • Avoid giving one agent both access to private data and a way to publish to public places in the same session.

Check what comes back from tools

  • Scan tool responses for injected instructions before they reach the model.
  • Scan tool names and descriptions when servers are added and whenever they change.
  • Apply data loss prevention to tool responses and outgoing tool calls, so secrets and private code can’t be sent out.

Control risky actions

  • Separate read tools from write tools, and require approval for destructive or outward-facing actions.
  • Block agents from editing their own MCP configuration and other agent settings files.
  • Restrict shell and execution tools to specific commands and arguments.
  • Pin MCP server versions and review changes before they reach developers.

Keep a record

  • Log every tool call with its arguments and results, including calls that were denied.
  • Review logs for patterns like a read from a private source followed by a write to a public one.

Test regularly

  • Red team coding agents with injected issues, docs, and messages to see whether controls hold.

How Airia protects coding agents at the MCP layer

Airia puts controls at the point where coding agents call tools, so they work no matter which model or editor a developer uses:

  • One control point for tool access. Airia’s MCP Gateway requires admin approval for MCP servers, sets access by role at the app, tool, and parameter level, scans tool names and descriptions for prompt injection, respects read-only and destructive tool annotations, and logs every call as succeeded, denied, or errored.
  • Injection and data protection. Airia Secure blocks prompt injection in under 300 milliseconds and applies data loss prevention to AI traffic, including MCP server responses.
  • Deterministic limits. Agent Constraints enforce rules on what agents can do, such as which actions need approval, separate from the model’s judgment.
  • Find unapproved servers. Airia Discover includes MCP Server Detection and Code Repository Scanning, so you can see the MCP servers developers have connected.
  • Test before attackers do. Agentic Red Teaming probes agents with attacks mapped to the OWASP LLM Top 10 and MITRE ATLAS.

FAQ

What is MCP prompt injection? It’s when malicious instructions reach an AI agent through an MCP tool, in a tool description or in the data a tool returns, and steer the agent into actions the user didn’t ask for.

How is MCP prompt injection different from tool poisoning? Tool poisoning puts instructions in the tool’s own description, which means the server is malicious or compromised. Content injection puts instructions in the data a trusted tool returns, such as an issue or a web page. Both are forms of MCP prompt injection.

Can coding agents be protected from prompt injection? Not by the model alone. The strongest protection combines least-privilege tool access, scanning of tool responses, approval for risky actions, and full logging.

Which coding agents are affected? Any agent that reads untrusted content through tools and can act on what it reads. The risk depends more on the agent’s access and tools than on which editor or model it uses.

Let developers use coding agents without handing attackers the keys. Request a demo to see how Airia stops prompt injection at the MCP layer before an agent acts on it.

Put these ideas to work.

Schedule a 30-minute walkthrough with our team.

Talk through your use case