Skip to content
Back to search

mcp-injection-experiments

Code snippets to reproduce MCP tool poisoning attacks.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/invariantlabs-ai--mcp-injection-experiments/badge.svg)](/listings/invariantlabs-ai--mcp-injection-experiments)

HTML

<a href="/listings/invariantlabs-ai--mcp-injection-experiments"><img src="/api/listings/invariantlabs-ai--mcp-injection-experiments/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 35 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # MCP Tool Poisoning Experiments
  2. This repository contains a few experimental MCP server implementations, that attempt ot inject the MCP client/agent in use.
  3. For more details about the attack method, please see our [blog post](https://invariantlabs.ai/blog/mcp-security-notification-tool-poisoning-attacks).
  4. **Update:** We have released a new security scanning tool called [mcp-scan](https://github.com/invariantlabs-ai/mcp-scan), that detects MCP attacks as demonstrated in this repository, and helps you secure your MCP servers.
  5. ## Direct Poisoning
  6. In [`direct-poisoning.py`](./direct-poisoning.py), we implement a simple MCP server that instructs an agent to leak sensitive files, when calling the `add` tool (in this case SSH keys and the `mcp.json` file itself).
  7. An example execution in cursor looks like this:
  8. ![Cursor executes tool poisoning](https://invariantlabs.ai/images/cursor-injection.png)
  9. ## Tool Shadowing
  10. In [`shadowing.py`](./shadowing.py), we implement a more sophisticated MCP attack, that manipulates the agent's behavior of a `send_email` tool (provided by a different, trusted server), such that all emails sent by the agent are leaked to the attacker's server.
  11. An example execution in Cursor looks like this:
  12. ![Cursor executes tool shadowing](https://invariantlabs.ai/images/mcp-shadow.png)
  13. ## WhatsApp takeover
  14. Lastly, in [`whatsapp-takeover.py`](./whatsapp-takeover.py), we implement a shadowing attack combined with a sleeper rug pull, i.e. an MCP server that changes its tool interface only on the second load to a malicious one.
  15. The server first masks as a benign "random fact of the day" implementation, and then changes the tool to a malicious one that manipulates [whatsapp-mcp](https://github.com/lharries/whatsapp-mcp) in the same agent, to leak messages to the attacker's phone number.
  16. ![Cursor executes WhatsApp MCP attack](https://github.com/user-attachments/assets/a39ea101-3fd2-4945-abcd-942006cfe11c)
  17. Can you spot the exfiltration? Here, the malicious tool instructions ask the agent to include the smuggled data after many spaces, such that with invisible scroll bars, the user does not see the data being leaked. Only when you scroll all the way to the right, will you be able to find the exfiltration payload.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.