mcp-trust-guard
Security middleware for MCP servers. Trust-based access control, rate limiting, and audit logging. Zero dependencies.
README
mcp-guard
KYA (Know Your Agent) security middleware for MCP servers. Abuse database, trust-based access control, rate limiting, and audit logging.
Zero dependencies. Works with any Node.js HTTP framework. Part of the KYA verification system.
Scan any MCP package for security issues: agentscores.xyz - type a package name, get instant results.
The Problem
MCP servers have no security layer. Any client can call any tool — there's no identity verification, no access control, no rate limiting, no audit trail. As AI agents begin calling MCP tools autonomously, this is a critical gap.
mcp-guard adds KYA verification to any MCP HTTP server — abuse database checks, trust-based access control, and audit logging in three lines of code.
Install
npm install mcp-trust-guard
Quick Start
import express from 'express';
import { McpGuard } from 'mcp-trust-guard';
const guard = new McpGuard({
rules: [
{ minTrust: 0, tools: ['get_*', 'list_*', 'search_*'] },
{ minTrust: 30, tools: ['create_*', 'update_*'] },
{ minTrust: 60, tools: ['delete_*', 'admin_*'] },
],
rateLimit: { window: 60, max: 30 },
audit: true,
});
const app = express();
app.use(express.json());
app.use('/mcp', guard.middleware());
// ... your MCP server handler
Every tools/call request is now verified against the caller's trust score. Read-only tools are open. Write tools need a score of 30+. Destructive tools need 60+.
How It Works
┌──────────────┐
Request ──→ Extract Identity ──→ Rate Limit ──→ │ Trust Check │ ──→ Rule Match ──→ Allow/Deny
(header) (per caller) │ (AgentScore) │ (tool pattern)
└──────────────┘
- Identity — Reads the caller's agent name from the
x-agent-nameheader (configurable) - Rate Limit — Sliding window per caller. Rejects with JSON-RPC error if exceeded
- Trust Check — Looks up the caller's trust score via AgentScore (5-min cache, fail-closed)
- Rule Match — Matches the requested tool against your rules using glob patterns. First match wins
- Allow/Deny — If the caller's score meets the rule's minimum, the request passes through. Otherwise, a JSON-RPC error is returned
Features
Trust-Based Access Control
Define tiered access based on trust scores:
const guard = new McpGuard({
rules: [
{ minTrust: 0, tools: ['read_*'] }, // Public — anyone can read
{ minTrust: 20, tools: ['query_*'] }, // Low bar — basic queries
{ minTrust: 40, tools: ['write_*'] }, // Verified agents only
{ minTrust: 70, tools: ['transfer_*'] }, // High trust — financial ops
],
defaultMinTrust: 10, // Tools not matching any rule require score >= 10
});
Tool Name Patterns
Rules use glob patterns with * wildcards:
{ minTrust: 30, tools: ['create_*', 'update_*'] } // Matches create_user, update_record
{ minTrust: 60, tools: ['admin_*'] } // Matches admin_delete, admin_config
{ minTrust: 0, tools: ['get_status'] } // Exact match only
{ minTrust: 50, tools: ['*'] } // Catch-all
Rate Limiting
In-memory sliding window per caller:
const guard = new McpGuard({
rateLimit: {
window: 60, // 60-second window
max: 30, // 30 requests per window per caller
},
});
Audit Logging
Console logging:
const guard = new McpGuard({ audit: true });
// [mcp-guard] ALLOW EmberFoundry → get_status (score: 42, band: MODERATE TRUST) score 42 >= 0 required for get_status
// [mcp-guard] DENY untrusted-bot → admin_delete (score: 3, band: UNVERIFIED) score 3 < 60 required for admin_delete
Custom audit handler:
const guard = new McpGuard({
audit: (entry) => {
db.insert('audit_log', entry);
if (!entry.allowed) alerting.notify(`Blocked ${entry.caller} from ${entry.tool}`);
},
});
Direct Trust Checks
Use the guard programmatically without middleware:
const guard = new McpGuard();
const decision = await guard.check('EmberFoundry', 'transfer_funds');
// { allowed: false, reason: 'score 14 < 70 required for transfer_funds', caller: 'EmberFoundry', trustScore: 14, trustBand: 'UNVERIFIED' }
Custom Trust Providers
Use any trust source — not just AgentScore:
import { McpGuard, TrustProvider, TrustResult } from 'mcp-trust-guard';
const myProvider: TrustProvider = {
async check(name: string): Promise<TrustResult> {
const score = await myDatabase.getAgentScore(name);
return { score, band: score > 50 ? 'TRUSTED' : 'UNTRUSTED', name };
},
};
const guard = new McpGuard({ provider: myProvider });
Wrapping Any Handler
Not using Express? Wrap any request handler:
const protectedHandler = guard.wrap(mcpHandler);
http.createServer(protectedHandler).listen(3000);
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
provider |
TrustProvider |
AgentScore | Custom trust score provider |
apiUrl |
string |
https://agentscores.xyz/api/score |
AgentScore API endpoint |
identityHeader |
string |
x-agent-name |
Header containing caller identity |
rules |
GuardRule[] |
[] |
Access rules (first match wins) |
defaultMinTrust |
number |
0 |
Min trust when no rule matches |
rateLimit |
{ window, max } |
none | Rate limit config (seconds, count) |
cacheTtl |
number |
300000 |
Trust cache TTL in ms (5 min) |
audit |
boolean | function |
false |
Enable audit logging |
allowAnonymous |
boolean |
false |
Allow requests without identity |
Identifying Callers
By default, mcp-guard reads the caller's identity from the x-agent-name HTTP header. MCP clients should include this header when making requests:
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-H "x-agent-name: MyAgent" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_data"}}'
You can change the header name:
const guard = new McpGuard({ identityHeader: 'authorization' });
Or use query parameters as a fallback — ?agent=MyAgent is checked automatically.
FAQ
What if the trust API is unreachable?
The agent gets a score of 0. Fail-closed by default. If your rules allow minTrust: 0 for some tools, those still work.
Does it work with stdio MCP servers?
No — stdio servers run locally and don't need network-level security. mcp-guard is for HTTP/SSE MCP servers that accept remote connections.
Does it modify the MCP request?
No. It only inspects tools/call requests. All other MCP methods (tools/list, resources/read, etc.) pass through untouched. When a request is allowed, it continues to your handler unchanged.
Can I use my own scoring system?
Yes. Implement the TrustProvider interface (one method: check(name) → { score, band, name }) and pass it in the config.
KYA Abuse Database (v0.2.0+)
Block agents that have been reported for abuse — data exfiltration, prompt injection, unauthorized access, and more. Community-driven, free, no API key.
const guard = new McpGuard({
abuseCheck: true, // Enable abuse database checks
abuseBlockLevel: 'CAUTION', // Block at MONITOR, CAUTION, or BLOCK level
rules: [
{ minTrust: 0, tools: ['get_*'] },
{ minTrust: 30, tools: ['write_*'] },
],
audit: true,
});
When an agent with abuse reports tries to call a tool:
[mcp-guard] DENY bad-agent → write_file (score: -1, band: ABUSE_REPORTED)
agent reported in KYA abuse database: prompt_injection (1 reports, severity: high)
Report abuse: POST https://agentscores.xyz/api/abuse/report
Check an agent: GET https://agentscores.xyz/api/abuse/check?agent=name
For standalone abuse checking without the full middleware, use kya-abuse-check.
Part of KYA (Know Your Agent)
mcp-trust-guard is the server-side component of KYA — real-time AI agent verification. Six checks: Deployer, Model, Code, Abuse, Permissions, Deployment. No platform registration required.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。