Metadata-Version: 2.5
Name: mcp-shield-proxy
Version: 0.2.3
Summary: Runtime security gateway, shadow isolation, and honeytoken deception for the Model Context Protocol (MCP).
Project-URL: Homepage, https://github.com/mcp-shield/mcp-shield
Project-URL: Documentation, https://github.com/mcp-shield/mcp-shield#readme
Project-URL: Repository, https://github.com/mcp-shield/mcp-shield
Project-URL: Changelog, https://github.com/mcp-shield/mcp-shield/blob/main/CHANGELOG.md
Author: MCP-Shield Contributors
License: MIT License
        
        Copyright (c) 2026 The Blue Pheonix
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: ai-agents,honeytoken,mcp,proxy,sandbox,security
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.11
Requires-Dist: httpx>=0.27.0
Requires-Dist: rich>=13.0.0
Requires-Dist: typer>=0.12.0
Provides-Extra: agent
Requires-Dist: mcp[cli]>=2.0.0; extra == 'agent'
Requires-Dist: openai>=1.40.0; extra == 'agent'
Requires-Dist: python-dotenv>=1.0.0; extra == 'agent'
Provides-Extra: dashboard
Requires-Dist: fastapi>=0.115.0; extra == 'dashboard'
Requires-Dist: uvicorn[standard]>=0.30.0; extra == 'dashboard'
Requires-Dist: websockets>=12.0; extra == 'dashboard'
Provides-Extra: dev
Requires-Dist: build>=1.2.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: twine>=5.0.0; extra == 'dev'
Description-Content-Type: text/markdown

# 🛡️ MCP-Shield

### Zero-Trust Runtime Security for AI Agents

**Protect your AI coding agents from indirect prompt injection, unauthorized tool execution, sensitive data exposure, and malicious MCP servers.**

MCP-Shield is a local-first runtime security gateway for the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/). It acts as a security layer between AI agents and the MCP servers they use, inspecting tool interactions and applying security policies before actions reach downstream tools.

> **Don't stop AI agents from working. Stop compromised instructions from turning into dangerous actions.**

<p align="center">
  <img src="docs/assets/banner.png" alt="MCP-Shield — Zero-Trust Security for AI Agents" width="100%">
</p>

<p align="center">
  <a href="https://github.com/The-Blue-Pheonix/MCP-Shield"><img src="https://img.shields.io/badge/Project-MCP--Shield-blueviolet?style=for-the-badge" alt="MCP-Shield"></a>
  <img src="https://img.shields.io/badge/Python-3.11%2B-blue?style=for-the-badge&logo=python&logoColor=white" alt="Python 3.11+">
  <img src="https://img.shields.io/badge/Protocol-MCP-black?style=for-the-badge" alt="MCP">
  <img src="https://img.shields.io/badge/License-MIT-green?style=for-the-badge" alt="MIT License">
  <img src="https://img.shields.io/badge/Status-Development-orange?style=for-the-badge" alt="Development">
</p>

<p align="center">
  <a href="#-why-mcp-shield">Why MCP-Shield</a> •
  <a href="#-architecture">Architecture</a> •
  <a href="#-security-features">Features</a> •
  <a href="#-installation">Installation</a> •
  <a href="#-integrations">Integrations</a> •
  <a href="#-testing">Testing</a>
</p>

---

## 📸 Screenshots & Demo

> Add the actual screenshots to `docs/assets/` before publishing this README. The filenames below are the intended project asset paths, not existing screenshots.

### Security Dashboard

<p align="center">
  <img src="docs/assets/dashboard.png" alt="MCP-Shield Security Dashboard" width="100%">
  <br>
  <em>Live security events, tool activity, session state, and policy decisions.</em>
</p>

### Agent Arena

<p align="center">
  <img src="docs/assets/agent-arena.png" alt="MCP-Shield Agent Arena" width="100%">
  <br>
  <em>Observe AI-agent tool interactions and simulated security scenarios.</em>
</p>

### Shadow Workspace & Diff Review

<p align="center">
  <img src="docs/assets/shadow-diff.png" alt="MCP-Shield Shadow Workspace Diff" width="100%">
  <br>
  <em>Review modifications made inside an isolated shadow workspace.</em>
</p>

### Security Event Demonstration

<p align="center">
  <img src="docs/assets/demo.gif" alt="MCP-Shield Runtime Security Demonstration" width="100%">
</p>

---

## 🚨 Why MCP-Shield?

AI coding agents are becoming increasingly capable.

They can:
- Read source code and project files.
- Access GitHub repositories and issues.
- Execute terminal commands.
- Interact with APIs and external services.
- Send emails and publish comments.
- Use multiple MCP servers within a single workflow.

However, connecting an AI agent to powerful tools introduces a serious security problem.

An agent may read an untrusted document containing malicious instructions. Those instructions can influence its subsequent actions, potentially causing it to access private information, execute unintended commands, or transmit sensitive data.

This is known as **Indirect Prompt Injection**.

### The Lethal Trifecta

MCP-Shield focuses on the dangerous combination of three capabilities:

```text
       UNTRUSTED INPUT
       External instructions
              |
              |
              v
        PRIVATE DATA
        Files / Secrets
              |
              |
              v
     EXTERNAL EGRESS / EXECUTION
       APIs / Terminal / Git
```

When these three capabilities are available to the same agent, malicious instructions may lead to unauthorized data access or exfiltration.

MCP-Shield introduces a runtime security layer to monitor and control these interactions.

### The problem

| Without runtime protection | With MCP-Shield |
|---|---|
| Untrusted instructions can influence tool usage | Configurable taint tracking |
| Sensitive file access may go unnoticed | Sensitive-path inspection |
| Fake credentials may be transmitted | Honey-token detection |
| Tool definitions may change unexpectedly | SHA-256 tool fingerprinting |
| Dangerous external actions may execute immediately | Human approval workflow |
| Agent modifications may affect the original workspace | Shadow-copy workflow |

These controls protect supported MCP execution paths; they do not automatically protect every native tool an agent may use outside MCP.

---

## 🏗️ Architecture

MCP-Shield follows a local-first security architecture.

The AI agent communicates with MCP-Shield through the MCP stdio transport. MCP-Shield launches the original downstream MCP server and inspects supported requests before forwarding them.

### High-Level Architecture

```mermaid
flowchart TB
    A["AI Coding Agent<br/>Antigravity / VS Code"] 
    B["MCP-Shield<br/>Stdio Reverse Proxy"]
    C["Security Decision Engine"]
    
    D["Taint Tracking"]
    E["Honey-Token Detection"]
    F["Tool Fingerprinting"]
    G["Policy Enforcement"]
    H["Approval Workflow"]
    I["Shadow Workspace / Sandbox"]

    J["Original MCP Server"]
    K["Protected Resources<br/>Files / GitHub / APIs"]
    L["SQLite Audit Storage"]
    M["FastAPI Control Server"]
    N["Web Security Dashboard"]

    A <-->|"JSON-RPC / stdio"| B
    B <--> C

    C --> D
    C --> E
    C --> F
    C --> G
    C --> H
    C --> I

    C --> L
    C <--> M
    M <--> N

    B -->|"Authorized requests"| J
    J --> K
```

### Request Lifecycle

```mermaid
sequenceDiagram
    participant Agent as AI Agent
    participant Proxy as MCP-Shield Proxy
    participant Engine as Security Engine
    participant DB as SQLite
    participant Server as MCP Server
    participant User as Human User

    Agent->>Proxy: tools/call
    Proxy->>Engine: Inspect tool and arguments
    Engine->>DB: Read session and policy state
    Engine->>Engine: Evaluate security rules

    alt Request allowed
        Engine-->>Proxy: ALLOW
        Proxy->>Server: Forward request
        Server-->>Proxy: Tool result
        Proxy-->>Agent: Return result
    else Request blocked
        Engine->>DB: Record blocked event
        Engine-->>Proxy: BLOCK
        Proxy-->>Agent: Security error
    else Approval required
        Engine->>DB: Store pending approval
        Engine-->>Proxy: Freeze request
        Proxy->>User: Request approval
        User-->>Proxy: Approve or reject
        Note over Proxy,Server: Execute only after approval
    end
```

The approval workflow is designed around the original request lifecycle. It must not forward an approval-required operation before authorization.

### Main Components

| Component | Responsibility |
|---|---|
| MCP Proxy | Intercepts supported MCP stdio messages |
| Security Engine | Evaluates tool requests and security policies |
| Taint Tracker | Tracks sessions that consume configured untrusted input |
| Deception Engine | Generates and detects honey-tokens |
| Fingerprint Engine | Detects changes in MCP tool definitions |
| Shadow Workspace | Provides an isolated working copy |
| Approval Manager | Controls configured sensitive external actions |
| SQLite Database | Stores sessions, approvals, tokens and events |
| FastAPI Backend | Coordinates inspection and dashboard events |
| Web Dashboard | Displays runtime activity and security decisions |

---

## 🔐 Security Features

### 1. Smart Taint Tracking

Not all input is trustworthy.

MCP-Shield can mark a session as **TAINTED** after configured untrusted sources are read.

Examples include:
- GitHub issues.
- External documents.
- Web content.
- User-provided external data.

A tainted session is not necessarily compromised. It means the agent has consumed content that may contain adversarial instructions and should be subject to stricter policies.

```text
CLEAN SESSION
     |
     | Read untrusted content
     v
TAINTED SESSION
     |
     | Apply stricter policies
     v
Protected tool execution
```

### 2. Shadow Workspace Isolation

MCP-Shield uses a shadow workspace to separate supported agent modifications from the original project workspace.

```mermaid
flowchart TD
    A["Original Project"]
    B["Create Shadow Copy"]
    C["Agent Works in Shadow"]
    D["Inspect File Changes"]
    E{"User Decision"}
    F["Merge Changes"]
    G["Discard Shadow"]

    A --> B
    B --> C
    C --> D
    D --> E
    E -->|"Accept"| F
    E -->|"Reject"| G
```

The user can inspect the generated diff before accepting or discarding changes.

For arbitrary command execution, a separate operating-system or container isolation boundary is required. A copied directory alone is not a complete security sandbox.

### 3. Honey-Token Deception

MCP-Shield generates unique fake credentials for a session.

These tokens are planted in a decoy environment file within the shadow workspace.

If an agent attempts to transmit a planted token through a configured outbound action, the deception engine can detect the match and block that action.

Supported detection transformations in the implementation include:

- Raw token.
- Reversed token.
- URL encoding.
- Base64 encoding.

Honey-tokens are detection signals, not real credentials. They do not guarantee detection of every possible transformation, encryption method, or exfiltration channel.

### 4. Exit-Door Protection

Certain actions have consequences outside the local workspace.

Examples:
- Publishing a GitHub comment.
- Sending an email.
- Pushing code.
- Triggering external integrations.

MCP-Shield can require explicit human approval for configured exit-door operations.

```text
Agent requests external action
           |
           v
   Security inspection
           |
           v
    Approval required
           |
       User review
        /      \
       /        \
   APPROVE     REJECT
      |           |
      v           v
  Execute      Block
```

### 5. Rug-Pull Detection

MCP servers expose tool definitions describing their names, descriptions and input schemas.

A malicious or compromised server may unexpectedly change a tool definition.

MCP-Shield calculates SHA-256 fingerprints of canonicalized tool definitions and compares subsequent versions with stored baselines.

An unexpected change can generate a security event and block the affected tool listing according to the configured enforcement behavior.

### 6. Lethal Trifecta Configuration Audit

MCP-Shield includes a configuration auditor that examines MCP server names, commands, arguments and environment-variable names for indicators of:

- Untrusted input.
- Private data access.
- External egress or execution.

It generates a risk classification:

| Risk level | Meaning |
|---|---|
| LOW | Fewer than two categories detected |
| MEDIUM | Two categories detected |
| CRITICAL | All three categories detected |

This is a heuristic configuration audit, not a proof that a configuration is safe or unsafe.

### 7. Live Security Monitoring

The FastAPI backend and WebSocket event system support live security monitoring.

The dashboard is designed to expose events such as:

- `TOOL_EVENT`
- `TAINT_TRIGGERED`
- `HONEYPOT_SERVED`
- `TRAP_TRIGGERED`
- `RUG_PULL_DETECTED`
- `APPROVAL_REQUIRED`
- `APPROVAL_RESOLVED`
- `SHADOW_UPDATED`

---

## ⚙️ Installation

MCP-Shield targets Python 3.11 and newer.

### Install from source

Clone the repository:

```bash
git clone https://github.com/The-Blue-Pheonix/MCP-Shield.git

cd MCP-Shield
```

Create a virtual environment:

```bash
python -m venv .venv
```

Activate it:

**Windows PowerShell**

```powershell
.venv\Scripts\Activate.ps1
```

**Linux / macOS**

```bash
source .venv/bin/activate
```

Install the project and its dashboard dependencies:

```bash
python -m pip install --upgrade pip
pip install -e ".[dashboard,agent,dev]"
```

> The extras must be kept aligned with the dependencies and entry points in `pyproject.toml`.

### PyPI installation

Once the official distribution is published and verified, installation will be:

```bash
pip install mcp-shield
```

The package name and release availability should be verified before announcing this command as a working public installation route.

---

## 🚀 Quick Start

### Step 1 — Start the MCP-Shield Control Server

From the repository root:

```bash
mcp-start --project-dir .
```

By default, the local control server listens on:

```text
http://127.0.0.1:8000
```

The dashboard can be opened in the browser automatically.

### Step 2 — Check the control server

```bash
curl http://127.0.0.1:8000/api/health
```

Expected response:

```json
{
  "status": "ok"
}
```

### Step 3 — Run the proxy

Example using a GitHub MCP server:

```bash
mcp-shield proxy \
  --server-name github \
  --session-id demo-session \
  -- npx -y @modelcontextprotocol/server-github
```

On Windows PowerShell, the same command can be entered on one line:

```powershell
mcp-shield proxy --server-name github --session-id demo-session -- npx -y @modelcontextprotocol/server-github
```

Make sure the required environment variables for the downstream server are available in the process environment.

### Step 4 — Inspect configuration

MCP-Shield can audit an MCP JSON configuration and generate a wrapped configuration snippet:

```bash
mcp-shield init --config path/to/mcp_config.json
```

Specify a custom output path:

```bash
mcp-shield init --config path/to/mcp_config.json --output shielded_config.json
```

### Step 5 — Inspect runtime paths

```bash
mcp-shield status
```

The CLI reports the resolved project directory, data directory, SQLite database path and policy path.

---

## 🔌 Integrations

MCP-Shield is designed to sit between existing MCP clients and their downstream MCP servers.

The initial integration targets are Google Antigravity and Visual Studio Code with supported MCP clients.

### Google Antigravity

Antigravity uses an `mcpServers` configuration object for local MCP servers.

A protected server entry can use the MCP-Shield proxy as its launch command:

```json
{
  "mcpServers": {
    "github-shield": {
      "command": "mcp-shield",
      "args": [
        "proxy",
        "--server-name",
        "github",
        "--session-id",
        "antigravity-session",
        "--",
        "npx",
        "-y",
        "@modelcontextprotocol/server-github"
      ]
    }
  }
}
```

Add the original server's required environment variables to the entry.

### Visual Studio Code

VS Code uses a `servers` configuration object for MCP servers.

Example:

```json
{
  "servers": {
    "github-shield": {
      "type": "stdio",
      "command": "mcp-shield",
      "args": [
        "proxy",
        "--server-name",
        "github",
        "--session-id",
        "vscode-session",
        "--",
        "npx",
        "-y",
        "@modelcontextprotocol/server-github"
      ]
    }
  }
}
```

Reload the MCP connection after updating the configuration.

> **Integration scope:** these examples route the configured MCP server through MCP-Shield. They do not intercept native agent tools that bypass MCP. Automatic configuration discovery, safe backups, restoration and end-to-end client verification should be treated as separate integration acceptance criteria.

---

## 🧪 Testing

MCP-Shield uses pytest for automated testing.

Install development dependencies:

```bash
pip install -e ".[dev]"
```

Run the test suite:

```bash
pytest -v
```

Run a specific test module:

```bash
pytest tests/test_proxy.py -v
```

The exact test filenames should be checked against the current repository.

### Security Test Scenarios

| Scenario | Expected security behavior |
|---|---|
| Normal file listing | Allowed |
| Configured untrusted source read | Taint event |
| Sensitive file access | Policy evaluation |
| Honey-token in outbound payload | Block and record detection |
| Changed MCP tool definition | Rug-pull event |
| Configured exit-door action | Approval workflow |
| Rejected approval | Operation not forwarded |
| Shadow workspace modification | Diff available for review |
| Invalid MCP configuration | Report error without overwriting original |

### Benchmarking

The project includes a benchmark suite intended to compare:

1. No Shield.
2. Basic blocker.
3. MCP-Shield.

Metrics of interest:

- Attack prevention rate.
- Legitimate task completion rate.
- False positive rate.
- Approval frequency.
- Proxy latency.
- Runtime stability.

Only measured benchmark results should be presented as actual performance claims. Preview data and target metrics must be labelled separately.

---

## 🗂️ Project Structure

The repository is organized around the following major areas:

```text
MCP-Shield/
│
├── src/
│   └── mcp_shield/
│       ├── cli.py
│       ├── proxy.py
│       ├── server.py
│       ├── engine.py
│       ├── auditor.py
│       ├── config.py
│       ├── db.py
│       ├── deception.py
│       ├── shadow.py
│       ├── sandbox.py
│       ├── routes_b.py
│       ├── policy.json
│       └── static/
│
├── agent/
├── backend/
├── benchmark/
├── demo_servers/
├── docker/
├── frontend/
├── proxy/
├── sample_repo/
├── sample_repo_clean/
├── tests/
│
├── docs/
│   └── assets/
│
├── pyproject.toml
├── requirements.txt
├── CHANGELOG.md
└── LICENSE
```

The exact contents may evolve as the package is consolidated around `src/mcp_shield/`.

---

## ⚠️ Security Model & Limitations

MCP-Shield is a defense-in-depth project. It is not a guarantee against every form of prompt injection or agent compromise.

Important limitations:

1. **MCP coverage:** only MCP connections routed through the proxy are inspected. Native agent tools and other unwrapped execution paths may bypass it.
2. **Local process security:** a stdio proxy does not automatically isolate arbitrary operating-system processes.
3. **Shadow isolation:** a shadow copy protects the original workspace from supported file modifications, but is not equivalent to a hardened container or VM.
4. **Honey-token detection:** detection depends on known token representations and inspected outbound tool arguments.
5. **Configuration audit:** keyword-based classification is heuristic.
6. **Tool fingerprinting:** a definition change is a signal requiring investigation, not proof of malicious behavior.
7. **Policy correctness:** weak or incomplete rules can allow unsafe actions or block legitimate work.
8. **Control-server availability:** enforcement behavior during control-server failures must be tested and configured safely.

Do not expose the local control server to an untrusted network without adding authentication, authorization, and appropriate network protections.

---

## 🛣️ Roadmap

- [x] Python package foundation
- [x] MCP stdio proxy foundation
- [x] FastAPI control server
- [x] SQLite event and session storage
- [x] Policy engine foundation
- [x] Tool fingerprinting foundation
- [x] Shadow workspace and deception components
- [x] Configuration auditor
- [ ] Complete end-to-end security enforcement validation
- [ ] Production-ready Antigravity adapter and recovery workflow
- [ ] Production-ready VS Code / Copilot adapter and recovery workflow
- [ ] Cross-platform integration testing
- [ ] Dashboard and approval lifecycle hardening
- [ ] Reproducible benchmark results
- [ ] TestPyPI validation
- [ ] Official PyPI release
- [ ] Remote Streamable HTTP proxy support
- [ ] Additional coding-agent integrations

> Check the actual test and integration status before changing roadmap items to completed.

---

## 🤝 Contributing

Contributions, security feedback, bug reports and feature suggestions are welcome.

### Development Setup

```bash
git clone https://github.com/The-Blue-Pheonix/MCP-Shield.git

cd MCP-Shield

python -m venv .venv

pip install -e ".[dashboard,agent,dev]"
```

Run tests:

```bash
pytest -v
```

### Contribution Guidelines

- Keep security decisions deterministic and auditable.
- Never log real secrets or credentials.
- Preserve valid MCP protocol behavior.
- Keep protocol messages on stdout and diagnostic logs on stderr.
- Include tests for new security controls.
- Document known limitations.
- Do not claim unmeasured security or benchmark results.

For significant changes, open an issue before submitting a pull request.

---

## 📚 References

- [Model Context Protocol](https://modelcontextprotocol.io/)
- [MCP Specification — stdio transport](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports)
- [MCP Specification — Tools](https://modelcontextprotocol.io/specification/2025-06-18/server/tools)
- [Google Antigravity](https://antigravity.google/)
- [Visual Studio Code MCP documentation](https://code.visualstudio.com/docs/copilot/customization/mcp-servers)
- [Python Packaging Guide](https://packaging.python.org/)
- [PyPI](https://pypi.org/)

---

## 📄 License

MCP-Shield is released under the [MIT License](LICENSE).

---

<p align="center">
  <strong>Built by Team BLUE_PHEONIX</strong>
  <br>
  <em>Work Freely. Guard the Exit Doors.</em>
</p>

<p align="center">
  ⭐ If you find MCP-Shield useful, consider giving the repository a star.
</p>