mcp-guard
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
mcp-guard
A small Model Context Protocol (MCP) server that shows how to give AI agents access to tools safely:
OAuth 2.1 resource server: validates bearer JWTs from an external authorization server (signature via JWKS,
iss,aud/RFC 8707 resource,exp) and publishes RFC 9728 Protected Resource Metadata so MCP clients can discover where to authenticate.Admin policy controls: a YAML policy that IT can review and version decides which tools each agent can see (
tools/listis filtered) and call (tools/callis enforced). Rules use scopes plus roles, it denies by default, and it includes a per-client kill switch and rate limit.Audit and metrics: one JSON audit line per decision (argument names only, never values) and Prometheus metrics (
mcp_tool_calls_total,mcp_tool_denials_total,mcp_tool_call_seconds).Tests: unit tests for the token verifier and policy engine, plus end-to-end tests over real Streamable HTTP using the official MCP Python SDK client.
Built on the official MCP Python SDK (v2).
Architecture
MCP client / agent ──Bearer JWT──▶ Streamable HTTP /mcp
│
SDK bearer auth ──┤ 401 + WWW-Authenticate (resource_metadata) if missing/invalid
JWTTokenVerifier │ iss / aud / exp / signature (JWKS or HS256 in dev)
▼
PolicyMiddleware
tools/list ─▶ filter by policy
tools/call ─▶ blocked? scopes? roles? rate limit?
│ └─ deny ─▶ JSON-RPC -32003 + audit + metric
▼
tool handlers ─▶ audit + latency histogramRelated MCP server: MCP-ToolHub
Quick start
pip install -e ".[dev]"
export MCP_GUARD_HS256_SECRET=dev-secret-at-least-32-bytes-long!!
python -m mcp_guard.server # serves http://127.0.0.1:8000/mcp
# mint dev tokens with different permissions
python -m mcp_guard.devtoken --client reader --scope "tickets:read"
python -m mcp_guard.devtoken --client ops --scope "tickets:read tickets:write" --role adminDiscovery and ops endpoints:
Path | Purpose |
| RFC 9728 metadata (authorization server, resource) |
| Prometheus metrics |
| Liveness |
Policy
tools:
search_tickets: { scopes: [tickets:read] }
create_ticket: { scopes: [tickets:write] }
close_ticket: { scopes: [tickets:write], roles: [admin] }
clients:
blocked: [rogue-agent]
rate_limit_per_minute: 120Token | Sees |
|
|
| hidden, |
| search + create |
|
| all three | allowed |
| nothing |
|
Production notes
Set
MCP_GUARD_JWKS_URL(RS256/ES256 keys from your IdP) and do not set the HS256 secret.MCP_GUARD_RESOURCE_URLmust be this server's canonical URL. Tokens whoseauddoesn't match are rejected, which prevents token replay across servers (the confused-deputy problem).Rate-limit buckets are in-memory per process. Behind multiple replicas, move them to Redis.
Suggested SLOs: 99.9% availability of
/mcp, p95 policy-check overhead under 5 ms, measured frommcp_tool_call_seconds.
Tests
pytest -qLicense
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP gateway with runtime security policy, tool-call-level control, and audit of agent actions.
Security & DLP proxy for MCP: tool-poisoning scans, PII redaction on tool args/results. Beta.
Find, vet, and run MCP tools through a secure audited gateway with prompt-injection risk scoring
MCP gateway: one connection for your AI apps, with tool policies, PII redaction and audit logs.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to discover and execute tools via a secure MCP server with JWT authentication, RBAC, rate limiting, and audit logging.1MIT
- AlicenseNot gradedqualityCmaintenanceProvides a unified MCP gateway enabling AI agents to securely access multiple tool servers (knowledge base, database, repo, etc.) with dynamic tool selection and OAuth2/RBAC security.1MIT
- AlicenseAqualityCmaintenanceProvides a security governance layer for AI agents to safely access upstream MCP servers, enforcing tool-level RBAC, parameter constraints, authentication via static tokens or OIDC, and tamper-evident audit logging.21Apache 2.0
- AlicenseNot gradedqualityCmaintenanceEnables production-hardened MCP tool serving with OAuth 2.1 audience-restricted tokens, purpose-bound tools, human-in-the-loop approvals, containment, and audit trails for AI agents.Apache 2.0