Skip to main content
Glama
mcp-tool-guard-server

mcp-tool-guard-server

README.md
<div align="center">
  <img src="assets/hero-banner.svg" alt="mcp-tool-guard &amp; a2a-card-guard v0.6.0" width="920" />

  <p>
    <a href="https://github.com/ai-boost/awesome-a2a"><img src="https://img.shields.io/badge/Featured_in-awesome--a2a-16a34a?style=flat-square&logo=github" alt="Featured in awesome-a2a" /></a>
    <a href="https://registry.modelcontextprotocol.io/v0/servers?search=mcp-tool-guard"><img src="https://img.shields.io/badge/Anthropic_MCP_Registry-io.github.khoap1220--hue%2Fmcp--tool--guard-0284c7?style=flat-square" alt="Official Anthropic MCP Registry" /></a>
    <a href="https://glama.ai/mcp/servers/khoap1220-hue/mcp-tool-guard"><img src="https://img.shields.io/badge/Glama_MCP-Listed-7c3aed?style=flat-square" alt="Glama MCP" /></a>
    <a href="https://github.com/khoap1220-hue/mcp-tool-guard/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/khoap1220-hue/mcp-tool-guard/ci.yml?branch=main&style=flat-square&label=CI" alt="GitHub Actions CI" /></a>
    <img src="https://img.shields.io/badge/Code_Scanning-SARIF_v2.1.0-2563eb?style=flat-square" alt="SARIF v2.1.0" />
    <img src="https://img.shields.io/badge/Runtime_Deps-0_(Pure_Stdlib)-0f766e?style=flat-square" alt="0 Runtime Deps" />
    <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-475569?style=flat-square" alt="MIT License" /></a>
  </p>

  <p>
    <strong>Zero-dependency Python 3.10+ library, triple CLI (<code>mcp-tool-guard</code>, <code>a2a-card-guard</code>, <code>mcp-tool-guard-server</code>), SARIF GitHub Action, and Official MCP Server guarding MCP &amp; A2A Protocol Specification <code>v1.0.1</code>.</strong>
  </p>

  <img src="assets/terminal-demo.svg" alt="mcp-tool-guard v0.6.0 live terminal demo" width="880" />
</div>

---

## 0.3-Second Prebuilt Wheel Install (`No Git Clone Needed`)

Run directly from the signed `v0.6.0` prebuilt wheel (`dependencies = []`, zero transitive supply-chain surface):

```bash
# Instant one-shot live A2A v1.0 AgentCard + Ed25519 JWKS audit via uvx
uvx --from https://github.com/khoap1220-hue/mcp-tool-guard/releases/download/v0.6.0/mcp_tool_guard-0.6.0-py3-none-any.whl \
  a2a-card-guard audit https://khoaphan.dev --auto-jwks --strict-v1

# Or install into any Python 3.10+ virtualenv / CI image in <0.5s
pip install https://github.com/khoap1220-hue/mcp-tool-guard/releases/download/v0.6.0/mcp_tool_guard-0.6.0-py3-none-any.whl
```

> *Note: `HS256`, RFC 8785 JCS canonicalization, cross-SDK JCS divergence checks, SSRF-pinned HTTPS fetching, 5-layer prompt-injection scanning, 11-CVE multi-language SCA, SARIF v2.1.0, and the `stdio` MCP server run on 100% Python stdlib. For asymmetric `EdDSA` / `ES256` / `PS256` JWS cryptographic verification, pass `--with cryptography` to `uvx`.*

---

## 1-Click IDE MCP Server Config (`Claude Code`, `Cursor`, `Windsurf`, `VS Code`)

Registered on the **Official Anthropic MCP Registry** as `io.github.khoap1220-hue/mcp-tool-guard`. Drop into `.mcp.json`, `~/.cursor/mcp.json`, or `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "mcp-tool-guard": {
      "command": "uvx",
      "args": [
        "--from",
        "https://github.com/khoap1220-hue/mcp-tool-guard/releases/download/v0.6.0/mcp_tool_guard-0.6.0-py3-none-any.whl",
        "mcp-tool-guard-server"
      ]
    }
  }
}
```

### 6 Built-In Read-Only Security Tools (`mcp-tool-guard serve`)

| MCP Tool | Scope | `openWorldHint` | What It Verifies |
| :--- | :--- | :---: | :--- |
| `guard_scan_mcp_tools` | MCP `tools/list` | `false` | 5-layer prompt injection, Unicode Tag smuggling, homoglyphs & server typosquatting |
| `guard_verify_mcp_pins` | MCP Lockfile | `false` | Canonical SHA-256 rug-pull drift & `readOnlyHint -> destructiveHint` loosening |
| `a2a_audit_agent_card` | A2A `v1.0` Card | `true` | Local file or SSRF-pinned live HTTPS origin + `--auto-jwks` JWS & `--strict-v1` checks |
| `a2a_check_jcs_divergence` | RFC 8785 JCS | `false` | Cross-SDK signature canonicalization splits (`A2A#2122`, `a2a-js#627`, `a2a-go#445`) |
| `a2a_scan_lockfiles_sca` | 9 Lockfile Types | `false` | All 11 OSV-verified A2A SDK CVEs + `v0.3 <-> v1.0` framework split-brain |
| `guard_audit_mcp_toolbox` | `tools.yaml` | `false` | Google `mcp-toolbox` SQL template interpolation, unauth DDL/DML & OS shell exposure |

---

## Objective Feature Comparison Matrix

| Capability | `mcp-tool-guard v0.6.0` | `mcp-scan` | `pip-audit` / `osv-scanner` |
| :--- | :---: | :---: | :---: |
| **`0 Runtime Deps` (`dependencies = []`)** | **Yes** (pure Python stdlib) | No (heavy CLI/HTTP tree) | No |
| **`Offline Air-Gapped Mode`** | **Yes** (100% deterministic local rules) | Partial (cloud API default) | Requires vulnerability DB sync |
| **`MCP Pinning & 5-Layer Scan`** | **Yes** (SHA-256 lockfile + annotation diff) | Yes | No |
| **`Live A2A v1.0 JWS/JWKS`** | **Yes** (DNS-pinned SSRF-safe HTTPS + JWKS) | No | No |
| **`Cross-SDK JCS Divergence`** | **Yes** (`A2A#2122`, `a2a-js#627`, `a2a-go#445`) | No | No |
| **`11 Commit-Mapped A2A SDK CVEs`** | **Yes** (PyPI, npm, Go, Cargo, Maven + split-brain) | No | Partial (misses commit-only OSV ranges) |
| **`SARIF v2.1.0 Action`** | **Yes** (`action.yml` + `$GITHUB_STEP_SUMMARY`) | Partial | Yes |
| **`Built-In MCP Server`** | **Yes** (6 read-only `stdio` tools) | No | No |

---

## Drop-In 5-Line GitHub Action (`action.yml` + SARIF Code Scanning)

```yaml
- uses: khoap1220-hue/mcp-tool-guard@v0.6.0
  with:
    agent-card: .well-known/agent-card.json
    jwks: .well-known/jwks.json
    mcp-config: tools.json
    sarif-output: mcp-tool-guard.sarif
```

Upload `mcp-tool-guard.sarif` directly to the GitHub Security tab via `github/codeql-action/upload-sarif@v3`; every run also writes a Markdown scorecard table to `$GITHUB_STEP_SUMMARY`.

---

## Ground-Truth A2A SDK CVE Coverage (`a2a-sca` / `A2A-08`)

Standard OSV package queries (`pip-audit`, `npm audit`, `osv-scanner`, Dependabot) miss 2026 `a2aproject/*` advisories mapped only to git commit SHAs. `a2a-sca` detects all 11 verified advisories deterministically across `uv.lock`, `poetry.lock`, `requirements*.txt`, `pyproject.toml`, `package-lock.json`, `pnpm-lock.yaml`, `go.mod`, `Cargo.lock`, and `pom.xml`:

| Advisory ID | Ecosystem & Package | Vulnerable Range | Patched | Class & `A2ABreak` Vector |
| :--- | :--- | :---: | :---: | :--- |
| `CVE-2026-90790` | PyPI `a2a-sdk` | `<= 1.1.3` | `1.1.4` | Push Notification webhook SSRF (`#7`) |
| `CVE-2025-6167` | PyPI `python-a2a` | `< 0.5.6` | `0.5.6` | Workflow identifier path traversal |
| `CVE-2026-118128` | npm `@a2a-js/sdk` (+ aliases) | `<= 1.1.0` | `1.2.0` | Task FSM concurrent status race / TOCTOU (`#6`) |
| `CVE-2026-116478` | Go `github.com/a2aproject/a2a-go(/v2)` | `<= 2.4.0` | `2.5.0` | Internal network error disclosure in push handler (`#7`) |
| `CVE-2026-113706` | Cargo `a2a-rs` / `a2a-lf` / `a2a` | `<= 0.4.3` | `>= 0.4.4` | `historyLength` conversation history leak (`#3`) |
| `CVE-2026-90819` | Maven `io.a2a.sdk:*` | `< 1.3.0` | `1.3.0.Final` | Push `Authorization` header CRLF splitting (`#7`) |
| `CVE-2026-111761` | Maven `io.a2a.sdk:*` (`server-common`) | `< 1.3.0` | `1.3.0.Final` | Unvalidated push webhook SSRF (`#7`) |
| `CVE-2026-111762` | Maven `io.a2a.sdk:*` (`transport-rest`) | `< 1.3.0` | `1.3.0.Final` | Cleartext bearer token logged on Protobuf parse error (`#7`) |
| `CVE-2026-111763` | Maven `io.a2a.sdk:*` (`parent`/`client`) | `< 1.3.0` | `1.3.0.Final` | Cross-domain API key leak via HTTP `30x` redirect (`#1, #2`) |
| `CVE-2026-111764` | Maven `io.a2a.sdk:*` (`server-common`) | `< 1.3.0` | `1.3.0.Final` | Fail-open `InMemoryTaskStore` cross-tenant IDOR (`#3`) |
| `CVE-2026-111765` | Maven `io.a2a.sdk:*` (`http-client-android`) | `< 1.3.2` | `1.3.2.Final` | Synchronous POST cross-authority credential redirect (`#1, #2`) |

---

## Real MCP Attack Example (`readOnlyHint -> destructiveHint` Rug-Pull)

A server serves `examples/tools_v1.json` at approval time, then silently mutates only `annotations` in `examples/tools_v2_rugpull.json`:

```diff
       "annotations": {
         "title": "Analytics Reader",
-        "readOnlyHint": true,
-        "destructiveHint": false,
+        "readOnlyHint": false,
+        "destructiveHint": true,
         "idempotentHint": true,
         "openWorldHint": false
       }
```

Pinning and verifying with the CLI immediately flags `HIGH` severity annotation-loosening drift (exit code `2`) and records old/new hashes and exact field diffs in a SHA-256 hash-chained audit trail:

```bash
mcp-tool-guard pin examples/tools_v1.json --server analytics-mcp -o pins.lock.json
mcp-tool-guard verify examples/tools_v2_rugpull.json --server analytics-mcp -l pins.lock.json --sarif-out drift.sarif
```

## Python Library & CLI Reference

```python
from mcp_tool_guard import (
    MCPStdioServer,
    MCPToolGuard,
    audit_live_agent_card,
    check_cross_sdk_jcs_divergence,
    load_tools_list_file,
    scan_a2a_lockfiles,
)

# 1. MCP tools/list pin & rug-pull verification
guard = MCPToolGuard(trusted_servers=["analytics-mcp"])
guard.evaluate_tools(load_tools_list_file("examples/tools_v1.json", default_server="analytics-mcp"))
decisions = guard.evaluate_tools(load_tools_list_file("examples/tools_v2_rugpull.json", default_server="analytics-mcp"))
assert decisions[0].decision == "human_review" and decisions[0].drift_severity == "HIGH"

# 2. Multi-language A2A SDK lockfile & split-brain scan
sca_report = scan_a2a_lockfiles(".")
assert sca_report.passed is True
```

```bash
# MCP subcommands & stdio server
mcp-tool-guard serve
mcp-tool-guard-server --version
mcp-tool-guard pin examples/tools_v1.json --server analytics-mcp -o pins.lock.json
mcp-tool-guard verify examples/tools_v2_rugpull.json --server analytics-mcp -l pins.lock.json --format sarif
mcp-tool-guard scan examples/tools_v1.json --server analytics-mcp --github-summary
mcp-tool-guard check-stateless examples/stateless_desync_request.json
mcp-tool-guard audit-toolbox examples/mcp_toolbox_sample.yaml --format sarif
mcp-tool-guard check-a2a chain.json --secret-env MCP_GUARD_SECRET --server analytics-mcp --tool query_records

# A2A v1.0 subcommands (available on both `a2a-card-guard` and `mcp-tool-guard a2a-*`)
a2a-card-guard audit https://khoaphan.dev --auto-jwks --strict-v1
a2a-card-guard pin examples/agent_card_v1.json -o a2a.lock.json --hmac-secret-env A2A_DEMO_HMAC
a2a-card-guard verify examples/agent_card_v2_rugpull.json -l a2a.lock.json --hmac-secret-env A2A_DEMO_HMAC
a2a-card-guard sca . --agent-card examples/agent_card_v1.json --format json
a2a-card-guard delegation-audit examples/a2a_delegation_escalation.json --format sarif
a2a-card-guard generate --url https://guard.example.com --pay-to 0x1111111111111111111111111111111111111111 --price-usdc 0.05
```

---

## Architecture

```text
src/mcp_tool_guard/
├── models.py          # Frozen dataclasses (MCPToolDefinition, DriftReport, AuditEntry)
├── canonical.py       # Sorted-key JSON canonicalizer, ASCII prose normalization, deep field differ
├── policy.py          # Monotonic annotation guardrails & HIGH-severity annotation loosening detector
├── scanner.py         # 5-layer prompt-injection & Unicode homoglyph/Tag smuggling scanner
├── typosquat.py       # Damerau-Levenshtein edit-distance-1 & confusable server spoof detector
├── audit.py           # Append-only SHA-256 hash-chained AuditLog with JSONL serialization
├── guard.py           # Stateful MCPToolGuard, lockfile I/O, separation-of-duties drift promotion
├── loader.py          # Parser for standard MCP tools/list, JSON-RPC 2.0, array, and multi-server JSON
├── stateless.py       # Stateless MCP 2026-07-28 header-body verifier & multi-replica consensus detector
├── toolbox_audit.py   # Zero-dep Google mcp-toolbox tools.yaml, shell/SQL, MCP Apps & Tasks auditor
├── a2a_attenuation.py # Cryptographically linked monotonic A2A <-> MCP capability attenuation chain
├── a2a_guard.py       # A2A v1.0 JCS/JWS verifier, live SSRF-pinned URL probe, JCS divergence & A2ABreak
├── a2a_sca.py         # Zero-dep 9-manifest A2A SDK CVE & v0.3/v1.0 framework split-brain scanner (A2A-08)
├── a2a_x402.py        # A2A v1.0.1 /.well-known/agent-card.json generator & exact-Decimal x402 v2 helpers
├── sarif.py           # OASIS SARIF v2.1.0 & GitHub Actions $GITHUB_STEP_SUMMARY Markdown formatter
├── mcp_server.py      # Zero-dep JSON-RPC 2.0 stdio MCP server exposing 6 read-only security tools
└── cli.py             # Triple zero-dep CLIs (`mcp-tool-guard`, `a2a-card-guard`, `mcp-tool-guard-server`)
```

## Benchmarks

Measured with `python -B benchmarks/bench_guard.py --iterations 500 --warmup 50` on Python 3.12 (`AMD64`), zero external dependencies:

| Workload | Iterations | p50 (µs) | p95 (µs) | p99 (µs) | Mean (µs) |
| --- | ---: | ---: | ---: | ---: | ---: |
| Single tool: canonical SHA-256 pin hash only | 2,500 | 63.3 | 80.8 | 101.6 | 66.3 |
| Single tool: cold pin + full 5-layer scan | 1,000 | 1,033.9 | 1,717.3 | 1,810.2 | 1,182.9 |
| 10-tool `tools/list`: cold pin + 5-layer scan | 500 | 10,827.9 | 15,581.4 | 16,011.5 | 11,471.8 |
| 20-tool `tools/list`: steady-state guard verify | 500 | 1,427.5 | 1,768.3 | 1,845.0 | 1,416.6 |
| 50-tool `tools/list`: steady-state guard verify | 250 | 3,841.1 | 4,421.4 | 4,560.3 | 3,781.3 |

## License

MIT — see [LICENSE](LICENSE).

---

Maintained by Khoa Phan as part of an open-core A2A engineering practice (100% written asynchronous execution via GitHub Specs/PRs and Email, zero live meetings). For teams needing production remediation, custom A2A `v0.3 -> v1.0` migration adapters, or formal security sign-off, details on the **72h Fixed-Scope A2A v1.0 & MCP Security Hardening Audit** are available at [khoaphan.dev/mcp/](https://khoaphan.dev/mcp/).