Skip to main content
Glama
wxsh-hub

mcp-gateway

by wxsh-hub

MCP Gateway

Sichere Zwischenschicht für das MCP-Ökosystem — eine Schutzbarriere zwischen LLM und Tool-Servern

License: MIT Python 3.10+

Welches Problem löst es?

Wenn ein LLM-Agent über das MCP-Protokoll externe Tools aufruft, bestehen drei zentrale Risiken:

  1. Credential-Leak — Antworten von Tools können sensible Informationen wie API-Keys oder Tokens enthalten, die direkt im LLM-Kontext offengelegt werden.

  2. Verlust privater Daten — Persönliche Benutzerdaten (Name, Ausweisnummer, Bankkartennummer) können in der Tool-Aufrufkette übertragen werden.

  3. Böswillige Tool-Injektion — In Tool-Beschreibungen können Prompt-Injection-Anweisungen versteckt sein, die den Agenten zu gefährlichen Aktionen verleiten.

MCP Gateway fungiert als Proxy-Ebene, die den gesamten Datenverkehr abfängt und vor dem Erreichen des Agenten sicher filtert (Anfragen/Antworten).

Related MCP server: arc-gate-mcp

Architekturübersicht

┌─────────────┐      ┌──────────────────────────────────┐      ┌─────────────┐
│             │      │          MCP Gateway             │      │             │
│   LLM Agent │ ───► │  ┌──────────┐  ┌──────────────┐  │ ───► │  MCP Server │
│             │      │  │ Sanitize │  │   Plugin     │  │      │  (tools)    │
│             │ ◄─── │  │ Request  │  │   Pipeline   │  │ ◄─── │             │
└─────────────┘      │  └──────────┘  └──────────────┘  │      └─────────────┘
                     │         ▲               │         │
                     │         │    ┌──────────▼──┐      │
                     │         │    │  Sanitize   │      │
                     │         │    │  Response   │      │
                     │         │    └─────────────┘      │
                     └──────────────────────────────────┘

Kernablauf:

  • Anfrage-Richtung: Die Plugin-Pipeline bereinigt Parameter (z. B. Entfernen von PII, Filtern von Injektionsanweisungen)

  • Antwort-Richtung: Token-Maskierung und Filterung sensibler Informationen für Tool-Rückgabewerte

  • Startphase: Der Security Scanner führt eine Reputationsbewertung aller konfigurierten MCP-Server durch

Schnellstart

Installation

git clone <your-repo-url>
cd mcp-gateway
pip install -e .

Optionale Abhängigkeiten:

pip install -e .[presidio]   # 启用 PII 检测(基于 Microsoft Presidio)

Minimalkonfiguration

Erstellen Sie mcp.json im Projektstammverzeichnis:

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
    }
  }
}

Start

# 启用基础 Token 掩码
mcp-gateway -p basic

# 启用 Token 掩码 + PII 检测
mcp-gateway -p basic -p presidio

# 调试模式
LOGLEVEL=DEBUG mcp-gateway -p basic

Integration in Cursor / Claude Desktop

{
  "mcpServers": {
    "mcp-gateway": {
      "command": "mcp-gateway",
      "args": [
        "--mcp-json-path", "~/.cursor/mcp.json",
        "-p", "basic",
        "-p", "xetrack"
      ],
      "servers": {
        "filesystem": {
          "command": "npx",
          "args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
        }
      }
    }
  }
}
{
  "mcpServers": {
    "mcp-gateway": {
      "command": "<python-path>",
      "args": [
        "-m", "mcp_gateway.server",
        "--mcp-json-path", "<path-to-config>",
        "-p", "basic"
      ],
      "servers": {
        "filesystem": {
          "command": "npx",
          "args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
        }
      }
    }
  }
}

Sicherheitsfunktionen

Token-Maskierung (basic-Plugin)

Automatische Erkennung und Ersetzung sensibler Anmeldeinformationen in Antworten. Unterstützt 12 gängige Schlüsselformate von Cloud-Plattformen und Entwicklungswerkzeugen:

Typ

Beispielformat

AWS Access Key

AKIA...

GitHub Token

ghp_..., gho_...

Azure Client Secret

*.azure.com-bezogen

GCP API Key

AIza...

JWT Token

eyJ...

HuggingFace Token

hf_...

GitLab Session Cookie

_gitlab_session=...

Slack App Token

xapp-...

Microsoft Teams Webhook

*.webhook.office.com

mcp-gateway -p basic

PII-Erkennung (presidio-Plugin)

Basierend auf der Microsoft-Presidio-Engine werden personenbezogene Daten im Text automatisch erkannt und anonymisiert:

  • Kreditkartennummern, IP-Adressen, E-Mail-Adressen

  • Telefonnummern, Sozialversicherungsnummern (SSN)

  • Weitere Entitätstypen finden Sie in der Presidio-Dokumentation

pip install -e .[presidio]
mcp-gateway -p presidio

Sicherheitsscanner (--scan)

Vor dem Start werden alle MCP-Server einer Reputationsbewertung und Tool-Beschreibungsanalyse unterzogen:

mcp-gateway --scan -p basic

Scan-Dimensionen:

  • Reputationsbewertung — Berechnung einer Gesamtbewertung basierend auf GitHub-Daten (Stars, Forks, Issue-Aktivität) und NPM-Downloadzahlen

  • Tool-Beschreibungs-Scan — Erkennt versteckte Prompt-Injection-Anweisungen, Verweise auf sensible Dateipfade und Anweisungen für gefährliche Aktionen

  • Automatische Blockierung — Server mit einem Reputationswert unter dem Schwellenwert (Standard: 30 Punkte) werden als blocked markiert und am Laden gehindert

Die Scan-Ergebnisse werden in die Konfigurationsdatei geschrieben:

{
  "servers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "."],
      "blocked": "passed"
    }
  }
}

Statuswerte: "passed" (sicher) | "blocked" (blockiert) | "skipped" (manuell übersprungen) | null (nicht gescannt)

Aufruf-Tracking

Xetrack-Tracing-Plugin

Zeichnet den vollständigen Kontext aller Tool-Aufrufe auf und unterstützt SQLite- und DuckDB-Abfragen:

pip install xetrack
mcp-gateway -p xetrack

Konfiguration über Umgebungsvariablen:

  • XETRACK_DB_PATH — Pfad zur SQLite-Datenbank

  • XETRACK_LOGS_PATH — Verzeichnis für Logdateien

{
  "mcpServers": {
    "mcp-gateway": {
      "command": "mcp-gateway",
      "args": ["--mcp-json-path", "~/.cursor/mcp.json", "-p", "xetrack"],
      "env": {
        "XETRACK_DB_PATH": "tracing.db",
        "XETRACK_LOGS_PATH": "logs/"
      }
    }
  }
}

Abfragebeispiel:

from xetrack import Reader
df = Reader("tracing.db").to_df()
-- DuckDB
INSTALL sqlite; LOAD sqlite; ATTACH 'tracing.db' (TYPE sqlite);
SELECT server_name, capability_name, content_text FROM db.events LIMIT 10;

Proxy-Tools

Das Gateway stellt dem LLM zwei standardisierte Tools bereit:

Tool

Funktion

get_metadata

Ruft die Fähigkeitsliste aller registrierten MCP-Server ab, um dem LLM die Auswahl geeigneter Tools zu erleichtern

run_tool

Führt über das Gateway beliebige MCP-Tool-Aufrufe aus und übernimmt automatisch die Sicherheitsverarbeitung von Anfrage/Antwort

Plugin-Entwicklung

Das Plugin-System basiert auf ABC-Basisklassen + Dekorator-Registrierungsmuster:

from mcp_gateway.plugins.base import GuardrailPlugin
from mcp_gateway.plugins.manager import register_plugin

@register_plugin
class MyPlugin(GuardrailPlugin):
    @property
    def name(self) -> str:
        return "my-plugin"

    def process_request(self, context):
        # 请求方向的处理逻辑
        return context.arguments

    def process_response(self, context, response):
        # 响应方向的处理逻辑
        return response

Plugins werden automatisch über den PluginManager erkannt und geladen und unterstützen die bidirektionale Abfangung von Anfrage/Antwort.

Projektstruktur

mcp_gateway/
├── __init__.py              # 包入口
├── server.py                # MCP Server 生命周期管理
├── gateway.py               # 动态工具注册、CLI 参数解析
├── config.py                # 配置文件加载
├── sanitizers.py            # 请求/响应安全分发
├── plugins/
│   ├── base.py              # Plugin ABC 基类
│   ├── manager.py           # 插件发现、注册、Pipeline
│   ├── guardrails/
│   │   ├── basic.py         # Token 掩码插件
│   │   └── presidio.py      # PII 检测插件
│   └── tracing/
│       └── xetrack.py       # 调用追踪插件
├── security_scanner/
│   ├── scanner.py           # 扫描器主入口
│   ├── github_collector.py  # GitHub API 数据采集
│   ├── npm_collector.py     # NPM Registry 数据采集
│   ├── smithery_collector.py# Smithery 市场数据采集
│   ├── project_analyzer.py  # 综合信誉评分算法
│   └── tool_poisoning_analyzer.py  # 工具描述安全分析
└── tests/
    ├── test_sanitizers.py
    ├── test_tool_poisoning_analyzer.py
    ├── test_plugin_pipeline.py
    └── test_config.py

License

MIT

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
    Not graded
    maintenance
    A transparent proxy and execution firewall that intercepts and audits AI agent tool calls against configurable security policies before forwarding them to downstream MCP servers. It provides safe execution environments with features like data redaction, anti-loop protection, and unified alert dispatching.
  • A
    license
    A
    quality
    B
    maintenance
    Runtime governance proxy for MCP tool calls. Inspects tool results for prompt injection and capability abuse before they reach your agent, blocking attacks that exploit the MCP trust boundary.
    1
    2
    AGPL 3.0
  • F
    license
    Not graded
    quality
    B
    maintenance
    Enables secure interaction between LLMs and MCP tools by applying zero-trust security controls, including sensitive data masking, file system protection, and policy enforcement.

View all related MCP servers

Related MCP Connectors

  • Security firewall for AI agents — scans MCP calls for injection, secrets, and risks.

  • The WAF for agents. Pattern-based + heuristic firewall scans prompts, RAG documents, tool argume...

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

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/wxsh-hub/mcp-gateway'

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