getarcis/arcis-example-mcp
GitHub: getarcis/arcis-example-mcp
Arcis 提示词注入检测器的最小化演示项目,展示 V32-V34 检测器如何捕获针对 AI agent 工具调用管道的提示词注入攻击。
Stars: 0 | Forks: 0
[](https://github.com/getarcis/arcis-example-mcp/actions/workflows/ci.yml)
# arcis-example-mcp
## 这是什么
这是一个最小化的演示,展示了 Arcis 的 V32 agent-toolcall-injection 检测器(在 v1.6.0 版本中发布)以及较旧的 DAN / `` 标签越狱签名,所有这些都通过 `@arcis/node` 中的 `detectPromptInjection` 运行。
这与 [`@arcis/mcp`](https://www.npmjs.com/package/@arcis/mcp) 服务器作为 `arcis_detect_prompt_injection` MCP 工具暴露的函数相同。任何兼容 MCP 的 AI agent(Cursor 或任何其他 MCP 客户端)都可以在将结果转发给模型之前,对每个工具调用的结果调用它。
文件:
- [`demo.js`](./demo.js):9 个 payload(2 个安全的,5 个 V32 工具调用注入,2 个经典越狱)。通过 `detectPromptInjection` 运行每一个,并报告哪些被捕获。
总依赖:`@arcis/node`。没有其他依赖。
## 运行它
```
npm install
npm run demo
```
预期输出:
```
Arcis prompt-injection demo against detectPromptInjection
------------------------------------------------------------------------
OK safe plain tool result: clean (passed through, as expected)
OK safe JSON tool result: clean (passed through, as expected)
BLOCK v32 agent-toolcall-marker: caught (rule=agent-toolcall-marker, severity=high)
BLOCK v32 agent-tool-name-spoof: caught (rule=agent-tool-name-spoof, severity=high)
BLOCK v32 agent-tool-result-marker: caught (rule=agent-tool-result-marker, severity=high)
BLOCK v32 ansi-escape-sequence: caught (rule=ignore-previous-instructions, severity=high)
BLOCK v32 claude-tool-use-tags: caught (rule=claude-tool-use-tags, severity=high)
BLOCK classic fake-system-tag: caught (rule=ignore-previous-instructions, severity=high)
BLOCK classic DAN jailbreak: caught (rule=jailbreak-dan, severity=high)
------------------------------------------------------------------------
7 injections caught, 2 safe calls passed, 0 unexpected
```
(ANSI-escape 和 fake-system-tag payload 也会触发旧签名库中的 `ignore-previous-instructions` —— 检测器会报告严重程度最高的匹配项。这两条规则都会在这些 payload 上触发。)
## V32 工具调用注入 — 它能捕获什么
Arcis v1.6.0 中发布了五个新模式,专门针对 AI agent 运行时,在这种环境下,一个被攻陷的工具结果可能会影响整个会话:
| 规则 | 捕获内容 |
|---|---|
| `agent-toolcall-marker` | 模仿工具调用 JSON 结构的字符串:`{"tool_call": ...}`, `{"function_call": ...}`, `{"call_tool": ...}` |
| `agent-tool-name-spoof` | 针对危险原语(如 `exec`, `shell`, `run_command`, `eval`, `read_file`, `write_file`, `delete_file`)的工具名称字符串 |
| `agent-tool-result-marker` | 模仿工具结果 JSON 结构的字符串:`{"tool_result": ...}`, `{"tool_output": ...}` |
| `ansi-escape-sequence` | 工具输出中的 ANSI 控制序列。用于终端清除注入(`\x1b[2J\x1b[H...`),通过在视觉上重写之前的上下文来改变对话走向 |
| `claude-tool-use-tags` | 像 ``, ``, `` 这样的标签式调用,一些 agent 运行时在回显时会直接执行它们 |
## AI agent 在生产环境中如何使用它
```
import { detectPromptInjection } from '@arcis/node';
async function runToolAndForward(toolName, toolArgs) {
const result = await callTool(toolName, toolArgs);
const finding = detectPromptInjection(result);
if (finding) {
return {
role: 'tool',
name: toolName,
content: `[Arcis blocked: ${finding.rule}]`,
};
}
return { role: 'tool', name: toolName, content: result };
}
```
MCP 形式([`@arcis/mcp`](https://www.npmjs.com/package/@arcis/mcp))封装了与 `arcis_detect_prompt_injection` 工具相同的逻辑,因此支持 MCP 的 agent 可以像调用任何其他已注册工具一样调用它。
## 姊妹示例
| 框架 | 仓库 |
|---|---|
| Express | [`arcis-example-express`](https://github.com/getarcis/arcis-example-express) |
| FastAPI | [`arcis-example-fastapi`](https://github.com/getarcis/arcis-example-fastapi) |
| Gin (Go) | [`arcis-example-gin`](https://github.com/getarcis/arcis-example-gin) |
| Bun + Hono | [`arcis-example-bun`](https://github.com/getarcis/arcis-example-bun) |
| NestJS | [`arcis-example-nestjs`](https://github.com/getarcis/arcis-example-nestjs) |
| Next.js | [`arcis-example-nextjs`](https://github.com/getarcis/arcis-example-nextjs) |
## 许可证
MIT。
标签:AI安全, Chat Copilot, GNU通用公共许可证, LLM应用防火墙, MCP, MITM代理, Node.js, TLS, 数据可视化, 暗色界面, 自定义脚本, 防御工具