Skip to main content
Glama
agent-guard-mcp
by dygogogo

agent-guard-mcp

CI License: MIT Go Reference

MCP Guard Server — 为 AI Agent 提供预算控制、审批工作流和审计日志记录。

适用于 Claude Code、Cursor、ChatGPT 以及任何支持 MCP 协议的 AI Agent。

功能特性

  • 预算控制 — 设置每日额度硬上限,防止 Agent 超支

  • 高风险审批 — 超过金额阈值或匹配敏感资源关键字的操作将触发人工审批

  • 审批工作流 — Agent 发起请求 → 生成令牌 → 人工通过仪表板或 Telegram 进行审批

  • 审计日志 — 记录所有支出、审批和拒绝操作,支持基于游标的分页查询

  • Web 仪表板 — 基于 Gin + HTMX + Tailwind 的实时仪表板

  • Telegram 通知 — 为高风险操作提供即时审批链接

  • 多传输协议 — 支持 stdio / SSE / StreamableHTTP,并可自动检测

Related MCP server: llm-cost-guard

MCP 工具

工具

描述

check_budget

查询今日预算状态

spend

执行支出(自动检测高风险)

request_approval

显式请求人工审批

approve

批准待处理的令牌

reject

拒绝待处理的令牌

check_approval

轮询审批状态

get_audit_log

带过滤和分页功能的审计日志查询

get_pending_approvals

列出所有待处理的审批请求

快速开始

要求

  • Go 1.24+

  • 无需 CGO(纯 Go SQLite 驱动)

从源码构建

git clone https://github.com/dygogogo/agent-guard-mcp.git
cd agent-guard-mcp
go build -o mcp-guard main.go

下载预编译二进制文件

下载适用于您平台的最新版本:

或者访问 最新发布 页面。

配置

通过环境变量或 .env 文件进行配置:

变量

描述

默认值

MCP_TRANSPORT

传输协议: stdio / sse / http

自动检测 (TTY → http)

BUDGET_LIMIT

每日预算上限 (额度)

10.0

HIGH_RISK_THRESHOLD

高风险金额阈值

2.0

HIGH_RISK_RESOURCES

高风险资源关键字 (逗号分隔)

delete,send

DB_PATH

SQLite 数据库路径

./mcp-guard.db

DASHBOARD_PORT

仪表板 HTTP 端口

8080

APPROVAL_BASE_URL

审批链接的基础 URL

http://localhost:8080

LOG_LEVEL

日志级别: debug/info/warn/error

info

PAYER_ID

付款人标识

hostname

TELEGRAM_BOT_TOKEN

Telegram 机器人令牌 (可选)

-

TELEGRAM_CHAT_ID

Telegram 聊天 ID (可选)

-

运行

# HTTP mode (auto-detected, with Dashboard)
./mcp-guard
# Dashboard: http://localhost:8080/dashboard
# MCP endpoint: http://localhost:8080/mcp

# stdio mode (for MCP clients)
MCP_TRANSPORT=stdio ./mcp-guard

# SSE mode
MCP_TRANSPORT=sse ./mcp-guard
# SSE endpoint: http://localhost:8080/sse

Claude Code 集成

添加到 Claude Code 的 MCP 配置中:

{
  "mcpServers": {
    "agent-guard-mcp": {
      "command": "mcp-guard",
      "env": {
        "MCP_TRANSPORT": "stdio",
        "BUDGET_LIMIT": "10"
      }
    }
  }
}

架构

┌─────────────┐     MCP Protocol     ┌────────────────┐
│  AI Agent   │ ◄──────────────────► │  MCP Guard      │
│ (Claude,    │   stdio / HTTP       │  Server         │
│  Cursor...) │                      │                  │
└─────────────┘                      │  ┌────────────┐ │
                                     │  │  BudgetStore │ │
┌─────────────┐    HTTP              │  │  (SQLite)    │ │
│  Dashboard  │ ◄──────────────────► │  └────────────┘ │
│  (Gin+HTMX) │                      └────────────────┘
└─────────────┘

┌─────────────┐    Webhook
│  Telegram   │ ◄────── Approval notifications
└─────────────┘

核心文件

文件

描述

main.go

入口点、传输选择、优雅关闭

server.go

包含 8 个已注册工具的 MCP 服务器

store.go

BudgetStore 接口 + SQLite 实现

approval.go

高风险检测、审批工作流、Telegram

config.go

环境配置、自动传输检测

logger.go

zap 日志记录 (stdio 模式: 仅限文件)

dashboard.go

Gin Web 仪表板

审批工作流

1. Agent calls spend(amount=5.0, resource="/api/delete")
2. MCP Guard detects high-risk (amount > threshold OR resource keyword matched)
3. Returns {status: "pending_approval", token: "xxx"}
4. Agent polls check_approval(token) for status
5. Human approves/rejects via Dashboard or Telegram
6. Agent receives final result (approved/rejected/budget_exceeded)

测试

# All tests with race detection
go test -race -count=1 ./...

# Integration tests only
go test -race -run TestIntegration -v ./...

# Coverage
go test -race -cover ./...

技术栈

  • Go 1.24 — 编程语言

  • mcp-go — MCP 协议 Go SDK

  • Gin — Web 框架 (仪表板)

  • modernc.org/sqlite — 纯 Go SQLite (无 CGO)

  • zap — 结构化日志记录

  • HTMX + Tailwind CSS — 仪表板前端

许可证

MIT


中文

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      MCP server for AI agent security guardrails. Provides input validation, prompt injection detection, PII redaction, output filtering, policy enforcement, rate limiting, and comprehensive audit logging.
      72 npm
      1
      MIT
    • A
      license
      B
      quality
      A
      maintenance
      Governance runtime for AI agents: a guard tool evaluates risky actions against policy before they execute (block / warn / require human approval), approvals route to a human queue, and every action becomes a replayable decision record with per-action spend tracking. Runs over stdio via npx @dashclaw/mcp-server; works with Claude Code, Codex, LangChain, CrewAI, or any MCP host.
      68
      320
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      MartinLoop is the independent governance and financial control layer for AI coding agents. Set hard spend limits, prevent runaway loops, enforce verification, trigger rollback on failure, and generate auditable receipts showing what changed, what it cost, and whether the work passed.
      24
      224 npm
      263
      Apache 2.0

    Appeared in Searches