@eyeoverthink/sva-gate 2.1.0 → 2.1.2
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 +201 -201
- package/README.md +221 -157
- package/bin/sva-gate.js +172 -172
- package/package.json +80 -79
- package/src/index.d.ts +142 -142
- package/src/index.js +49 -49
- package/src/lib/binder-induction.d.ts +17 -17
- package/src/lib/binder-induction.js +267 -267
- package/src/lib/membrane-core.js +156 -156
- package/src/lib/sentinel.js +103 -103
- package/src/lib/stream-guard.js +228 -228
- package/src/mcp-server.js +273 -273
- package/src/receipt.js +412 -412
- package/test/review-2026-12-04.test.js +84 -84
- package/test/sva-gate.test.js +268 -268
- package/test/trust.test.js +88 -88
- package/test/types.test.js +31 -31
package/src/mcp-server.js
CHANGED
|
@@ -1,273 +1,273 @@
|
|
|
1
|
-
// Zero-dependency stdio JSON-RPC 2.0 MCP Server for @eyeoverthink/sva-gate.
|
|
2
|
-
// Exposes 6 deterministic verification tools spanning all 3 SVA layers:
|
|
3
|
-
// 1. sva_seal_text (EMA/1 privacy membrane + StreamSealGuard + injection scan)
|
|
4
|
-
// 2. sva_mint_receipt (SVA-ER/1 Ed25519 + RFC 6962 Merkle receipt & OPEG/1 envelope)
|
|
5
|
-
// 3. sva_verify_receipt (SVA-ER/1 & AER-1 v0.4 verifier; AER-1 = individual Internet-Draft draft-zambo-aer1-26)
|
|
6
|
-
// 4. sva_opeg_check (OPEG/1 S4_COMMIT fail-closed execution gate)
|
|
7
|
-
// 5. sva_judge_audit (SVA-JEV/1 calibrated epistemic judge & planted-fake gate)
|
|
8
|
-
// 6. sva_crystallize_skill (VSC/1 zero-LLM binder induction + leave-one-out check)
|
|
9
|
-
|
|
10
|
-
import readline from 'node:readline';
|
|
11
|
-
import fs from 'node:fs';
|
|
12
|
-
import { mintSvaEr1, verifyAnyReceipt, evaluateOpeg1 } from './receipt.js';
|
|
13
|
-
import { detect, SealSession, StreamSealGuard, scanInjection } from './membrane.js';
|
|
14
|
-
import { evaluateSvaJev1 } from './lib/judge-verify.js';
|
|
15
|
-
import { induce, leaveOneOut, explainApply, novelWording } from './lib/binder-induction.js';
|
|
16
|
-
|
|
17
|
-
// Read from package.json so serverInfo never drifts from the published version (it said 2.0.0 in 2.0.2).
|
|
18
|
-
const PKG_VERSION = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
19
|
-
|
|
20
|
-
export const SERVER_INFO = {
|
|
21
|
-
name: '@eyeoverthink/sva-gate',
|
|
22
|
-
version: PKG_VERSION,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const MCP_TOOLS = [
|
|
26
|
-
{
|
|
27
|
-
name: 'sva_seal_text',
|
|
28
|
-
description: 'Seal PII and secrets (emails, SSNs, API keys, phones) into typed placeholders with zero-leak audit and prompt-injection scan. Optionally pass chunks[] to run StreamSealGuard across token boundaries.',
|
|
29
|
-
inputSchema: {
|
|
30
|
-
type: 'object',
|
|
31
|
-
properties: {
|
|
32
|
-
text: { type: 'string', description: 'Plain text to seal before cloud egress.' },
|
|
33
|
-
chunks: { type: 'array', items: { type: 'string' }, description: 'Optional streaming token chunks to seal via StreamSealGuard.' },
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
name: 'sva_mint_receipt',
|
|
39
|
-
description: 'Mint an Ed25519-signed, RFC 6962 Merkle-proven SVA-ER/1 execution receipt and matching OPEG/1 S4_COMMIT envelope for a sanitized JSON result object (rSan).',
|
|
40
|
-
inputSchema: {
|
|
41
|
-
type: 'object',
|
|
42
|
-
required: ['rSan'],
|
|
43
|
-
properties: {
|
|
44
|
-
rSan: { type: 'object', description: 'Sanitized result object to bind cryptographically.' },
|
|
45
|
-
missionId: { type: 'string', description: 'Optional mission identifier.' },
|
|
46
|
-
agencyName: { type: 'string', description: 'Optional agency/issuer display name.' },
|
|
47
|
-
clockStatus: { type: 'string', enum: ['attested', 'drift', 'unattested'], description: 'Explicit clock honesty state (default: unattested).' },
|
|
48
|
-
seedHex: { type: 'string', description: 'Optional 64-hex-char Ed25519 signing seed (ephemeral key generated if omitted).' },
|
|
49
|
-
events: { type: 'array', items: { type: 'object' }, description: 'Optional execution log events to include in the Merkle tree.' },
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
name: 'sva_verify_receipt',
|
|
55
|
-
description: 'Verify an SVA-ER/1 receipt (Ed25519 + RFC 6962 Merkle + deliverable digest + RFC 3339 clock) OR an AER-1 v0.4 receipt (individual Internet-Draft draft-zambo-aer1-26) offline. AER-1 receipts carry no issuer signature and are reported as integrity_only.',
|
|
56
|
-
inputSchema: {
|
|
57
|
-
type: 'object',
|
|
58
|
-
required: ['receipt'],
|
|
59
|
-
properties: {
|
|
60
|
-
receipt: { type: 'object', description: 'SVA-ER/1 or AER-1 v0.4 receipt JSON object.' },
|
|
61
|
-
deliverable: { description: 'Optional deliverable string or JSON object to verify against deliverableSha256 (SVA-ER/1) or the outputs (AER-1).' },
|
|
62
|
-
expectedPublicKeys: { type: 'array', items: { type: 'string' }, description: 'Hex Ed25519 key(s) allowed to have signed. Without them an intact receipt is reported as integrity_only (ok: false), because anyone can mint an intact receipt with their own key.' },
|
|
63
|
-
allowUnpinned: { type: 'boolean', description: 'Accept any signer (1.x behaviour). For demos and migration only; the result says trust: unpinned.' },
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
name: 'sva_opeg_check',
|
|
69
|
-
description: 'Evaluate an OPEG/1 S4_COMMIT gate envelope fail-closed. Blocks DIRECT_INFERENCE, tampered rSan payloads, and invalid SVA-ER/1 or AER-1 v0.4 receipts.',
|
|
70
|
-
inputSchema: {
|
|
71
|
-
type: 'object',
|
|
72
|
-
required: ['envelope'],
|
|
73
|
-
properties: {
|
|
74
|
-
envelope: { type: 'object', description: 'OPEG/1 S4_COMMIT envelope JSON object.' },
|
|
75
|
-
expectedPublicKeys: { type: 'array', items: { type: 'string' }, description: 'Hex Ed25519 key(s) allowed to have signed. Without them an intact receipt is reported as integrity_only (ok: false), because anyone can mint an intact receipt with their own key.' },
|
|
76
|
-
allowUnpinned: { type: 'boolean', description: 'Accept any signer (1.x behaviour). For demos and migration only; the result says trust: unpinned.' },
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
name: 'sva_judge_audit',
|
|
82
|
-
description: 'Evaluate an SVA-JEV/1 epistemic judge envelope (calibration Wilson 95% CI, independent JEV vote with author self-vote exclusion, verbatim >=12-char quote check, or planted-fake + zero-LLM new_terms claim trace).',
|
|
83
|
-
inputSchema: {
|
|
84
|
-
type: 'object',
|
|
85
|
-
required: ['envelope'],
|
|
86
|
-
properties: {
|
|
87
|
-
envelope: { type: 'object', description: 'SVA-JEV/1 envelope with spec="sva-jev/1", semantics="stability-signal-not-correctness", and mode.' },
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
name: 'sva_crystallize_skill',
|
|
93
|
-
description: 'Induce a zero-LLM deterministic parameter binder from positive/negative examples, check leave-one-out accuracy, and optionally test binding against a new task string.',
|
|
94
|
-
inputSchema: {
|
|
95
|
-
type: 'object',
|
|
96
|
-
required: ['examples'],
|
|
97
|
-
properties: {
|
|
98
|
-
examples: {
|
|
99
|
-
type: 'array',
|
|
100
|
-
items: {
|
|
101
|
-
type: 'object',
|
|
102
|
-
required: ['task', 'input'],
|
|
103
|
-
properties: {
|
|
104
|
-
task: { type: 'string' },
|
|
105
|
-
input: { type: 'object' },
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
description: 'Array of solved positive { task, input } examples.',
|
|
109
|
-
},
|
|
110
|
-
negatives: {
|
|
111
|
-
type: 'array',
|
|
112
|
-
items: { type: 'object', properties: { task: { type: 'string' } } },
|
|
113
|
-
description: 'Optional refused near-miss { task } counter-examples.',
|
|
114
|
-
},
|
|
115
|
-
skill: { type: 'object', description: 'Optional skill schema with params.properties metadata.' },
|
|
116
|
-
testTask: { type: 'string', description: 'Optional novel task string to test binder extraction and near-miss rejection.' },
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
];
|
|
121
|
-
|
|
122
|
-
function runTool(name, args = {}) {
|
|
123
|
-
switch (name) {
|
|
124
|
-
case 'sva_seal_text': {
|
|
125
|
-
if (Array.isArray(args.chunks) && args.chunks.length > 0) {
|
|
126
|
-
const sg = new StreamSealGuard();
|
|
127
|
-
const sealed = args.chunks.map((c) => sg.push(String(c))).join('') + sg.flush();
|
|
128
|
-
const fullRaw = args.chunks.map(String).join('');
|
|
129
|
-
return {
|
|
130
|
-
mode: 'stream',
|
|
131
|
-
sealed,
|
|
132
|
-
audit: sg.session.audit(sealed),
|
|
133
|
-
injection: scanInjection(fullRaw),
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
const text = String(args.text ?? '');
|
|
137
|
-
const findings = detect(text);
|
|
138
|
-
const session = new SealSession();
|
|
139
|
-
const sealed = session.apply(text, findings);
|
|
140
|
-
return {
|
|
141
|
-
mode: 'single',
|
|
142
|
-
sealed,
|
|
143
|
-
findingsCount: findings.length,
|
|
144
|
-
audit: session.audit(sealed),
|
|
145
|
-
injection: scanInjection(text),
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
case 'sva_mint_receipt': {
|
|
149
|
-
return mintSvaEr1({
|
|
150
|
-
rSan: args.rSan,
|
|
151
|
-
missionId: args.missionId,
|
|
152
|
-
agencyName: args.agencyName,
|
|
153
|
-
clockStatus: args.clockStatus || 'unattested',
|
|
154
|
-
seedHex: args.seedHex || null,
|
|
155
|
-
events: Array.isArray(args.events) ? args.events : [],
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
case 'sva_verify_receipt': {
|
|
159
|
-
return verifyAnyReceipt(args.receipt, { deliverable: args.deliverable ?? null, expectedPublicKeys: args.expectedPublicKeys ?? null, allowUnpinned: args.allowUnpinned === true });
|
|
160
|
-
}
|
|
161
|
-
case 'sva_opeg_check': {
|
|
162
|
-
return evaluateOpeg1(args.envelope, { expectedPublicKeys: args.expectedPublicKeys ?? null, allowUnpinned: args.allowUnpinned === true });
|
|
163
|
-
}
|
|
164
|
-
case 'sva_judge_audit': {
|
|
165
|
-
return evaluateSvaJev1(args.envelope);
|
|
166
|
-
}
|
|
167
|
-
case 'sva_crystallize_skill': {
|
|
168
|
-
const pos = (Array.isArray(args.examples) ? args.examples : []).map((e) => ({
|
|
169
|
-
task: e.task,
|
|
170
|
-
input: e.input ?? e.params,
|
|
171
|
-
}));
|
|
172
|
-
const neg = Array.isArray(args.negatives) ? args.negatives : [];
|
|
173
|
-
const skill = args.skill && typeof args.skill === 'object' ? args.skill : { params: { properties: {} } };
|
|
174
|
-
const induced = induce(pos, neg, skill);
|
|
175
|
-
const spec = induced?.spec || null;
|
|
176
|
-
const looRows = spec ? leaveOneOut(pos, neg, skill) : [];
|
|
177
|
-
const looPassed = looRows.filter((r) => r.ok).length;
|
|
178
|
-
const loo = { passed: looPassed, total: looRows.length, ok: looRows.length > 0 && looPassed === looRows.length };
|
|
179
|
-
const out = { induced: Boolean(spec), error: induced?.error ?? null, leaveOneOut: loo, spec };
|
|
180
|
-
if (spec && typeof args.testTask === 'string') {
|
|
181
|
-
const { input: bound, refused, detail } = explainApply(spec, args.testTask);
|
|
182
|
-
const novel = novelWording(pos, args.testTask);
|
|
183
|
-
out.testResult = {
|
|
184
|
-
routed: Boolean(bound && novel.length === 0),
|
|
185
|
-
novelWordingRejected: novel.length > 0 || !bound,
|
|
186
|
-
novelWords: novel,
|
|
187
|
-
refused: refused ? { reason: refused, detail } : null,
|
|
188
|
-
bound,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
return out;
|
|
192
|
-
}
|
|
193
|
-
default:
|
|
194
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export function createMcpHandler() {
|
|
199
|
-
return function handleRequest(msg) {
|
|
200
|
-
if (!msg || typeof msg !== 'object' || msg.jsonrpc !== '2.0') {
|
|
201
|
-
return { jsonrpc: '2.0', id: null, error: { code: -32600, message: 'Invalid JSON-RPC 2.0 request' } };
|
|
202
|
-
}
|
|
203
|
-
const { id, method, params } = msg;
|
|
204
|
-
// Notifications have no id and expect no response
|
|
205
|
-
if (id === undefined) return null;
|
|
206
|
-
|
|
207
|
-
try {
|
|
208
|
-
if (method === 'initialize') {
|
|
209
|
-
const protocolVersion = typeof params?.protocolVersion === 'string' ? params.protocolVersion : '2025-03-26';
|
|
210
|
-
return {
|
|
211
|
-
jsonrpc: '2.0',
|
|
212
|
-
id,
|
|
213
|
-
result: {
|
|
214
|
-
protocolVersion,
|
|
215
|
-
capabilities: { tools: {} },
|
|
216
|
-
serverInfo: SERVER_INFO,
|
|
217
|
-
},
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
if (method === 'ping') {
|
|
221
|
-
return { jsonrpc: '2.0', id, result: {} };
|
|
222
|
-
}
|
|
223
|
-
if (method === 'tools/list') {
|
|
224
|
-
return { jsonrpc: '2.0', id, result: { tools: MCP_TOOLS } };
|
|
225
|
-
}
|
|
226
|
-
if (method === 'tools/call') {
|
|
227
|
-
const toolName = params?.name;
|
|
228
|
-
const toolArgs = params?.arguments || {};
|
|
229
|
-
const data = runTool(toolName, toolArgs);
|
|
230
|
-
return {
|
|
231
|
-
jsonrpc: '2.0',
|
|
232
|
-
id,
|
|
233
|
-
result: {
|
|
234
|
-
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
235
|
-
structuredContent: data,
|
|
236
|
-
isError: false,
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
return { jsonrpc: '2.0', id, error: { code: -32601, message: `Method not found: ${method}` } };
|
|
241
|
-
} catch (err) {
|
|
242
|
-
return {
|
|
243
|
-
jsonrpc: '2.0',
|
|
244
|
-
id,
|
|
245
|
-
result: {
|
|
246
|
-
content: [{ type: 'text', text: JSON.stringify({ error: err.message }) }],
|
|
247
|
-
isError: true,
|
|
248
|
-
},
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export function startStdioMcpServer(input = process.stdin, output = process.stdout) {
|
|
255
|
-
const handle = createMcpHandler();
|
|
256
|
-
const rl = readline.createInterface({ input, crlfDelay: Infinity });
|
|
257
|
-
rl.on('line', (line) => {
|
|
258
|
-
const trimmed = line.trim();
|
|
259
|
-
if (!trimmed) return;
|
|
260
|
-
let parsed;
|
|
261
|
-
try {
|
|
262
|
-
parsed = JSON.parse(trimmed);
|
|
263
|
-
} catch {
|
|
264
|
-
output.write(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } }) + '\n');
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
const resp = handle(parsed);
|
|
268
|
-
if (resp !== null) {
|
|
269
|
-
output.write(JSON.stringify(resp) + '\n');
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
return rl;
|
|
273
|
-
}
|
|
1
|
+
// Zero-dependency stdio JSON-RPC 2.0 MCP Server for @eyeoverthink/sva-gate.
|
|
2
|
+
// Exposes 6 deterministic verification tools spanning all 3 SVA layers:
|
|
3
|
+
// 1. sva_seal_text (EMA/1 privacy membrane + StreamSealGuard + injection scan)
|
|
4
|
+
// 2. sva_mint_receipt (SVA-ER/1 Ed25519 + RFC 6962 Merkle receipt & OPEG/1 envelope)
|
|
5
|
+
// 3. sva_verify_receipt (SVA-ER/1 & AER-1 v0.4 verifier; AER-1 = individual Internet-Draft draft-zambo-aer1-26)
|
|
6
|
+
// 4. sva_opeg_check (OPEG/1 S4_COMMIT fail-closed execution gate)
|
|
7
|
+
// 5. sva_judge_audit (SVA-JEV/1 calibrated epistemic judge & planted-fake gate)
|
|
8
|
+
// 6. sva_crystallize_skill (VSC/1 zero-LLM binder induction + leave-one-out check)
|
|
9
|
+
|
|
10
|
+
import readline from 'node:readline';
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import { mintSvaEr1, verifyAnyReceipt, evaluateOpeg1 } from './receipt.js';
|
|
13
|
+
import { detect, SealSession, StreamSealGuard, scanInjection } from './membrane.js';
|
|
14
|
+
import { evaluateSvaJev1 } from './lib/judge-verify.js';
|
|
15
|
+
import { induce, leaveOneOut, explainApply, novelWording } from './lib/binder-induction.js';
|
|
16
|
+
|
|
17
|
+
// Read from package.json so serverInfo never drifts from the published version (it said 2.0.0 in 2.0.2).
|
|
18
|
+
const PKG_VERSION = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
19
|
+
|
|
20
|
+
export const SERVER_INFO = {
|
|
21
|
+
name: '@eyeoverthink/sva-gate',
|
|
22
|
+
version: PKG_VERSION,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const MCP_TOOLS = [
|
|
26
|
+
{
|
|
27
|
+
name: 'sva_seal_text',
|
|
28
|
+
description: 'Seal PII and secrets (emails, SSNs, API keys, phones) into typed placeholders with zero-leak audit and prompt-injection scan. Optionally pass chunks[] to run StreamSealGuard across token boundaries.',
|
|
29
|
+
inputSchema: {
|
|
30
|
+
type: 'object',
|
|
31
|
+
properties: {
|
|
32
|
+
text: { type: 'string', description: 'Plain text to seal before cloud egress.' },
|
|
33
|
+
chunks: { type: 'array', items: { type: 'string' }, description: 'Optional streaming token chunks to seal via StreamSealGuard.' },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'sva_mint_receipt',
|
|
39
|
+
description: 'Mint an Ed25519-signed, RFC 6962 Merkle-proven SVA-ER/1 execution receipt and matching OPEG/1 S4_COMMIT envelope for a sanitized JSON result object (rSan).',
|
|
40
|
+
inputSchema: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
required: ['rSan'],
|
|
43
|
+
properties: {
|
|
44
|
+
rSan: { type: 'object', description: 'Sanitized result object to bind cryptographically.' },
|
|
45
|
+
missionId: { type: 'string', description: 'Optional mission identifier.' },
|
|
46
|
+
agencyName: { type: 'string', description: 'Optional agency/issuer display name.' },
|
|
47
|
+
clockStatus: { type: 'string', enum: ['attested', 'drift', 'unattested'], description: 'Explicit clock honesty state (default: unattested).' },
|
|
48
|
+
seedHex: { type: 'string', description: 'Optional 64-hex-char Ed25519 signing seed (ephemeral key generated if omitted).' },
|
|
49
|
+
events: { type: 'array', items: { type: 'object' }, description: 'Optional execution log events to include in the Merkle tree.' },
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'sva_verify_receipt',
|
|
55
|
+
description: 'Verify an SVA-ER/1 receipt (Ed25519 + RFC 6962 Merkle + deliverable digest + RFC 3339 clock) OR an AER-1 v0.4 receipt (individual Internet-Draft draft-zambo-aer1-26) offline. AER-1 receipts carry no issuer signature and are reported as integrity_only.',
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: 'object',
|
|
58
|
+
required: ['receipt'],
|
|
59
|
+
properties: {
|
|
60
|
+
receipt: { type: 'object', description: 'SVA-ER/1 or AER-1 v0.4 receipt JSON object.' },
|
|
61
|
+
deliverable: { description: 'Optional deliverable string or JSON object to verify against deliverableSha256 (SVA-ER/1) or the outputs (AER-1).' },
|
|
62
|
+
expectedPublicKeys: { type: 'array', items: { type: 'string' }, description: 'Hex Ed25519 key(s) allowed to have signed. Without them an intact receipt is reported as integrity_only (ok: false), because anyone can mint an intact receipt with their own key.' },
|
|
63
|
+
allowUnpinned: { type: 'boolean', description: 'Accept any signer (1.x behaviour). For demos and migration only; the result says trust: unpinned.' },
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'sva_opeg_check',
|
|
69
|
+
description: 'Evaluate an OPEG/1 S4_COMMIT gate envelope fail-closed. Blocks DIRECT_INFERENCE, tampered rSan payloads, and invalid SVA-ER/1 or AER-1 v0.4 receipts.',
|
|
70
|
+
inputSchema: {
|
|
71
|
+
type: 'object',
|
|
72
|
+
required: ['envelope'],
|
|
73
|
+
properties: {
|
|
74
|
+
envelope: { type: 'object', description: 'OPEG/1 S4_COMMIT envelope JSON object.' },
|
|
75
|
+
expectedPublicKeys: { type: 'array', items: { type: 'string' }, description: 'Hex Ed25519 key(s) allowed to have signed. Without them an intact receipt is reported as integrity_only (ok: false), because anyone can mint an intact receipt with their own key.' },
|
|
76
|
+
allowUnpinned: { type: 'boolean', description: 'Accept any signer (1.x behaviour). For demos and migration only; the result says trust: unpinned.' },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'sva_judge_audit',
|
|
82
|
+
description: 'Evaluate an SVA-JEV/1 epistemic judge envelope (calibration Wilson 95% CI, independent JEV vote with author self-vote exclusion, verbatim >=12-char quote check, or planted-fake + zero-LLM new_terms claim trace).',
|
|
83
|
+
inputSchema: {
|
|
84
|
+
type: 'object',
|
|
85
|
+
required: ['envelope'],
|
|
86
|
+
properties: {
|
|
87
|
+
envelope: { type: 'object', description: 'SVA-JEV/1 envelope with spec="sva-jev/1", semantics="stability-signal-not-correctness", and mode.' },
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'sva_crystallize_skill',
|
|
93
|
+
description: 'Induce a zero-LLM deterministic parameter binder from positive/negative examples, check leave-one-out accuracy, and optionally test binding against a new task string.',
|
|
94
|
+
inputSchema: {
|
|
95
|
+
type: 'object',
|
|
96
|
+
required: ['examples'],
|
|
97
|
+
properties: {
|
|
98
|
+
examples: {
|
|
99
|
+
type: 'array',
|
|
100
|
+
items: {
|
|
101
|
+
type: 'object',
|
|
102
|
+
required: ['task', 'input'],
|
|
103
|
+
properties: {
|
|
104
|
+
task: { type: 'string' },
|
|
105
|
+
input: { type: 'object' },
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
description: 'Array of solved positive { task, input } examples.',
|
|
109
|
+
},
|
|
110
|
+
negatives: {
|
|
111
|
+
type: 'array',
|
|
112
|
+
items: { type: 'object', properties: { task: { type: 'string' } } },
|
|
113
|
+
description: 'Optional refused near-miss { task } counter-examples.',
|
|
114
|
+
},
|
|
115
|
+
skill: { type: 'object', description: 'Optional skill schema with params.properties metadata.' },
|
|
116
|
+
testTask: { type: 'string', description: 'Optional novel task string to test binder extraction and near-miss rejection.' },
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
function runTool(name, args = {}) {
|
|
123
|
+
switch (name) {
|
|
124
|
+
case 'sva_seal_text': {
|
|
125
|
+
if (Array.isArray(args.chunks) && args.chunks.length > 0) {
|
|
126
|
+
const sg = new StreamSealGuard();
|
|
127
|
+
const sealed = args.chunks.map((c) => sg.push(String(c))).join('') + sg.flush();
|
|
128
|
+
const fullRaw = args.chunks.map(String).join('');
|
|
129
|
+
return {
|
|
130
|
+
mode: 'stream',
|
|
131
|
+
sealed,
|
|
132
|
+
audit: sg.session.audit(sealed),
|
|
133
|
+
injection: scanInjection(fullRaw),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const text = String(args.text ?? '');
|
|
137
|
+
const findings = detect(text);
|
|
138
|
+
const session = new SealSession();
|
|
139
|
+
const sealed = session.apply(text, findings);
|
|
140
|
+
return {
|
|
141
|
+
mode: 'single',
|
|
142
|
+
sealed,
|
|
143
|
+
findingsCount: findings.length,
|
|
144
|
+
audit: session.audit(sealed),
|
|
145
|
+
injection: scanInjection(text),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
case 'sva_mint_receipt': {
|
|
149
|
+
return mintSvaEr1({
|
|
150
|
+
rSan: args.rSan,
|
|
151
|
+
missionId: args.missionId,
|
|
152
|
+
agencyName: args.agencyName,
|
|
153
|
+
clockStatus: args.clockStatus || 'unattested',
|
|
154
|
+
seedHex: args.seedHex || null,
|
|
155
|
+
events: Array.isArray(args.events) ? args.events : [],
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
case 'sva_verify_receipt': {
|
|
159
|
+
return verifyAnyReceipt(args.receipt, { deliverable: args.deliverable ?? null, expectedPublicKeys: args.expectedPublicKeys ?? null, allowUnpinned: args.allowUnpinned === true });
|
|
160
|
+
}
|
|
161
|
+
case 'sva_opeg_check': {
|
|
162
|
+
return evaluateOpeg1(args.envelope, { expectedPublicKeys: args.expectedPublicKeys ?? null, allowUnpinned: args.allowUnpinned === true });
|
|
163
|
+
}
|
|
164
|
+
case 'sva_judge_audit': {
|
|
165
|
+
return evaluateSvaJev1(args.envelope);
|
|
166
|
+
}
|
|
167
|
+
case 'sva_crystallize_skill': {
|
|
168
|
+
const pos = (Array.isArray(args.examples) ? args.examples : []).map((e) => ({
|
|
169
|
+
task: e.task,
|
|
170
|
+
input: e.input ?? e.params,
|
|
171
|
+
}));
|
|
172
|
+
const neg = Array.isArray(args.negatives) ? args.negatives : [];
|
|
173
|
+
const skill = args.skill && typeof args.skill === 'object' ? args.skill : { params: { properties: {} } };
|
|
174
|
+
const induced = induce(pos, neg, skill);
|
|
175
|
+
const spec = induced?.spec || null;
|
|
176
|
+
const looRows = spec ? leaveOneOut(pos, neg, skill) : [];
|
|
177
|
+
const looPassed = looRows.filter((r) => r.ok).length;
|
|
178
|
+
const loo = { passed: looPassed, total: looRows.length, ok: looRows.length > 0 && looPassed === looRows.length };
|
|
179
|
+
const out = { induced: Boolean(spec), error: induced?.error ?? null, leaveOneOut: loo, spec };
|
|
180
|
+
if (spec && typeof args.testTask === 'string') {
|
|
181
|
+
const { input: bound, refused, detail } = explainApply(spec, args.testTask);
|
|
182
|
+
const novel = novelWording(pos, args.testTask);
|
|
183
|
+
out.testResult = {
|
|
184
|
+
routed: Boolean(bound && novel.length === 0),
|
|
185
|
+
novelWordingRejected: novel.length > 0 || !bound,
|
|
186
|
+
novelWords: novel,
|
|
187
|
+
refused: refused ? { reason: refused, detail } : null,
|
|
188
|
+
bound,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return out;
|
|
192
|
+
}
|
|
193
|
+
default:
|
|
194
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function createMcpHandler() {
|
|
199
|
+
return function handleRequest(msg) {
|
|
200
|
+
if (!msg || typeof msg !== 'object' || msg.jsonrpc !== '2.0') {
|
|
201
|
+
return { jsonrpc: '2.0', id: null, error: { code: -32600, message: 'Invalid JSON-RPC 2.0 request' } };
|
|
202
|
+
}
|
|
203
|
+
const { id, method, params } = msg;
|
|
204
|
+
// Notifications have no id and expect no response
|
|
205
|
+
if (id === undefined) return null;
|
|
206
|
+
|
|
207
|
+
try {
|
|
208
|
+
if (method === 'initialize') {
|
|
209
|
+
const protocolVersion = typeof params?.protocolVersion === 'string' ? params.protocolVersion : '2025-03-26';
|
|
210
|
+
return {
|
|
211
|
+
jsonrpc: '2.0',
|
|
212
|
+
id,
|
|
213
|
+
result: {
|
|
214
|
+
protocolVersion,
|
|
215
|
+
capabilities: { tools: {} },
|
|
216
|
+
serverInfo: SERVER_INFO,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
if (method === 'ping') {
|
|
221
|
+
return { jsonrpc: '2.0', id, result: {} };
|
|
222
|
+
}
|
|
223
|
+
if (method === 'tools/list') {
|
|
224
|
+
return { jsonrpc: '2.0', id, result: { tools: MCP_TOOLS } };
|
|
225
|
+
}
|
|
226
|
+
if (method === 'tools/call') {
|
|
227
|
+
const toolName = params?.name;
|
|
228
|
+
const toolArgs = params?.arguments || {};
|
|
229
|
+
const data = runTool(toolName, toolArgs);
|
|
230
|
+
return {
|
|
231
|
+
jsonrpc: '2.0',
|
|
232
|
+
id,
|
|
233
|
+
result: {
|
|
234
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
235
|
+
structuredContent: data,
|
|
236
|
+
isError: false,
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
return { jsonrpc: '2.0', id, error: { code: -32601, message: `Method not found: ${method}` } };
|
|
241
|
+
} catch (err) {
|
|
242
|
+
return {
|
|
243
|
+
jsonrpc: '2.0',
|
|
244
|
+
id,
|
|
245
|
+
result: {
|
|
246
|
+
content: [{ type: 'text', text: JSON.stringify({ error: err.message }) }],
|
|
247
|
+
isError: true,
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function startStdioMcpServer(input = process.stdin, output = process.stdout) {
|
|
255
|
+
const handle = createMcpHandler();
|
|
256
|
+
const rl = readline.createInterface({ input, crlfDelay: Infinity });
|
|
257
|
+
rl.on('line', (line) => {
|
|
258
|
+
const trimmed = line.trim();
|
|
259
|
+
if (!trimmed) return;
|
|
260
|
+
let parsed;
|
|
261
|
+
try {
|
|
262
|
+
parsed = JSON.parse(trimmed);
|
|
263
|
+
} catch {
|
|
264
|
+
output.write(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } }) + '\n');
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const resp = handle(parsed);
|
|
268
|
+
if (resp !== null) {
|
|
269
|
+
output.write(JSON.stringify(resp) + '\n');
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
return rl;
|
|
273
|
+
}
|