mcp-gateway
MCP Gateway
MCP エコシステムのセキュリティ中間層 — LLM とツールサーバーの間に防護バリアを構築
何を解決するのか?
LLM Agent が MCP プロトコルを通じて外部ツールを呼び出す際、3つの主要なリスクがあります:
認証情報の漏洩 — ツールが返すレスポンスに API Key、Token などの機密情報が含まれ、そのまま LLM コンテキストに露出する可能性があります
プライバシーデータの外部流出 — ユーザーの個人情報(氏名、身分証番号、銀行カード番号)がツール呼び出しの連鎖の中で送信される可能性があります
悪意のあるツール注入 — ツールの説明に prompt injection 命令が隠され、Agent に危険な操作を実行させてしまう可能性があります
MCP Gateway はプロキシレイヤーとしてすべてのトラフィックを傍受し、リクエスト/レスポンスが Agent に到達する前にセキュリティフィルタリングを実行します。
Related MCP server: @guardbee/mcp-security-proxy
アーキテクチャ概要
┌─────────────┐ ┌──────────────────────────────────┐ ┌─────────────┐
│ │ │ MCP Gateway │ │ │
│ LLM Agent │ ───► │ ┌──────────┐ ┌──────────────┐ │ ───► │ MCP Server │
│ │ │ │ Sanitize │ │ Plugin │ │ │ (tools) │
│ │ ◄─── │ │ Request │ │ Pipeline │ │ ◄─── │ │
└─────────────┘ │ └──────────┘ └──────────────┘ │ └─────────────┘
│ ▲ │ │
│ │ ┌──────────▼──┐ │
│ │ │ Sanitize │ │
│ │ │ Response │ │
│ │ └─────────────┘ │
└──────────────────────────────────┘コアフロー:
リクエスト方向:Plugin Pipeline がパラメータをマスキング処理(PII の除去、注入命令のフィルタリングなど)します
レスポンス方向:ツールの戻り値に対して Token マスキング、機密情報のフィルタリングを行います
起動段階:Security Scanner が設定済みのすべての MCP Server に対してレピュテーション評価を実施します
クイックスタート
インストール
git clone <your-repo-url>
cd mcp-gateway
pip install -e .任意の依存関係:
pip install -e .[presidio] # 启用 PII 检测(基于 Microsoft Presidio)最小構成
プロジェクトルートに mcp.json を作成します:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
}
}
}起動
# 启用基础 Token 掩码
mcp-gateway -p basic
# 启用 Token 掩码 + PII 检测
mcp-gateway -p basic -p presidio
# 调试模式
LOGLEVEL=DEBUG mcp-gateway -p basicCursor / 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", "."]
}
}
}
}
}セキュリティ保護機能
Token マスキング(basic プラグイン)
レスポンス内の機密認証情報を自動識別して置換します。主要なクラウドプラットフォームおよび開発ツールの12種類のキー形式に対応しています:
タイプ | 例の形式 |
AWS Access Key |
|
GitHub Token |
|
Azure Client Secret |
|
GCP API Key |
|
JWT Token |
|
HuggingFace Token |
|
GitLab Session Cookie |
|
Slack App Token |
|
Microsoft Teams Webhook |
|
mcp-gateway -p basicPII 検出(presidio プラグイン)
Microsoft Presidio エンジンに基づき、テキスト内の個人特定情報を自動認識して匿名化します:
クレジットカード番号、IP アドレス、電子メール
電話番号、社会保障番号(SSN)
その他のエンティティタイプについては Presidio ドキュメント を参照してください
pip install -e .[presidio]
mcp-gateway -p presidioセキュリティスキャナー(--scan)
起動前にすべての MCP Server に対してレ誉为評価とツール説明を分析します:
mcp-gateway --scan -p basicスキャンの指標:
レピュテーション評価 — GitHub データ(Star、Fork、Issue のアクティビティ)と NPM ダウンロード数に基づいて総合スコアを計算します
ツール説明のスキャン — 隠された prompt injection 命令、機密ファイルパスへの参照、危険な操作命令を検出します
自動ブロック — レピュテーションスコアが基準値(デフォルト 30 点)未満の Server は
blockedとマークされ、ロードがブロックされます
スキャン結果は設定ファイルに書き込まれます:
{
"servers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "."],
"blocked": "passed"
}
}
}ステータス値:"passed"(安全)| "blocked"(ブロック)| "skipped"(手動スキップ)| null(未スキャン)
呼び出しトレーシング
Xetrack トレーシングプラグイン
すべてのツール呼び出しの完全なコンテキストを記録し、SQLite と DuckDB でのクエリをサポートします:
pip install xetrack
mcp-gateway -p xetrack環境変数の設定:
XETRACK_DB_PATH— SQLite データベースのパスXETRACK_LOGS_PATH— ログファイルのディレクトリ
{
"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/"
}
}
}
}クエリ例:
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;プロキシツール
Gateway は LLM に以下の2つの標準化ツールを公開します:
ツール | 機能 |
| 登録済みのすべての MCP Server の能力リストを取得し、LLM が適切なツールを選択するのを支援します |
| Gateway を介して任意の MCP ツール呼び出しを実行し、リクエスト/レスポンスのセキュリティ処理を自動的に行います |
プラグイン開発
プラグインシステムはABC ベースクラス + デコレータ登録パターンに基づいています:
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プラグインは PluginManager によって自動検出・ロードされ、リクエスト/レスポンスの双方向インターセプトをサポートします。
プロジェクト構造
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ライセンス
This server cannot be deployed
Maintenance
Related MCP Connectors
Security & DLP proxy for MCP: tool-poisoning scans, PII redaction on tool args/results. Beta.
Security firewall for AI agents — scans MCP calls for injection, secrets, and risks.
Scan prompts for injection attacks, redact PII, and audit LLM SDK usage from any MCP client
Real-time MCP & A2A prompt-injection, jailbreak, and tool-schema poisoning firewall for AI agents.
Related MCP Servers
- FlicenseNot gradedqualityCmaintenanceEnables safe use of any MCP server by proxying and live-scanning all tool requests and responses, blocking or redacting poison descriptions, indirect prompt injection, malicious arguments, and unauthorized destinations.-
- AlicenseNot gradedqualityFmaintenanceEnables transparent security for any MCP server by intercepting tool calls, blocking prompt injection attempts, masking PII in responses, and writing immutable audit logs.2,302 npmMIT
- AlicenseNot gradedqualityBmaintenanceEnforces MCP security by proxying between AI agents and MCP servers, scanning tools and results for prompt injection, enforcing allow/deny policies, redacting sensitive arguments, and logging all traffic.22 PyPIMIT
- AlicenseNot gradedqualityCmaintenanceEnables secure, low-latency proxying of MCP tool calls by detecting and blocking malicious requests such as path traversals and command injections, while redacting leaked credentials.11 npmMIT