Skip to main content
Glama
chandanCoding

mcp-tool-gateway

๐Ÿ” mcp-tool-gateway

A secure tool-execution plane for agentic AI โ€” an MCP-style tool server fronted by a gateway that enforces identity (JWT + scopes), quota (token-bucket rate limiting), and safety (prompt-injection inspection), ingests downstream APIs from OpenAPI, and writes a structured audit log. Pure Python, zero dependencies.

Mirrors the secure agent tool-execution plane I run in production (MCP / OpenAPI behind API governance, JWT validation, Entra-style scope propagation, and prompt inspection) โ€” the controls that let agentic systems clear banking compliance audits.

Request lifecycle

 agent tool call โ”€โ–ถ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ SecureToolGateway โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   (+ JWT)          โ”‚ 1 authenticate (HS256 verify, exp)                                โ”‚
                    โ”‚ 2 rate limit  (per-principal token bucket)                        โ”‚
                    โ”‚ 3 authorize   (tool.required_scope โˆˆ principal.scopes)            โ”‚
                    โ”‚ 4 inspect IN  (prompt-injection / exfiltration / cmd-injection)   โ”‚
                    โ”‚ 5 execute     (MCP server: tools/list ยท tools/call)               โ”‚
                    โ”‚ 6 inspect OUT + audit log                                         โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Related MCP server: Bastion

Components

Module

Responsibility

jwt_auth

HS256 JWT encode/verify (from scratch), exp check, Principal with scope helpers

rate_limit

TokenBucket + per-principal RateLimiter

inspection

Rule-based Inspector (instruction-override, exfiltration, command-injection, role-spoofing) with severity-based blocking

mcp

MCPServer implementing tools/list and tools/call over JSON-RPC

openapi

tools_from_openapi โ€” auto-register downstream API operations as MCP tools

audit

Append-only structured AuditLog

gateway

SecureToolGateway wiring auth โ†’ quota โ†’ authz โ†’ inspection โ†’ execute โ†’ audit

Quickstart

python examples/run_gateway.py

Output demonstrates: an authorized call, a missing-scope rejection, a blocked prompt-injection payload, an invalid token, and the populated audit trail.

from mcp_gateway import MCPServer, MCPTool, SecureToolGateway, encode

server = MCPServer()
server.register(MCPTool("get_trade_status", "...", schema,
                        handler=lambda trade_id: "ACK", required_scope="trades:read"))
gw = SecureToolGateway(server=server, secret="...")

token = encode({"sub": "agent-1", "scopes": ["trades:read"]}, "...")
gw.handle({"id": 1, "method": "tools/call",
           "params": {"name": "get_trade_status", "arguments": {"trade_id": "T-1"}}}, token)

Security properties

  • Fail-closed: missing scope, bad signature, expired token, or a high-severity finding all reject before the tool ever executes.

  • Defense in depth: inputs and outputs are inspected; everything is audited.

  • Least privilege: per-tool required_scope, per-principal quota.

Tests

pip install pytest && pytest -q

Covers JWT round-trip + tamper detection, scope enforcement, injection blocking, rate limiting, and inspector severity.

Tech

Python 3.10+ ยท stdlib only (optional: pytest)

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

โ€“Maintainers
โ€“Response time
โ€“Release cycle
โ€“Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    Not graded
    quality
    A
    maintenance
    A production-ready MCP gateway and control plane that provides credential vault, policy engine, audit logging, and managed runtime for routing tool calls between AI agents and downstream MCP servers.
    58
  • A
    license
    Not graded
    quality
    A
    maintenance
    A local-first control plane for AI agent tools, providing policy enforcement, spend caps, rate limiting, and audit trails for MCP servers.
    1
    Apache 2.0
  • A
    license
    Not graded
    quality
    C
    maintenance
    A secure MCP gateway for enterprise AI tool execution, enabling governed invocation of business tools with authentication, RBAC, audit logging, PII redaction, and async processing.
    Apache 2.0

View all related MCP servers

Related MCP Connectors

  • Security firewall for AI agents โ€” scans MCP calls for injection, secrets, and risks.

  • MCP server for secureFlows: token-free URL builders and integration-linting tools for AI agents.

  • MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/chandanCoding/mcp-tool-gateway'

If you have feedback or need assistance with the MCP directory API, please join our Discord server