mcp-guardian
Scans MCP tool descriptions for prompt injection attacks, including cross-tool instructions, privilege escalation, and data exfiltration patterns. It can be used as a CLI scanner or integrated as an MCP server itself.
README
mcp-guardian
MCP security scanner that detects prompt injection attacks in tool descriptions.
What It Detects
- Cross-tool instructions - Attempts to chain tool calls ("before using this tool", "first call", "you must execute")
- Privilege escalation - Attempts to override safety ("ignore previous instructions", "you are now", "bypass security")
- Data exfiltration - Attempts to send data externally (URLs, "send to", "upload to")
- Stealth directives - Hidden instructions in descriptions
- Sensitive path access - References to ~/.ssh, ~/.aws, credentials, etc.
- Encoded content - Base64, unicode escapes, hex encoding (potential obfuscation)
Installation
npm install mcp-guardian
Usage
CLI - Scan MCP Config
# Auto-detect Claude Desktop config
npx mcp-guardian
# Explicit config path
npx mcp-guardian /path/to/claude_desktop_config.json
# JSON output
npx mcp-guardian --json
CLI - Run as MCP Server
npx mcp-guardian --mcp
Claude Desktop Integration
Add to your claude_desktop_config.json:
{
"mcpServers": {
"mcp-guardian": {
"command": "npx",
"args": ["-y", "mcp-guardian", "--mcp"]
}
}
}
Library Usage
import {
scanToolDescription,
scanToolDefinitions,
isDescriptionSafe,
verifyToolDefinitions,
} from "mcp-guardian";
// Scan a single tool description
const result = scanToolDescription("my_tool", "Tool description here");
if (result.status === "critical") {
console.error("Potential injection:", result.issues);
}
// Quick safety check
if (!isDescriptionSafe("Before using this tool, first call...")) {
console.warn("Suspicious description detected");
}
// Scan multiple tools
const tools = [
{ name: "tool1", description: "...", schema: {} },
{ name: "tool2", description: "...", schema: {} },
];
const serverResult = scanToolDefinitions(tools, "my-server");
// Tool pinning - detect changes
const pinResult = verifyToolDefinitions(tools);
if (pinResult.status === "changed") {
console.warn("Tool definitions changed:", pinResult.changedTools);
}
Demo
Try mcp-guardian instantly with built-in poisoned tool examples:
npx mcp-guardian demo
This scans hardcoded examples demonstrating real attack patterns — no config file needed.
Expected output:
✅ filesystem (14 tools)
✅ memory (9 tools)
🔴 suspicious-tool (4 tools)
└─ add: sensitive_path (~/.ssh)
└─ format_text: privilege_escalation ("You are now")
└─ search_docs: exfiltration (evil URL), sensitive_path (~/.aws/credentials)
Summary:
📊 Total tools: 27
✅ Clean: 2
⚠️ Warning: 0
🚨 Critical: 1
The poisoned server demonstrates real attack patterns from published security research. See examples/poisoned-server/README.md for details.
Detection Patterns
Critical Severity (38 patterns)
| Category | Examples |
|---|---|
| Cross-tool instruction | "before using this tool", "first call", "then execute", "always call" |
| Privilege escalation | "ignore previous instructions", "override system", "you are now" |
| Exfiltration | URLs, "send to", "post to", "forward to", "upload to" |
Warning Severity (13 patterns)
| Category | Examples |
|---|---|
| Sensitive paths | ~/.ssh, ~/.aws, /etc/passwd, .env, api_key |
| Encoded content | Base64 strings, unicode escapes, hex encoding |
Pre-commit Integration
Using pre-commit framework
Add to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/alexandriashai/mcp-guardian
rev: v1.2.2
hooks:
- id: mcp-guardian
Using Husky
Add to .husky/pre-commit:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx mcp-guardian --sync --quiet
Using Lefthook
Add to lefthook.yml:
pre-commit:
commands:
mcp-guardian:
glob: "claude_desktop_config.json"
run: npx mcp-guardian --sync {staged_files}
Tool Pinning
MCP Guardian includes tool definition pinning - SHA-256 hashing of tool definitions to detect tampering:
import { verifyToolDefinitions, approveAllTools } from "mcp-guardian";
// Verify tools against stored baseline
const result = verifyToolDefinitions(tools);
// Status: "created" | "verified" | "changed" | "error"
if (result.status === "changed") {
console.log("Modified tools:", result.changedTools);
console.log("New tools:", result.newTools);
console.log("Removed tools:", result.removedTools);
}
// Re-approve all tools (after review)
approveAllTools(tools);
Manifests are stored in ~/.mcp-guardian/tool-manifest.json.
Research References
This tool is informed by MCP security research from:
- Invariant Labs - MCP Security Research
- Microsoft - Prompt Injection Attacks
- Palo Alto Unit 42 - AI Security
- Simon Willison - Prompt Injection
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 模型以安全和受控的方式获取实时的网络信息。