Governed MCP Starter
by skarthik1710
README.md
# Governed MCP Starter
A vendor-neutral, secure-by-default reference starter for **enterprise AI agent tool servers** built around the Model Context Protocol (MCP).
> **Core design principle:** *Rules give the verdicts, AI advises, and people approve every change.*
## Why This Exists
Enterprise AI agents that inspect collaboration suites, directories, or financial systems often need powerful admin-level read access. Giving raw credentials, unmasked PII, and inconsistent authorization logic to every agent is a risk no enterprise security team accepts.
This starter demonstrates a reusable **governed tool boundary** where:
1. **Agents never hold upstream credentials** — only a small, auditable, read-only tool server does.
2. **Authorization fails closed** — an [Open Policy Agent (Rego)](policy/agent_authz.rego) policy checks caller role, tenant clearance, tool allowlist, and `READ`-only scope before every call. If the policy engine is unreachable, the call is denied.
3. **Identities are pseudonymised before the model sees data** — an HMAC-SHA256 keyed pseudonymizer + strict field allowlist strips names, emails, and phone numbers at the tool boundary.
4. **Every call is recorded in a tamper-evident audit chain** — hash-chained, content-free entries detect post-hoc modification.
5. **Operators have an immediate kill switch** — global or per-tool halts stop agent tool execution cleanly.
6. **Controls are enforced by automated contract tests in CI**, not by convention.
## Architecture
```mermaid
flowchart LR
Agent["AI Agent / LLM"] -->|"Verified CallerContext"| KS{"Kill Switch"}
KS -->|"Halted"| Audit["Hash-Chained Audit Log"]
KS -->|"Active"| OPA{"OPA Policy Sidecar<br/>(Fail-Closed Rego)"}
OPA -->|"DENY / Unreachable"| Audit
OPA -->|"ALLOW (READ-only)"| Audit
OPA -->|"ALLOW"| Data["Read-Only Enterprise Store"]
Data -->|"Raw Records"| Pseudo["Keyed Pseudonymizer +<br/>Field Allowlist"]
Pseudo -->|"Pseudonymised Snapshot<br/>(Zero PII)"| Agent
```
## Quick Start (No API Keys Required)
```bash
python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
# Run the security contract test suite
pytest -v
# Run the end-to-end CLI walkthrough
PYTHONPATH=src python3 -m governed_mcp.demo
```
To expose the gateway as a live **FastMCP** server:
```bash
pip install -e ".[mcp]"
```
```python
from governed_mcp import (
GovernedToolGateway,
HashChainedAuditLog,
KeyedPseudonymizer,
KillSwitch,
OPAPolicyClient,
create_fastmcp_server,
)
gateway = GovernedToolGateway(
policy=OPAPolicyClient(), # talks to pod-local OPA sidecar; fails closed if unreachable
pseudonymizer=KeyedPseudonymizer(b"replace-with-vault-secret-32byte"),
audit_log=HashChainedAuditLog(),
kill_switch=KillSwitch(),
)
mcp = create_fastmcp_server(gateway)
```
## Security Contract Tests Included
| Control | Contract Verified in [`tests/test_contracts.py`](tests/test_contracts.py) |
| :--- | :--- |
| **Zero PII leakage** | Raw names, emails, and phone numbers never appear in agent-facing payloads; only `subject_id` + allowlisted fields are returned. |
| **Fail-closed policy** | Missing roles, uncleared tenants, write attempts, and unreachable OPA sidecars all deny by default. |
| **Kill switch** | Global and per-tool halts immediately block execution and record `HALTED` in the audit trail. |
| **Tamper-evident audit** | Hash-chain verification passes on intact logs and fails immediately if any historical entry is modified. |
| **Tenant isolation** | Pseudonyms are deterministic within a tenant and distinct across tenants. |
## Related Reading
- **Enterprise Agent Playbook:** [karthikeyanselvam.com/playbook.html](https://karthikeyanselvam.com/playbook.html)
- **Interactive Architecture Diagrams:** [karthikeyanselvam.com/projects.html](https://karthikeyanselvam.com/projects.html)
## License
MIT — © 2026 Karthikeyan Selvam
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues