mcpbroker
by plthiyagu
README.md
# mcpbroker
Cloud-neutral MCP tool registry and gateway with pluggable identity.
One catalog of governed tools. Two ways to fill it: engineers commit YAML or decorate
Python functions; business users paste a curl command or fill in a form. Agents connect
to a single MCP endpoint and see only the tools their identity allows. The gateway handles
inbound identity (OIDC, API keys), outbound credentials (2LO, 3LO, token exchange, cloud
IAM), approvals, risk tiers, rate limits, tool-poisoning detection and audit.
Apache-2.0. Python 3.11+.
## Why
Existing AI gateways (Kong, Bifrost, LiteLLM, ContextForge, agentgateway) route LLM and
MCP traffic well. What they leave to you:
| Gap | mcpbroker |
|---|---|
| Only engineers can register tools | Guided form and curl import for non-technical owners; YAML, decorator and OpenAPI import for engineers. Same catalog, same approval queue. |
| Shared service credentials for every user | 3LO (authorization code + PKCE) so a tool calls the backend as the user; RFC 8693 token exchange when the IdP supports it; 2LO when a service identity is right. |
| Tied to one cloud | Secret refs for AWS Secrets Manager, GCP Secret Manager, Azure Key Vault, Vault and env. Backends on plain HTTP, Lambda, Cloud Run, Azure Functions or another MCP server. |
| Tool descriptions change silently | Approval pins a SHA-256 of description and schema. A changed tool disappears from discovery until re-approved. |
| No governance model | Risk tiers (low to critical) drive approval counts and self-approval rules. Per-tool RBAC, tenant isolation, rate limits, human-in-the-loop flag. |
mcpbroker does not route LLM completions. Put it next to LiteLLM or Kong for that.
## Install
```bash
pip install mcpbroker # core
pip install "mcpbroker[aws,gcp,azure,vault]"
```
## Quick start (engineer)
```python
from mcpbroker import Gateway, build_app, tool
from mcpbroker.registration import python_tools
@tool(risk_tier="low")
def add(a: int, b: int) -> int:
"""Add two integers."""
return a + b
gw = Gateway()
python_tools.install(gw.catalog)
app = build_app(gw) # ASGI app: /mcp, /admin/*, /oauth/callback, /healthz
```
Or declare tools in YAML and run the CLI:
```bash
mcpbroker tools validate examples/tools
mcpbroker serve examples/gateway.yaml
```
See [`examples/gateway.yaml`](examples/gateway.yaml) for inbound (Okta, Entra, Auth0,
Keycloak, Google, Cognito, API keys) and outbound (2LO, 3LO, token exchange, GCP, Azure)
configuration, and [`examples/tools/crm.yaml`](examples/tools/crm.yaml) for tool specs.
## Quick start (business user)
Paste a curl command to pre-fill the form:
```bash
mcpbroker import curl "curl -X POST https://api.acme.com/refunds -H 'Authorization: Bearer x' -d '{\"order_id\":\"o1\",\"amount\":12.5}'"
```
Fill in the plain-language fields and submit to `POST /admin/tools/form`:
```json
{
"tool_name": "billing.refund",
"what_it_does": "Issue a refund for an order.",
"url": "https://api.acme.com/refunds",
"method": "POST",
"fields": [
{"name": "order_id", "description": "Order number", "type": "text"},
{"name": "amount", "description": "Amount in dollars", "type": "number"}
],
"changes_data": true,
"handles_sensitive_data": true,
"who_can_use": ["finance"],
"login_type": "shared api key",
"api_key_location": "aws-sm://prod/billing#key"
}
```
The tool lands in the approval queue as `critical` (changes data and handles sensitive
data), needs two reviewer approvals, and is flagged for per-call human approval.
## Import an existing API
```bash
mcpbroker import openapi https://crm.example.com/openapi.json --prefix crm -o tools/crm.yaml
```
Each operation becomes a draft tool. Risk tier is inferred from the HTTP method, auth mode
from `securitySchemes`, and path/query/body parameters are merged into one input schema.
## Identity model
```
agent ──bearer/API key──▶ gateway ──credential──▶ backend
(inbound) (outbound)
```
Inbound: `OIDCAuthenticator` (any OIDC issuer, presets for common IdPs), `ApiKeyAuthenticator`.
Outbound, per tool via `auth.mode`:
| mode | acts as | when |
|---|---|---|
| `oauth2_2lo` | the gateway | shared service access |
| `oauth2_3lo` | the calling user | per-user permissions; first call returns a consent link |
| `token_exchange` | the calling user | IdP supports RFC 8693; no browser round-trip |
| `cloud_iam` | the gateway's workload identity | Lambda, Cloud Run, Azure Functions |
| `api_key` | the gateway | legacy APIs; key read from a secret ref |
| `none` | – | public APIs |
Secrets are referenced, never stored: `env://`, `aws-sm://`, `gcp-sm://`, `azure-kv://`, `vault://`.
## Governance
- `ToolSpec.state`: draft → pending → approved / rejected → deprecated.
- Approvals required: low/medium 1, high/critical 2. Owners cannot self-approve high or critical.
- `description_pin` is set on approval. `is_poisoned()` flips if description or schema change.
- `Policy`: `allowed_roles`, `denied_roles`, `allowed_tenants`, `rate_limit_per_minute`, `requires_human_approval`.
- Every registration, approval, denial, consent and call is written to the audit log as JSON.
## Development
```bash
uv sync --all-extras --group dev
uv run pytest
uv run ruff check src tests
```
## Status
Alpha. The data model and interfaces (`Authenticator`, `CredentialProvider`,
`SecretBackend`, `CatalogStore`) are the stable surface; everything else may change.
Not yet included: a web UI for the form, Redis-backed token store and rate limiter,
SAML, mTLS inbound, and the per-call human-approval workflow (flag exists, enforcement
is up to the caller for now).