mcp-runtime-guard

mcp-runtime-guard

Runtime proxy that intercepts and blocks MCP tool calls based on YAML-defined policies, enforcing security rules for AI agents like Claude Code or Cursor.

Category
访问服务器

README

MCP Runtime Guard

Language

  • 🇯🇵 Japanese (このページ)
  • 🌐 English

👉 📚 Docs

  • 🇯🇵 coming soon...
  • 🌐 coming soon...

MCPサーバーへのtool callをポリシーに基づいてリアルタイムでブロックするランタイムプロキシ。

AIエージェント(Claude Code、Cursor等)と実MCPサーバーの間に透過的に挟まり、YAMLで定義したルールに違反するtool callを実行前にブロックする。

仕組み

Claude Code / Cursor
    │  stdio (JSON-RPC 2.0)
    ▼
mcp-runtime-guard   ← ここでポリシー評価(実行前)
    │  stdio (JSON-RPC 2.0, subprocess)
    ▼
実MCPサーバー

mcp-runtime-guard 自身がMCPサーバーとして振る舞い、実サーバーをサブプロセスとして起動する。tools/listresourcesprompts はそのまま転送し、tools/call だけを傍受する。


特徴

  • 同期的ブロック — deny 判定時は upstream に一切転送しない
  • ポリシー駆動 — ルールはコード外のYAMLファイルで定義。再ビルド不要
  • fail-closed — policy ファイルが読めなければ起動失敗。プロキシがクラッシュすれば stdio が切れてエージェントにエラーが返る
  • 完全インターセプト — すべての tools/call がポリシーエンジンを通過する。抜け道なし

インストール

npm install -g mcp-runtime-guard

npx で直接使う場合:

npx mcp-runtime-guard --policy ./policy.yaml -- npx @modelcontextprotocol/server-filesystem /home/user

使い方

mcp-runtime-guard --policy <ポリシーファイルのパス> -- <upstreamコマンド> [args...]

-- 以降がすべて upstream MCPサーバーのコマンドライン。

オプション

オプション 説明 デフォルト
--policy <path> YAMLポリシーファイルのパス 必須
--log-level <level> debug / info / warn info
--log-file <path> JSONL監査ログの出力先 stderrのみ

Claude Desktop への組み込み例

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "mcp-runtime-guard",
        "--policy", "/home/user/.config/mcp-runtime-guard/policy.yaml",
        "--",
        "npx", "@modelcontextprotocol/server-filesystem", "/home/user"
      ]
    }
  }
}

ポリシーファイル

version: 1

# ルールにマッチしなかったtool callのデフォルト動作
# 省略した場合は "block"(fail-closed)
default_action: allow

rules:
  # ツール名完全一致 + 引数条件
  - name: no-credential-read
    tool: read_file
    when:
      path:
        matches: '\.env$|\.env\.|\.aws/|\.ssh/|id_rsa|\.pem$'
    action: block
    message: "Credential files are protected by mcp-runtime-guard"

  # ツール名 regex
  - name: no-shell
    tool:
      matches: 'execute_command|run_shell|bash|eval'
    action: block
    message: "Shell execution is not allowed"

  # not_matches でallowlist
  - name: restrict-fetch
    tool: fetch
    when:
      url:
        not_matches: '^https://api\.github\.com/'
    action: block
    message: "External requests restricted to api.github.com"

logging:
  level: info
  # file: ~/.mcp-runtime-guard/audit.jsonl

マッチングルール

設定 動作
tool: "write_file" 完全一致
tool: { matches: "..." } 正規表現マッチ
when: { key: { matches: "..." } } 引数の値が正規表現にマッチ
when: { key: { not_matches: "..." } } 引数の値が正規表現にマッチ
複数の when 条件 AND 評価
複数のルール 上から順に評価、最初のマッチが適用
マッチなし default_action に従う

ブロック時のレスポンス

upstreamサーバーは呼ばれず、MCP標準の CallToolResult エラーが返る。

{
  "content": [{
    "type": "text",
    "text": "[mcp-runtime-guard] BLOCKED: Credential files are protected by mcp-runtime-guard (rule: no-credential-read)"
  }],
  "isError": true
}

ログ

stderr(リアルタイム確認用):

[mcp-runtime-guard] BLOCK  read_file   {"path":"/home/user/.env"}   rule=no-credential-read
[mcp-runtime-guard] ALLOW  read_file   {"path":"/tmp/data.json"}

JSONLファイル(構造化監査ログ、オプション):

{"ts":"2026-04-07T10:00:01Z","action":"BLOCK","tool":"read_file","args":{"path":"/home/user/.env"},"rule":"no-credential-read","message":"Credential files are protected by mcp-runtime-guard"}
{"ts":"2026-04-07T10:00:02Z","action":"ALLOW","tool":"read_file","args":{"path":"/tmp/data.json"},"rule":null,"message":null}

License

Apache-2.0

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选