Metadata-Version: 2.5
Name: agentgate-mcp
Version: 0.1.0
Summary: Runtime security gateway for AI agents (MCP): policy, poisoning/rug-pull detection, taint tracking and SIEM-ready audit logs.
Author: Mayank Sharma
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agents,ai-security,llm,mcp,prompt-injection,siem
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Security
Requires-Python: >=3.11
Requires-Dist: pydantic>=2.7
Requires-Dist: pyyaml>=6.0
Requires-Dist: rich>=13.0
Requires-Dist: typer>=0.12
Provides-Extra: dev
Requires-Dist: httpx>=0.27; extra == 'dev'
Requires-Dist: hypothesis>=6.100; extra == 'dev'
Requires-Dist: mcp>=2.0; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Requires-Dist: starlette>=0.37; extra == 'dev'
Requires-Dist: types-pyyaml; extra == 'dev'
Requires-Dist: uvicorn>=0.29; extra == 'dev'
Provides-Extra: http
Requires-Dist: httpx>=0.27; extra == 'http'
Requires-Dist: starlette>=0.37; extra == 'http'
Requires-Dist: uvicorn>=0.29; extra == 'http'
Provides-Extra: ml
Requires-Dist: huggingface-hub>=0.23; extra == 'ml'
Requires-Dist: numpy>=1.26; extra == 'ml'
Requires-Dist: onnxruntime>=1.17; extra == 'ml'
Requires-Dist: tokenizers>=0.15; extra == 'ml'
Description-Content-Type: text/markdown

# AgentGate

**A runtime security gateway for AI agents using MCP.** It tracks data flow across tool calls, sends detections to your SIEM, and is measured on an open attack benchmark.

[![CI](https://github.com/mayanksharma7804/Agent-Gate/actions/workflows/ci.yml/badge.svg)](https://github.com/mayanksharma7804/Agent-Gate/actions/workflows/ci.yml)
![Python](https://img.shields.io/badge/python-3.11%2B-blue)
![License](https://img.shields.io/badge/license-Apache--2.0-blue)

> Status: **v0.1.0 (pre-release).** Everything in the project plan's core is built and measured:
> stdio and HTTP proxies, seven detectors, taint tracking, SIEM pack, benchmark. See
> [Results](#results-frozen-run-29-nov-2026) and [Roadmap](#roadmap).

AgentGate sits between an MCP client (Claude Desktop, VS Code, Cursor, a custom agent) and each
MCP server. It inspects every JSON-RPC message, then allows it, denies it or asks a human. Every
decision becomes a structured audit event that can go to Splunk.

```
MCP client ──stdio/HTTP──▶ agentgate wrap / serve ──stdio/HTTP──▶ real MCP server(s)
                              │ manifest guard (pinning, rug pull, shadowing)
                              │ poisoning heuristics · classifier · LLM judge (optional)
                              │ argument policy (paths, shell, SSRF) · secrets & PII
                              │ result scanner · taint tracker (cross-server data flow)
                              ▼
                  audit.jsonl ──▶ Splunk HEC ──▶ Sigma rules + dashboard
```

![AgentGate Splunk dashboard: denied calls, blocked exfiltration flows, findings by OWASP MCP Top 10 category, and the attack chain by session](docs/img/splunk_dashboard.png)

*The Splunk dashboard after replaying the demo attack chain in the lab (`lab/`). 10 of 12 detections fire, including two correlation rules. See [detections/README.md](detections/README.md).*

**End-to-end demo with a real LLM** (`openai/gpt-oss-120b`, [transcripts](docs/demo.md)): asked only
"What's the weather in Delhi?", an agent with a poisoned weather tool leaked a canary SSH key to
the attacker in **6 of 7** unprotected runs and **0 of 7** with AgentGate.

## Quickstart

```bash
pip install -e .            # PyPI release as agentgate-mcp is coming with v0.1.0
```

On Windows, see [docs/windows_quickstart.md](docs/windows_quickstart.md).

Put every stdio server of a client behind AgentGate in one step (shows a diff first; `--apply`
writes it and keeps a `.bak`):

```bash
agentgate install --client claude-desktop            # or cursor, windsurf, vscode, claude-code
agentgate install --client claude-desktop --apply
```

Or wrap a server by hand. In your client's MCP config, replace the server command:

```jsonc
// before
"filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "C:/Users/me/projects"] }
// after
"filesystem": { "command": "agentgate", "args": ["wrap", "--server", "filesystem", "--",
                "npx", "-y", "@modelcontextprotocol/server-filesystem", "C:/Users/me/projects"] }
```

For a remote (Streamable HTTP) server, run the gateway and point the client at it:

```bash
pip install -e ".[http]"
agentgate serve --server github --upstream https://mcp.example.com/mcp --port 8765
# client config: "url": "http://127.0.0.1:8765/"
```

As a central gateway in Docker (audit events go to `docker logs` for your log shipper):

```bash
docker build -t agentgate .
docker run -p 8765:8765 -e UPSTREAM=http://mcp-server:8000/mcp -e SERVER=github agentgate
```

Useful commands:

```bash
agentgate pins                       # pinned tool definitions and their status
agentgate approve weather            # review and approve new/changed tool definitions
agentgate logs --findings            # recent audit events that had findings
agentgate report -o report.md         # Markdown summary: decisions, top findings, blocked by session
agentgate scan-config --sarif r.sarif  # audit client MCP configs (Claude, Cursor, VS Code, ...)
agentgate check -s filesystem --input '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"read_file","arguments":{"path":"~/.ssh/id_rsa"}}}'
agentgate check -s weather --manifest tools.json   # scan a tools/list result (exit 1 if blocked)
```

**Team allowlist (policy-as-code):** `agentgate pins-export -o pins.json` writes every approved
tool definition with its SHA-256; commit it, review changes in pull requests, and run
`agentgate pins-import pins.json` on each machine. With `defaults.first_seen_tool: deny`, only
reviewed definitions ever reach the model. Import re-hashes each definition and rejects a file
whose definitions were edited without updating the hash; protecting the file itself is up to
code review and signed commits.

To approve "ask" decisions from your phone, set `defaults.approvals: telegram` in the policy and
export `TELEGRAM_BOT_TOKEN` and `TELEGRAM_CHAT_ID`; AgentGate sends Allow/Deny buttons and
denies if nobody answers within two minutes.

State lives in `~/.agentgate/` (override with `AGENTGATE_HOME`). The policy comes from `--policy`, then `AGENTGATE_POLICY`, then the bundled [`policies/default.yaml`](policies/default.yaml).

## Results (frozen run, 29 Nov 2026)

AgentGate-Bench: 60 attack cases in 10 categories and 112 benign cases (42 real MCP server
manifests with 709 tools, plus real documentation text as tool results). Rules and thresholds
were frozen (commit `ba3c71f`) before the test split was read.
[Full results](docs/results.md) · [error analysis](docs/error_analysis.md)

| | Default (heuristics + taint) | + classifier on results |
|---|---|---|
| Recall (60 attacks) | **77%** | 82% |
| False-positive rate (112 benign cases) | **5%** | 10% |
| Added latency, p95 per tool call | **0.26 ms** | 66 ms |

- 100% on obvious poisoning, invisible Unicode, rug pulls, shadowing, secrets, command injection, SSRF.
- Taint tracking lifts obfuscated exfiltration from 0% to 60%.
- **Subtle, keyword-free poisoning: 0%** with every layer. That's the main open problem.
- The classifier's gains were all on the dev split; on test it added nothing, so it stays opt-in.
- **Generalisation check (corpus v2):** after adding 43 cases in new families and tuning on dev
  only, recall on the 20 new *unseen* test cases was **50%** vs 77% on dev
  ([results](docs/results_v2_test.md)). Rules fit what you've seen; this is the honest number.
- **LLM-judge layer** (post-freeze, gpt-oss-20b): subtle poisoning 57% → **86%**, overall
  92% → 96%, false positives 4% → 6% ([results](docs/results_judge_20b.md)).
- Caveat: the same person wrote the rules and the attacks; a held-out red-team set is next.

**Compared with existing tools** on the same cases ([details](docs/comparison.md)):

| | AgentGate | Cisco MCP Scanner (static, YARA) | mcpwall 0.3.1 (runtime, defaults) |
|---|---|---|---|
| Tool-definition attacks (31) | 23 | 6 | n/a (not inspected) |
| Tool-call attacks (21) | 19 | n/a (static) | 9 |
| Real benign servers flagged (42) | 1 | 11 | n/a |

Neither other tool's rules have seen these cases, while mine were written alongside them, so
this favours AgentGate; read the fairness notes.

## What it detects today

| Detector | Where | OWASP MCP Top 10 (2025) |
|---|---|---|
| **Manifest guard:** SHA-256 pin per tool, rug-pull diff, cross-server shadowing | `tools/list` | MCP03 |
| **Poisoning heuristics:** override/concealment phrases, fake `<IMPORTANT>` tags, sensitive paths, invisible Unicode (zero-width, bidi, tag block, decoded), base64 payloads | `tools/list` | MCP03 |
| **Argument policy:** path allow/deny globs (with `~` and `../` normalised), shell metacharacters, traversal, egress allowlist, SSRF (private, link-local, metadata, decimal/hex IPs) | `tools/call` | MCP02, MCP05 |
| **Secrets/PII:** AWS, GitHub, OpenAI, Groq, Slack, Google keys, private keys, JWTs, high-entropy strings, **Aadhaar (Verhoeff-checked)**, PAN | `tools/call` args and results | MCP01 |
| **Taint tracker:** data from sensitive tool results (or any result holding a secret) reappearing in a later call to *any* server, even URL- or base64-encoded | `tools/call` | MCP10 |
| **Server instructions & prompts:** `initialize` instructions scanned (stripped if poisoned); `prompts/list` entries hidden if poisoned; `prompts/get` messages flagged | `initialize`, `prompts/*` | MCP03, MCP06 |
| **Result scanner:** indirect prompt injection in tool output, flagged and annotated (never silently dropped) | `tools/call`, `resources/read` | MCP06 |

Tools that are flagged, or that changed since approval, are **removed from `tools/list`**, so the model never sees the poisoned description. Calls to them are denied with a JSON-RPC error. If a detector crashes, the message is denied (**fail closed**).

## Non-goals

- AgentGate does not replace sandboxing or least-privilege credentials. It is one layer of defence in depth.
- Prompt-injection detection is probabilistic. False-negative rates will be reported honestly in the benchmark.
- No enterprise features (SSO, multi-tenancy).

## Roadmap

- [x] stdio relay and Streamable HTTP reverse proxy; fail-closed pipeline; JSONL audit log
- [x] YAML policy (allow / deny / ask); approvals on a terminal or via Telegram
- [x] Manifest pinning, rug-pull diff, shadowing; team allowlist via `pins-export` / `pins-import`
- [x] Poisoning heuristics (intent patterns, invisible Unicode, homoglyphs, suspicious defaults),
      applied to tools, server instructions and prompts
- [x] Argument policy, SSRF (incl. IPv4 shorthand), secrets and Indian PII, result scanning and redaction
- [x] Taint tracker: winnowed fingerprints, exact and key=value secrets, identifiers for
      paraphrased leaks, URL/base64/hex decoding, shared across servers
- [x] Optional ONNX classifier and LLM judge (with persistent verdict cache)
- [x] `scan-config` (SARIF), `check`, lethal-trifecta posture warning
- [x] Splunk pack (16 Sigma rules, dashboard, lab) and Wazuh rules, both verified on an attack chain
- [x] AgentGate-Bench: 110 attacks, 42 real benign servers, two freezes, comparison, CI gate
- [x] LLM-judge results with gpt-oss-20b (gpt-oss-120b run in progress, Groq free-tier quota)
- [ ] Held-out red-team evaluation (needs an outside contributor)
- [ ] PyPI release and demo video

## Development

```bash
python -m venv .venv && . .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
pytest -q && ruff check . && mypy
```

See [docs/threat_model.md](docs/threat_model.md) and [docs/owasp_mapping.md](docs/owasp_mapping.md).

Contributions welcome: see [CONTRIBUTING.md](CONTRIBUTING.md). Licence: Apache-2.0. To report a vulnerability, see [SECURITY.md](SECURITY.md).
