@reaatech/pi-bench-mcp-server 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +228 -0
- package/dist/index.cjs +797 -0
- package/dist/index.d.cts +146 -0
- package/dist/index.d.ts +146 -0
- package/dist/index.js +770 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 prompt-injection-bench contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# @reaatech/pi-bench-mcp-server
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@reaatech/pi-bench-mcp-server)
|
|
4
|
+
[](https://github.com/reaatech/prompt-injection-bench/blob/main/LICENSE)
|
|
5
|
+
[](https://github.com/reaatech/prompt-injection-bench/actions/workflows/ci.yml)
|
|
6
|
+
|
|
7
|
+
> **Status:** Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.
|
|
8
|
+
|
|
9
|
+
MCP (Model Context Protocol) server for prompt-injection-bench, plus report data normalization and deterministic reproducibility tools. Exposes benchmark operations as MCP tools consumable by any MCP client.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @reaatech/pi-bench-mcp-server
|
|
15
|
+
# or
|
|
16
|
+
pnpm add @reaatech/pi-bench-mcp-server
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Feature Overview
|
|
20
|
+
|
|
21
|
+
- **4 MCP tools** — `run_benchmark`, `compare_defenses`, `generate_report`, `submit_results`
|
|
22
|
+
- **Stdio transport** — Connect to any MCP-compatible client via standard I/O
|
|
23
|
+
- **Report generation** — HTML and Markdown reports with category breakdowns
|
|
24
|
+
- **Path traversal protection** — Validates all file paths in tool operations
|
|
25
|
+
- **Deterministic seed manager** — LCG-based PRNG with SHA-256 proof hashes for reproducible benchmarks
|
|
26
|
+
- **Dual ESM/CJS output** — works with `import` and `require`
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { createMCPServer } from "@reaatech/pi-bench-mcp-server";
|
|
32
|
+
|
|
33
|
+
const server = createMCPServer();
|
|
34
|
+
await server.start();
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Or connect via MCP client configuration:
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"mcpServers": {
|
|
42
|
+
"prompt-injection-bench": {
|
|
43
|
+
"command": "npx",
|
|
44
|
+
"args": ["@reaatech/pi-bench-mcp-server"]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API Reference
|
|
51
|
+
|
|
52
|
+
### BenchmarkMCPServer
|
|
53
|
+
|
|
54
|
+
| Method | Description |
|
|
55
|
+
|--------|-------------|
|
|
56
|
+
| `start()` | Start the MCP server on stdio transport |
|
|
57
|
+
| `stop()` | Stop the server |
|
|
58
|
+
|
|
59
|
+
#### `createMCPServer(config?)`
|
|
60
|
+
|
|
61
|
+
Factory function.
|
|
62
|
+
|
|
63
|
+
#### MCP Tools
|
|
64
|
+
|
|
65
|
+
##### `run_benchmark`
|
|
66
|
+
|
|
67
|
+
Execute a full benchmark against a defense:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"name": "run_benchmark",
|
|
72
|
+
"arguments": {
|
|
73
|
+
"defense": "rebuff",
|
|
74
|
+
"corpus": "default",
|
|
75
|
+
"categories": ["direct-injection", "prompt-leaking", "role-playing"],
|
|
76
|
+
"parallel": 10,
|
|
77
|
+
"timeout_ms": 30000
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
##### `compare_defenses`
|
|
83
|
+
|
|
84
|
+
Compare multiple defense results:
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"name": "compare_defenses",
|
|
89
|
+
"arguments": {
|
|
90
|
+
"results": ["results/rebuff.json", "results/lakera.json"],
|
|
91
|
+
"significance_level": 0.05
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
##### `generate_report`
|
|
97
|
+
|
|
98
|
+
Generate HTML/JSON/Markdown reports:
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"name": "generate_report",
|
|
103
|
+
"arguments": {
|
|
104
|
+
"results": "results/latest.json",
|
|
105
|
+
"format": "html",
|
|
106
|
+
"include_categories": true,
|
|
107
|
+
"output": "reports/benchmark-report.html"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
##### `submit_results`
|
|
113
|
+
|
|
114
|
+
Submit results to the public leaderboard:
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"name": "submit_results",
|
|
119
|
+
"arguments": {
|
|
120
|
+
"results": "results/latest.json",
|
|
121
|
+
"defense_name": "my-custom-defense",
|
|
122
|
+
"defense_version": "1.0.0",
|
|
123
|
+
"reproducibility_proof": {
|
|
124
|
+
"seed": "abc123",
|
|
125
|
+
"corpus_version": "2026.04",
|
|
126
|
+
"adapter_versions": { "rebuff": "1.2.0" }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Report Data Normalization
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { normalizeReportData } from "@reaatech/pi-bench-mcp-server";
|
|
136
|
+
|
|
137
|
+
const data = normalizeReportData(rawResults);
|
|
138
|
+
// Returns normalized { defense, score, overallMetrics } regardless of input format
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`normalizeReportData` accepts multiple result formats:
|
|
142
|
+
- Full `BenchmarkResult` objects
|
|
143
|
+
- Pre-computed `DefenseScore` objects
|
|
144
|
+
- JSON file paths (auto-reads and parses)
|
|
145
|
+
- Mixed arrays of any of the above
|
|
146
|
+
|
|
147
|
+
### SeedManager
|
|
148
|
+
|
|
149
|
+
Deterministic PRNG for reproducible benchmarks:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { createSeedManager } from "@reaatech/pi-bench-mcp-server";
|
|
153
|
+
|
|
154
|
+
const seed = createSeedManager({ seed: "my-benchmark-v1" });
|
|
155
|
+
|
|
156
|
+
const nextInt = seed.nextInt(1, 1000);
|
|
157
|
+
const shuffled = seed.shuffle(samples);
|
|
158
|
+
const proofHash = seed.generateProof(corpusVersion, adapterVersions);
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
| Method | Description |
|
|
162
|
+
|--------|-------------|
|
|
163
|
+
| `next()` | Next float in [0, 1) |
|
|
164
|
+
| `nextInt(min, max)` | Next integer in [min, max] |
|
|
165
|
+
| `shuffle(array)` | Deterministic Fisher-Yates shuffle |
|
|
166
|
+
| `generateProof(corpusVersion, adapterVersions)` | SHA-256 proof hash |
|
|
167
|
+
| `reset()` | Reset to initial seed |
|
|
168
|
+
|
|
169
|
+
#### `createSeedManager(config?)`
|
|
170
|
+
|
|
171
|
+
Factory function. Accepts optional `SeedConfig` with `seed` (string) and `algorithm` (default: `"lcg"`).
|
|
172
|
+
|
|
173
|
+
## Usage Patterns
|
|
174
|
+
|
|
175
|
+
### MCP Tool Invocation from an Agent
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
// From an MCP client (e.g., Claude Desktop, agent-mesh):
|
|
179
|
+
const result = await mcpClient.callTool("run_benchmark", {
|
|
180
|
+
defense: "mock",
|
|
181
|
+
corpus: "default",
|
|
182
|
+
categories: ["direct-injection", "role-playing"],
|
|
183
|
+
parallel: 10,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
console.log(`Defense: ${result.defense}`);
|
|
187
|
+
console.log(`Detection rate: ${result.detectionRate}`);
|
|
188
|
+
console.log(`Score: ${result.overallScore}`);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Generating Reports Programmatically
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { normalizeReportData } from "@reaatech/pi-bench-mcp-server";
|
|
195
|
+
|
|
196
|
+
const data = normalizeReportData("results/benchmark.json");
|
|
197
|
+
|
|
198
|
+
// Build a Markdown report
|
|
199
|
+
let md = `# Benchmark Report\n\n`;
|
|
200
|
+
md += `**Defense:** ${data.defense}\n`;
|
|
201
|
+
md += `**Overall Score:** ${data.score.overallScore.toFixed(3)}\n`;
|
|
202
|
+
md += `**Detection Rate:** ${(1 - data.score.attackSuccessRate) * 100}%\n`;
|
|
203
|
+
|
|
204
|
+
for (const [category, catData] of Object.entries(data.score.categoryScores)) {
|
|
205
|
+
md += `- **${category}:** ${(catData.detectionRate * 100).toFixed(1)}%\n`;
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Reproducible Runs
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
const seed = createSeedManager({ seed: "my-benchmark-v1" });
|
|
213
|
+
|
|
214
|
+
// Use seed for deterministic corpus generation and result ordering
|
|
215
|
+
const shuffled = seed.shuffle(corpus);
|
|
216
|
+
const proof = seed.generateProof("2026.04", { mock: "1.0.0" });
|
|
217
|
+
console.log(`Reproducibility proof: ${proof}`);
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Related Packages
|
|
221
|
+
|
|
222
|
+
- [`@reaatech/pi-bench-runner`](https://www.npmjs.com/package/@reaatech/pi-bench-runner) — Benchmark execution engine
|
|
223
|
+
- [`@reaatech/pi-bench-leaderboard`](https://www.npmjs.com/package/@reaatech/pi-bench-leaderboard) — Leaderboard management
|
|
224
|
+
- [`prompt-injection-bench`](https://www.npmjs.com/package/prompt-injection-bench) — CLI and umbrella package
|
|
225
|
+
|
|
226
|
+
## License
|
|
227
|
+
|
|
228
|
+
[MIT](https://github.com/reaatech/prompt-injection-bench/blob/main/LICENSE)
|