mcp-tool-gateway

mcp-tool-gateway

A secure tool-execution plane for agentic AI that enforces JWT authentication, rate limiting, prompt-injection inspection, and audit logging, while ingesting downstream OpenAPI endpoints as MCP tools.

Category
Visit Server

README

๐Ÿ” 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                                         โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

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)

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured