Skip to main content
Glama

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,并可自动检测

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


中文

-
security - not tested
A
license - permissive license
-
quality - not tested

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/dygogogo/agent-guard-mcp'

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