mcpField
A
Agent Guardrail MCP Server

Agent Guardrail MCP Server

ローカル
github.comセキュリティ032 週間前に更新

Agent Guardrail MCP Server について

Agent Guardrailは、AIエージェントの行動を管理するPythonライブラリ、コマンドライン、ホスト型APIです。エージェントの開発者や運用担当者向けに、許可・拒否・承認要求の判定と操作記録を提供します。

主な機能

  1. 01ツールと対象の許可・拒否リスト
  2. 02エージェントごとの支出上限
  3. 03緊急停止スイッチ
  4. 04操作の記録と再生
  5. 05人による承認ゲート
  6. 06操作ごとのリスク評価

活用シーン

  1. 01エージェントのファイルやネットワーク利用の制限
  2. 02エージェントの支出上限の設定
  3. 03エージェント操作の確認や再生
  4. 04高リスク操作への承認要求

設定

ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。

mcp.json · 共通設定
{
"mcpServers": {
"jarvisonm4-agent-guardrail": {
"command": "uvx",
"args": [
"agent-guardrail"
]
}
}
}
起動コマンドuvx agent-guardrail

ローカルサーバーにはマシン上の実行環境(Node.js 18 以上など)が必要です。設定ファイルの場所はクライアントごとに異なります。

パッケージ
pypiagent-guardrail0.1.2

ツール

ツール一覧はまだ取得されていません

ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。

詳細

Agent Guardrail

AI エージェントのアクションレベルのガバナンス — エージェントの「発言」ではなく「行動」を制御します。

PyPI License: MIT Python 3.10+


問題点

AI エージェントがツールにアクセスできるようになってきています。シェルコマンドの実行、API 呼び出し、ファイルの読み取り、金銭の支出が可能です。しかし、ほとんどの「ガードレール」がフィルタリングするのは、エージェントの「発言」だけで、「行動」ではありません。

実際に起きた事例:

  • AutoGPT が単一のセッションで、API 呼び出しに自律的に 1 万ドル以上を費やしました
  • ChaosGPT が軍事システムへのアクセスと、ほかの AI エージェントの勧誘を試みました
  • Air Canada chatbot が返金ポリシーを捏造し、航空会社に 800 ドル以上の損害を与えました

必要なのは、アクションレベルの制御です。出力のフィルタリングではありません。

Agent Guardrail の機能

Agent Framework --> Agent Guardrail --> {allow, deny, require_approval}
                                    --> Flight Recorder logs everything
  • ポリシーエンジン — ツールと対象に対する許可リスト、拒否リスト、glob パターン
  • 支出上限 — エージェントごとの 1 日および合計の米ドル上限
  • キルスイッチ — 暴走したエージェントのすべてのアクションを即座に拒否
  • フライトレコーダー — すべてのアクションを記録し、完全なリプレイに対応
  • 承認ゲート — リスクの高いアクションを人によるレビューに回す
  • リスクスコアリング — アクションの種類ごとにリスクを自動評価
  • 3 種類のテンプレート — 厳格、中程度、寛容(1 つのコマンドで適用)
  • 評価ごとの従量課金 — 無料枠 + Blockonomics 経由の BTC クレジットパック

依存関係ゼロ。 Python 標準ライブラリのみを使用します。ストレージには SQLite を使用します。

30 秒クイックスタート

pip install agent-guardrail

# Register an agent
agent-guardrail register "my-research-agent" --framework langchain

# Apply the moderate policy template
agent-guardrail apply-template moderate <agent-id>

# Test it
agent-guardrail eval <agent-id> bash --target /workspace/test.sh     # -> allow
agent-guardrail eval <agent-id> bash --target /etc/shadow             # -> deny
agent-guardrail eval <agent-id> sudo                                  # -> deny

Python API

from agent_guardrail import GuardrailStore, PolicyEngine, DEFAULT_POLICIES

# Initialize
store = GuardrailStore()  # ~/.agent-guardrail/guardrail.db
engine = PolicyEngine(store)

# Register agent
agent = store.register_agent("my-agent", framework="langchain")

# Apply policy template
store.save_policy({
    "name": "moderate",
    "agent_id": agent["id"],
    "rules": DEFAULT_POLICIES["moderate"]["rules"],
})

# Evaluate actions
decision = engine.evaluate(agent["id"], "bash", target="/workspace/run.sh")
# -> PolicyDecision(decision="allow", risk_score=0.7)

decision = engine.evaluate(agent["id"], "bash", target="/etc/shadow")
# -> PolicyDecision(decision="deny", reason="Target '/etc/shadow' is denied...")

# Evaluate + record to flight recorder
decision = engine.evaluate_and_record(
    agent_id=agent["id"],
    action_type="api_call",
    tool_name="openai_chat",
    cost_usd=0.05,
    session_id="session-123",
)

フレームワークとの統合

LangChain コールバック
from agent_guardrail import GuardrailStore, PolicyEngine

class GuardrailCallback:
    """Drop into any LangChain agent as a callback handler."""
    def __init__(self, agent_id, db_path=None):
        self._engine = PolicyEngine(GuardrailStore(db_path=db_path))
        self.agent_id = agent_id

    def on_tool_start(self, serialized, input_str, **kwargs):
        decision = self._engine.evaluate_and_record(
            agent_id=self.agent_id,
            action_type="tool_call",
            tool_name=serialized.get("name"),
            target=input_str[:200],
        )
        if decision.decision == "deny":
            raise PermissionError(f"Guardrail: {decision.reason}")
CrewAI タスクガードレール
from agent_guardrail import GuardrailStore, PolicyEngine

def make_guardrail(agent_id, db_path=None):
    engine = PolicyEngine(GuardrailStore(db_path=db_path))

    def check(task_output):
        decision = engine.evaluate_and_record(
            agent_id=agent_id, action_type="task_output",
            target=str(task_output)[:200],
        )
        if decision.decision == "deny":
            return (False, f"Blocked: {decision.reason}")
        return (True, task_output)
    return check

# task = Task(description="...", guardrail=make_guardrail("agent-id"))
汎用デコレーター
from agent_guardrail import GuardrailStore, PolicyEngine
import functools

def guardrail(agent_id, action_type="function_call", db_path=None):
    engine = PolicyEngine(GuardrailStore(db_path=db_path))
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            target = str(args[0])[:200] if args else None
            decision = engine.evaluate_and_record(
                agent_id=agent_id, action_type=action_type,
                tool_name=func.__name__, target=target,
            )
            if decision.decision == "deny":
                raise PermissionError(f"Guardrail: {decision.reason}")
            return func(*args, **kwargs)
        return wrapper
    return decorator

@guardrail("my-agent", action_type="bash")
def run_command(cmd):
    ...

ホステッド API(エージェント向け)

ライブラリは人間向けです。API はエージェント向けです。

5 つのサブエージェントを実行するオーケストレーターは、pip install を実行するのではなく、エンドポイントを呼び出します。

# Start the proxy server
pip install agent-guardrail[proxy]
guardrail-proxy --port 8300 --admin-key YOUR_ADMIN_KEY
# Register an agent (admin)
curl -X POST http://localhost:8300/v1/agents \
  -H "X-Admin-Key: YOUR_ADMIN_KEY" \
  -d '{"name": "research-agent", "framework": "crewai"}'

# Evaluate an action (agent)
curl -X POST http://localhost:8300/v1/evaluate \
  -H "X-API-Key: gw_agent_key_here" \
  -d '{
    "agent_id": "...",
    "action_type": "bash",
    "tool_name": "shell",
    "target": "/etc/shadow",
    "cost_usd": 0.0
  }'
# -> {"decision": "deny", "reason": "Target denied...", "risk_score": 0.7}

API の全ドキュメントは http://localhost:8300/docs(Swagger UI)をご覧ください。

課金と料金

無料枠が含まれています。さらに必要な場合は、Bitcoin でお支払いください。

プラン評価回数料金1 評価あたり
無料エージェントごとに 1 日 100 回$0$0
スターター1,000 回$10$0.010
グロース5,000 回$40$0.008
スケール25,000 回$150$0.006

クレジットは前払いで、有効期限はありません。管理者認証済みのリクエストは、課金を完全に回避します。

仕組み:

# Check your balance
curl http://localhost:8300/v1/billing/balance \
  -H "X-API-Key: gw_your_agent_key"

# Buy credits (returns a BTC address + amount)
curl -X POST http://localhost:8300/v1/billing/checkout \
  -H "X-API-Key: gw_your_agent_key" \
  -d '{"pack_id": "pack_1000"}'
# -> {"btc_address": "bc1q...", "amount_btc": 0.00015, "amount_satoshi": 15000, ...}

# Pay the BTC address -> webhook confirms -> credits granted automatically

無料枠を使い切り、クレジットも残っていない場合、/v1/evaluate は利用可能なパックへのリンクとともに 402 Payment Required を返します。

セルフホスト環境での課金: BLOCKONOMICS_API_KEY と BLOCKONOMICS_WEBHOOK_SECRET の環境変数を設定してください。これらが設定されていない場合、課金は無効になり、計測なしですべての評価が実行されます(後方互換性あり)。

ポリシールールのリファレンス

{
    "tool_allowlist": ["read_file", "write_file"],    # Only these tools allowed
    "tool_denylist": ["sudo", "rm", "delete*"],       # These tools always denied
    "target_allowlist": ["/workspace/*"],              # Only these targets allowed
    "target_denylist": ["/etc/*", "*.env", "*.key"],   # These targets always denied
    "network_allowlist": ["api.openai.com"],           # Allowed network targets
    "network_denylist": ["*"],                         # Denied network targets
    "spend_cap_daily_usd": 25.0,                      # Daily spend limit
    "spend_cap_total_usd": 500.0,                     # Lifetime spend limit
    "require_approval": ["bash", "install"],           # Human approval required
    "risk_threshold": 0.8,                             # Auto-approval gate
}

パターンは glob マッチング(*、?、[abc])に対応しています。

判定フロー

Kill switch? ──deny──> DENY
      |
Agent enabled? ──no──> DENY
      |
Spend cap? ──exceeded──> DENY
      |
Tool denylist? ──match──> DENY
      |
Target denylist? ──match──> DENY
      |
Approval required? ──match──> REQUIRE_APPROVAL
      |
Risk threshold? ──exceeded──> REQUIRE_APPROVAL
      |
Tool allowlist? ──not in list──> DENY
      |
Target allowlist? ──not in list──> DENY
      |
DEFAULT ──> ALLOW

アーキテクチャ

+-------------------+     +------------------+     +-----------------+
|  Agent Framework  |---->|  Billing Check   |---->|  Policy Engine  |
|  (LangChain,     |     |  (free tier /    |     |  (evaluate)     |
|   CrewAI, custom) |     |   credits)       |     +-----------------+
+-------------------+     +------------------+            |
                                 |                        v
                                 |           +------------------------+
                          402 if empty       |  Decision:             |
                                             |  allow / deny /        |
                                             |  require_approval      |
                                             +------------------------+
                                                         |
                                                         v
                                             +-----------------+
                                             |  Flight Recorder|
                                             |  (SQLite)       |
                                             +-----------------+

+-------------------+     +------------------+
|  BTC Payment      |---->|  Blockonomics    |
|  (checkout)       |     |  (xpub-derived   |
+-------------------+     |   addresses)     |
                          +------------------+
                                 |
                          webhook (status=2)
                                 |
                                 v
                          +------------------+
                          |  Credit Grant    |
                          |  (billing_ledger)|
                          +------------------+

比較

機能Agent GuardrailGuardrails AINeMo GuardrailsDIY
アクションレベルの制御ありなし(出力のみ)なし(対話のみ)手動
支出上限ありなしなし手動
キルスイッチありなしなし手動
フライトレコーダーありなしなし手動
評価ごとの従量課金あり(BTC)なしなし手動
依存関係ゼロありなし(多数)なし(多数)さまざま
フレームワーク非依存ありLangChain に特化LangChain に特化あり
ホステッド APIありクラウドのみなし手動

CLI リファレンス

agent-guardrail agents                      # List registered agents
agent-guardrail register "name"             # Register a new agent
agent-guardrail kill <agent_id>             # Emergency kill switch
agent-guardrail unkill <agent_id>           # Revoke kill switch
agent-guardrail policies                    # List policies
agent-guardrail apply-template <template> <agent_id>
agent-guardrail actions [--agent X] [--decision deny]
agent-guardrail replay <session_id>         # Session replay
agent-guardrail approvals                   # Pending approvals
agent-guardrail approve <id>                # Approve action
agent-guardrail deny <id>                   # Deny action
agent-guardrail eval <agent_id> <type> [--target X] [--cost 0.5]
agent-guardrail stats                       # Statistics

設定

変数デフォルト用途
GUARDRAIL_DB~/.agent-guardrail/guardrail.dbSQLite データベースのパス
GUARDRAIL_LOG_DIR~/.agent-guardrail/logsCLI ログディレクトリ
GUARDRAIL_ADMIN_KEY(none)プロキシ用の管理 API キー
BLOCKONOMICS_API_KEY(none)Blockonomics Store API キー(課金が有効になります)
BLOCKONOMICS_WEBHOOK_SECRET(none)Webhook 検証用のシークレット
GUARDRAIL_BILLING_ENABLEDtrueAPI キーが設定されていても課金を無効にするには、false を設定します

ライセンス

MIT

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。