Secure MCP Gateway
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.
Secure MCP Gateway
Secure, scalable and observable infrastructure for AI agents and MCP-powered applications.
An authenticated Model Context Protocol (MCP) server and client in Python. Every request carries a bearer token (a static API key or a signed JWT), checked before it reaches a tool, and each tool enforces its own scopes.
This is theMVP. It implements bearer-token authentication and scope-based authorization over Streamable HTTP. OAuth 2.1, RBAC, observability and cloud-native deployment are on the roadmap.
Table of contents
Related MCP server: agentmemory-mcp-gateway
Features
Two authentication modes: a static API key (compared in constant time) or a JWT (HS256/384/512) with its signature, algorithm, issuer, audience and expiry all checked.
Scope-based authorization: every request needs
mcp:read, and write tools also requiremcp:write.Audience binding: tokens issued for a different server URL are rejected (RFC 8707).
Settings checked at startup: misconfiguration fails at startup with a clear message, and secrets never appear in logs or
repr.Reusable client:
AuthenticatedMCPClientkeeps one session open per connection and reuses it for every call.Developer tooling:
uv, aMakefile, strict typing, and 109 unit plus 5 integration tests with ≥85% coverage enforced.
Architecture

Each request is handled in this order:
The client sends
Authorization: Bearer <token>over Streamable HTTP.MCPTokenVerifiervalidates the token. An invalid token gets401.The SDK checks the token was issued for this server. A mismatch gets
401.The SDK requires the
mcp:readscope. A token without it gets403.The FastMCP tool runs. Write tools also call
require_scope("mcp:write").
Getting started
Prerequisites
Python 3.13+
uv 0.12+
make(optional; every target wraps auv runcommand)
Installation
git clone https://github.com/SimeonDee/secure-mcp-gateway.git
cd secure-mcp-gateway
make install # uv sync: runtime + dev dependencies
make env # creates .env from .env.example (never overwrites)
make secret ARGS="--env" # prints MCP_API_KEY / JWT_SECRET lines to paste into .envRun
make run-server # serves http://127.0.0.1:8000/mcp
make run-client # in a second terminal: lists tools, calls add + get_user_profileConfiguration
All settings come from environment variables, which can be loaded from .env in the working directory. Real environment variables override .env.
Variable | Default | Description |
|
| Bind address |
|
| Bind port (1–65535) |
|
| Public URL; also the JWT audience |
|
|
|
| — | Required for |
| — | Required for |
|
|
|
|
| Expected |
|
| Token lifetime (1–1440) |
|
| Default |
| — | Client only, |
Usage
JWT mode
# .env: AUTH_TYPE=jwt, then restart the server
export MCP_ACCESS_TOKEN="$(make -s token)"
make run-client
# A read-only token for a specific client:
make -s token ARGS="--client-id reporting-agent --scopes mcp:read --minutes 15"Python client
import asyncio
from secure_mcp_gateway.client import AuthenticatedMCPClient
async def main() -> None:
async with AuthenticatedMCPClient("http://127.0.0.1:8000/mcp", token="...") as client:
print([tool.name for tool in await client.list_tools()])
print(await client.call_tool("add", {"a": 25, "b": 15}))
asyncio.run(main())Exposed capabilities
Kind | Name | Scope |
Tool |
|
|
Tool |
|
|
Tool |
|
|
Tool |
|
|
Tool |
|
|
Tool |
|
|
Resource |
|
|
Prompt |
|
|
Currency tools
get_currency_rate fetches a rate from the public Frankfurter API; convert_currency is pure
arithmetic and makes no network call, so the two are typically chained. Currency codes are
lowercase ISO 4217 (usd, eur, ngn) and dates are YYYY-MM-DD.
rate = await client.call_tool(
"get_currency_rate",
{"source_currency": "eur", "destination_currency": "chf", "the_date": "2024-05-15"},
)
# defaults: source "ngn", destination "usd", date today
result = await client.call_tool(
"convert_currency",
{"base_currency": "EUR", "quote_currency": "CHF", "conversion_rate": 0.98, "amount": 200},
)
# -> {"date": "<today>", "from": "EUR", "to": "CHF", "rate": 0.98, "amount": 200.0,
# "converted_amount": 196.0}Outbound requests time out after 10 seconds. Upstream failures come back as data instead of
raising: {"status": "http-error", "status_code": ..., "message": <response body>} or
{"status": "error", "message": ...}.
Use from Claude Code
.mcp.json registers the running gateway as an MCP server. Its headersHelper runs
secure-mcp-headers, which reads .env and prints the Authorization header (API key, or in
jwt mode MCP_ACCESS_TOKEN or a freshly minted short-lived JWT). Start the server, open the
project in Claude Code, accept the trust prompt, and check /mcp.
Verify authentication with curl
curl -i -X POST http://127.0.0.1:8000/mcp # 401
curl -i -X POST http://127.0.0.1:8000/mcp -H "Authorization: Bearer nope" # 401Development
make # list all targets
make format # black + ruff --fix
make check # lint + strict typecheck + unit tests (the merge gate)
make test-integration # starts real servers on free localhost ports
make coverage # HTML report in htmlcov/Run a single test with uv run pytest tests/unit/test_auth.py::test_valid_jwt_is_accepted --no-cov.
Tool | Purpose |
pytest + pytest-asyncio + pytest-cov | Tests and coverage (≥85% enforced) |
Formatting (line length 100) | |
Linting, including the | |
Strict static typing for |
Project structure
secure-mcp-gateway/
├── src/secure_mcp_gateway/
│ ├── config.py # Settings loaded and validated from the environment
│ ├── auth.py # MCPTokenVerifier: API key / JWT validation
│ ├── server.py # build_server(): FastMCP app, tools, resources, prompts
│ ├── client.py # AuthenticatedMCPClient
│ ├── tokens.py # JWT issuance
│ ├── keygen.py # Secret generation
│ └── cli.py # Console entry points
├── tests/
│ ├── unit/ # Offline tests
│ └── integration/ # Real server + client over HTTP
├── docs/ # PRD, roadmap, architecture diagrams
├── .env.example # Every variable, with placeholder values
├── Makefile
└── pyproject.tomlConsole scripts: secure-mcp-gateway (server), secure-mcp-client, secure-mcp-token, secure-mcp-secret, secure-mcp-headers.
Security
Never commit
.env. It is git-ignored, and.env.exampleholds placeholders only.Keep
JWT_SECRETandsecure-mcp-tokenon a trusted host. Anyone with the secret can mint tokens.Serve over HTTPS outside localhost. Bearer tokens are credentials.
Prefer short-lived JWTs with only the scopes they need over static API keys.
get_currency_rateandget_fake_api_postsmake outbound HTTP requests.get_fake_api_postsfetches any URL the caller supplies, so don't expose it to untrusted clients on a host that can reach internal services.
If you find a vulnerability, please report it privately through GitHub Security Advisories rather than opening a public issue.
Roadmap
API-key and JWT bearer authentication
Scope-based tool authorization and audience binding
OAuth 2.1 with an external identity provider (Keycloak / Auth0 / Entra ID)
RS256 with JWKS key verification
Role-based access control and per-tool policies
Rate limiting and audit logging
OpenTelemetry, Prometheus and Grafana
Docker, Kubernetes and Helm deployment
GitHub Actions CI
Contributing
Contributions are welcome.
Fork the repository and create a feature branch.
Add tests for every new or changed behavior.
Run
make checkandmake test-integration, which must pass.Open a pull request that describes the change and why.
License
Licensed under the Apache License 2.0.
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
Zero-setup MCP gateway securely connecting AI to your tools with authentication and workflows
Build, validate, deploy — HTTP APIs, cron jobs, webhooks and MCP tools — from your AI client. Air Pipe MCP token as a bearer credential, e.g. 'Authorization: Bearer <token>'. Create one at https://app.airpipe.io/
MCP server for secureFlows: token-free URL builders and integration-linting tools for AI agents.
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
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
- FlicenseNot gradedqualityFmaintenanceEnables remote MCP clients to securely access AgentMemory tools like memory_recall, memory_smart_search, and memory_save through OAuth 2.1 and Streamable HTTP, while keeping the AgentMemory backend secret private.-
- 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
- AlicenseNot gradedqualityCmaintenanceSecures MCP tools as an OAuth 2.1 resource server, validating short-lived delegated tokens, enforcing policy-as-code, and auditing AI agent actions.MIT