sigild 0.0.1 → 0.0.3
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/README.md +142 -33
- package/THREAT_MODEL.md +47 -19
- package/dist/src/bin/sigil-hook-post.d.ts +3 -0
- package/dist/src/bin/sigil-hook-post.d.ts.map +1 -0
- package/dist/src/bin/sigil-hook-post.js +15 -0
- package/dist/src/bin/sigil-hook-post.js.map +1 -0
- package/dist/src/bin/sigil-hook-pre.d.ts +3 -0
- package/dist/src/bin/sigil-hook-pre.d.ts.map +1 -0
- package/dist/src/bin/sigil-hook-pre.js +18 -0
- package/dist/src/bin/sigil-hook-pre.js.map +1 -0
- package/dist/src/bin/sigil-mcp.d.ts +3 -0
- package/dist/src/bin/sigil-mcp.d.ts.map +1 -0
- package/dist/src/bin/sigil-mcp.js +90 -0
- package/dist/src/bin/sigil-mcp.js.map +1 -0
- package/dist/src/bin/sigil.d.ts +3 -0
- package/dist/src/bin/sigil.d.ts.map +1 -0
- package/dist/src/bin/sigil.js +9 -0
- package/dist/src/bin/sigil.js.map +1 -0
- package/dist/src/cli/args.d.ts +26 -0
- package/dist/src/cli/args.d.ts.map +1 -0
- package/dist/src/cli/args.js +36 -0
- package/dist/src/cli/args.js.map +1 -0
- package/dist/src/cli/index.d.ts +7 -0
- package/dist/src/cli/index.d.ts.map +1 -0
- package/dist/src/cli/index.js +7 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/cli/main.d.ts +26 -0
- package/dist/src/cli/main.d.ts.map +1 -0
- package/dist/src/cli/main.js +197 -0
- package/dist/src/cli/main.js.map +1 -0
- package/dist/src/cli/paths.d.ts +18 -0
- package/dist/src/cli/paths.d.ts.map +1 -0
- package/dist/src/cli/paths.js +13 -0
- package/dist/src/cli/paths.js.map +1 -0
- package/dist/src/cli/portal.d.ts +59 -0
- package/dist/src/cli/portal.d.ts.map +1 -0
- package/dist/src/cli/portal.js +112 -0
- package/dist/src/cli/portal.js.map +1 -0
- package/dist/src/cli/status.d.ts +28 -0
- package/dist/src/cli/status.d.ts.map +1 -0
- package/dist/src/cli/status.js +59 -0
- package/dist/src/cli/status.js.map +1 -0
- package/dist/src/cli/unlock.d.ts +36 -0
- package/dist/src/cli/unlock.d.ts.map +1 -0
- package/dist/src/cli/unlock.js +77 -0
- package/dist/src/cli/unlock.js.map +1 -0
- package/dist/src/control/client.d.ts +26 -0
- package/dist/src/control/client.d.ts.map +1 -0
- package/dist/src/control/client.js +76 -0
- package/dist/src/control/client.js.map +1 -0
- package/dist/src/control/index.d.ts +4 -0
- package/dist/src/control/index.d.ts.map +1 -0
- package/dist/src/control/index.js +4 -0
- package/dist/src/control/index.js.map +1 -0
- package/dist/src/control/protocol.d.ts +54 -0
- package/dist/src/control/protocol.d.ts.map +1 -0
- package/dist/src/control/protocol.js +60 -0
- package/dist/src/control/protocol.js.map +1 -0
- package/dist/src/control/server.d.ts +52 -0
- package/dist/src/control/server.d.ts.map +1 -0
- package/dist/src/control/server.js +199 -0
- package/dist/src/control/server.js.map +1 -0
- package/dist/src/daemon/handles.d.ts +35 -6
- package/dist/src/daemon/handles.d.ts.map +1 -1
- package/dist/src/daemon/handles.js +83 -28
- package/dist/src/daemon/handles.js.map +1 -1
- package/dist/src/daemon/index.d.ts +2 -3
- package/dist/src/daemon/index.d.ts.map +1 -1
- package/dist/src/daemon/index.js +2 -3
- package/dist/src/daemon/index.js.map +1 -1
- package/dist/src/daemon/methods.d.ts +13 -0
- package/dist/src/daemon/methods.d.ts.map +1 -1
- package/dist/src/daemon/methods.js +50 -1
- package/dist/src/daemon/methods.js.map +1 -1
- package/dist/src/hooks/command-scanner.d.ts +5 -0
- package/dist/src/hooks/command-scanner.d.ts.map +1 -0
- package/dist/src/hooks/command-scanner.js +117 -0
- package/dist/src/hooks/command-scanner.js.map +1 -0
- package/dist/src/hooks/glob.d.ts +8 -0
- package/dist/src/hooks/glob.d.ts.map +1 -0
- package/dist/src/hooks/glob.js +98 -0
- package/dist/src/hooks/glob.js.map +1 -0
- package/dist/src/hooks/index.d.ts +9 -0
- package/dist/src/hooks/index.d.ts.map +1 -0
- package/dist/src/hooks/index.js +9 -0
- package/dist/src/hooks/index.js.map +1 -0
- package/dist/src/hooks/install.d.ts +29 -0
- package/dist/src/hooks/install.d.ts.map +1 -0
- package/dist/src/hooks/install.js +86 -0
- package/dist/src/hooks/install.js.map +1 -0
- package/dist/src/hooks/path-blocker.d.ts +29 -0
- package/dist/src/hooks/path-blocker.d.ts.map +1 -0
- package/dist/src/hooks/path-blocker.js +59 -0
- package/dist/src/hooks/path-blocker.js.map +1 -0
- package/dist/src/hooks/post-tool-use.d.ts +13 -0
- package/dist/src/hooks/post-tool-use.d.ts.map +1 -0
- package/dist/src/hooks/post-tool-use.js +45 -0
- package/dist/src/hooks/post-tool-use.js.map +1 -0
- package/dist/src/hooks/pre-tool-use.d.ts +8 -0
- package/dist/src/hooks/pre-tool-use.d.ts.map +1 -0
- package/dist/src/hooks/pre-tool-use.js +38 -0
- package/dist/src/hooks/pre-tool-use.js.map +1 -0
- package/dist/src/hooks/protocol.d.ts +41 -0
- package/dist/src/hooks/protocol.d.ts.map +1 -0
- package/dist/src/hooks/protocol.js +27 -0
- package/dist/src/hooks/protocol.js.map +1 -0
- package/dist/src/hooks/redactor.d.ts +19 -0
- package/dist/src/hooks/redactor.d.ts.map +1 -0
- package/dist/src/hooks/redactor.js +71 -0
- package/dist/src/hooks/redactor.js.map +1 -0
- package/dist/src/mcp/index.d.ts +4 -0
- package/dist/src/mcp/index.d.ts.map +1 -0
- package/dist/src/mcp/index.js +4 -0
- package/dist/src/mcp/index.js.map +1 -0
- package/dist/src/mcp/protocol.d.ts +98 -0
- package/dist/src/mcp/protocol.d.ts.map +1 -0
- package/dist/src/mcp/protocol.js +79 -0
- package/dist/src/mcp/protocol.js.map +1 -0
- package/dist/src/mcp/server.d.ts +46 -0
- package/dist/src/mcp/server.d.ts.map +1 -0
- package/dist/src/mcp/server.js +108 -0
- package/dist/src/mcp/server.js.map +1 -0
- package/dist/src/mcp/tools.d.ts +16 -0
- package/dist/src/mcp/tools.d.ts.map +1 -0
- package/dist/src/mcp/tools.js +117 -0
- package/dist/src/mcp/tools.js.map +1 -0
- package/dist/src/policy/evaluate.d.ts +13 -0
- package/dist/src/policy/evaluate.d.ts.map +1 -0
- package/dist/src/policy/evaluate.js +73 -0
- package/dist/src/policy/evaluate.js.map +1 -0
- package/dist/src/policy/index.d.ts +5 -0
- package/dist/src/policy/index.d.ts.map +1 -0
- package/dist/src/policy/index.js +5 -0
- package/dist/src/policy/index.js.map +1 -0
- package/dist/src/policy/loader.d.ts +33 -0
- package/dist/src/policy/loader.d.ts.map +1 -0
- package/dist/src/policy/loader.js +170 -0
- package/dist/src/policy/loader.js.map +1 -0
- package/dist/src/policy/template.d.ts +10 -0
- package/dist/src/policy/template.d.ts.map +1 -0
- package/dist/src/policy/template.js +69 -0
- package/dist/src/policy/template.js.map +1 -0
- package/dist/src/policy/types.d.ts +62 -0
- package/dist/src/policy/types.d.ts.map +1 -0
- package/dist/src/policy/types.js +10 -0
- package/dist/src/policy/types.js.map +1 -0
- package/package.json +9 -3
- package/dist/src/bin/sigild.d.ts +0 -3
- package/dist/src/bin/sigild.d.ts.map +0 -1
- package/dist/src/bin/sigild.js +0 -30
- package/dist/src/bin/sigild.js.map +0 -1
- package/dist/src/daemon/rpc.d.ts +0 -61
- package/dist/src/daemon/rpc.d.ts.map +0 -1
- package/dist/src/daemon/rpc.js +0 -76
- package/dist/src/daemon/rpc.js.map +0 -1
- package/dist/src/daemon/runtime.d.ts +0 -40
- package/dist/src/daemon/runtime.d.ts.map +0 -1
- package/dist/src/daemon/runtime.js +0 -61
- package/dist/src/daemon/runtime.js.map +0 -1
- package/dist/src/daemon/server.d.ts +0 -53
- package/dist/src/daemon/server.d.ts.map +0 -1
- package/dist/src/daemon/server.js +0 -103
- package/dist/src/daemon/server.js.map +0 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output redactor — the second line of defence behind the path blocker.
|
|
3
|
+
* If a key somehow ends up in tool output (because the agent read a file
|
|
4
|
+
* the blocker missed, or coaxed a key out of an API), redact it before it
|
|
5
|
+
* reaches the model's context.
|
|
6
|
+
*
|
|
7
|
+
* The rules are deliberately strict — false positives are tolerable
|
|
8
|
+
* (redacted noise in tool output is annoying; an exfiltrated key is fatal).
|
|
9
|
+
*/
|
|
10
|
+
const RULES = Object.freeze([
|
|
11
|
+
// PEM-encoded private key blocks. Matched first so the inner base64 isn't
|
|
12
|
+
// also caught by the hex/JWT rules.
|
|
13
|
+
{
|
|
14
|
+
reason: 'pem-private-key',
|
|
15
|
+
regex: /-----BEGIN [A-Z0-9 ]*PRIVATE KEY[A-Z0-9 ]*-----[\s\S]+?-----END [A-Z0-9 ]*PRIVATE KEY[A-Z0-9 ]*-----/g,
|
|
16
|
+
},
|
|
17
|
+
// Generic PEM block — second-line check for "BEGIN ... KEY ...END ... KEY"
|
|
18
|
+
// that didn't say PRIVATE explicitly (some tools emit just "KEY").
|
|
19
|
+
{
|
|
20
|
+
reason: 'pem-key-block',
|
|
21
|
+
regex: /-----BEGIN [A-Z0-9 ]*KEY[A-Z0-9 ]*-----[\s\S]+?-----END [A-Z0-9 ]*KEY[A-Z0-9 ]*-----/g,
|
|
22
|
+
},
|
|
23
|
+
// 32-byte raw private keys as 0x-prefixed hex (most common Ethereum form).
|
|
24
|
+
// Word boundary on both sides so we don't grab a 0x... that happens to be
|
|
25
|
+
// a longer hash and continue past it.
|
|
26
|
+
{
|
|
27
|
+
reason: 'hex-private-key',
|
|
28
|
+
regex: /\b0x[0-9a-fA-F]{64}(?![0-9a-fA-F])/g,
|
|
29
|
+
},
|
|
30
|
+
// JWT (header.payload.signature where header starts with eyJ — base64url
|
|
31
|
+
// of {"...). Three url-safe-base64 sections separated by dots.
|
|
32
|
+
{
|
|
33
|
+
reason: 'jwt',
|
|
34
|
+
regex: /\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g,
|
|
35
|
+
},
|
|
36
|
+
// npm tokens (npm_ + ~36 chars) — same pattern they're emitted in.
|
|
37
|
+
{
|
|
38
|
+
reason: 'npm-token',
|
|
39
|
+
regex: /\bnpm_[A-Za-z0-9]{36,}\b/g,
|
|
40
|
+
},
|
|
41
|
+
// Anthropic / Claude API keys (sk-ant-...).
|
|
42
|
+
{
|
|
43
|
+
reason: 'anthropic-api-key',
|
|
44
|
+
regex: /\bsk-ant-[A-Za-z0-9_-]{20,}\b/g,
|
|
45
|
+
},
|
|
46
|
+
// OpenAI keys.
|
|
47
|
+
{
|
|
48
|
+
reason: 'openai-api-key',
|
|
49
|
+
regex: /\bsk-[A-Za-z0-9]{32,}\b/g,
|
|
50
|
+
},
|
|
51
|
+
// AWS access key IDs (AKIA + 16 chars) and secret access keys (40 base64-ish chars).
|
|
52
|
+
{
|
|
53
|
+
reason: 'aws-access-key-id',
|
|
54
|
+
regex: /\bAKIA[0-9A-Z]{16}\b/g,
|
|
55
|
+
},
|
|
56
|
+
]);
|
|
57
|
+
export function redact(text) {
|
|
58
|
+
const counts = new Map();
|
|
59
|
+
let out = text;
|
|
60
|
+
for (const rule of RULES) {
|
|
61
|
+
out = out.replace(rule.regex, () => {
|
|
62
|
+
counts.set(rule.reason, (counts.get(rule.reason) ?? 0) + 1);
|
|
63
|
+
return `<REDACTED:${rule.reason}>`;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const redactions = [];
|
|
67
|
+
for (const [reason, count] of counts)
|
|
68
|
+
redactions.push({ reason, count });
|
|
69
|
+
return { text: out, redactions };
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=redactor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redactor.js","sourceRoot":"","sources":["../../../src/hooks/redactor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAiBH,MAAM,KAAK,GAAoB,MAAM,CAAC,MAAM,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;IACvC,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,MAAM;QAAE,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACzE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { type McpId, type McpRequest, type McpNotification, type McpResponse, type McpSuccess, type McpError, type McpErrorBody, type ParseResult, type ToolInputSchema, type ToolDefinition, type ToolContent, type ToolResult, PROTOCOL_VERSION, SERVER_INFO, MCP_PARSE_ERROR, MCP_INVALID_REQUEST, MCP_METHOD_NOT_FOUND, MCP_INVALID_PARAMS, MCP_INTERNAL_ERROR, parseMessage, encodeSuccess, encodeError, } from './protocol.js';
|
|
2
|
+
export { type Tool, type ToolHandler, type ToolHandlerCtx, ToolError, TOOLS, findTool, } from './tools.js';
|
|
3
|
+
export { type McpServerOpts, type McpStdioOpts, type McpLogEvent, handleLine, runMcpStdio, } from './server.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,SAAS,EACT,KAAK,EACL,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,UAAU,EACV,WAAW,GACZ,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { PROTOCOL_VERSION, SERVER_INFO, MCP_PARSE_ERROR, MCP_INVALID_REQUEST, MCP_METHOD_NOT_FOUND, MCP_INVALID_PARAMS, MCP_INTERNAL_ERROR, parseMessage, encodeSuccess, encodeError, } from './protocol.js';
|
|
2
|
+
export { ToolError, TOOLS, findTool, } from './tools.js';
|
|
3
|
+
export { handleLine, runMcpStdio, } from './server.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAaL,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAIL,SAAS,EACT,KAAK,EACL,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EAIL,UAAU,EACV,WAAW,GACZ,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal subset of the Model Context Protocol (MCP) wire format that sigil
|
|
3
|
+
* needs to act as a stdio tool server for Claude Code (and any other MCP
|
|
4
|
+
* client). MCP rides on JSON-RPC 2.0; this module defines the request,
|
|
5
|
+
* response, and notification shapes plus helpers for encoding.
|
|
6
|
+
*
|
|
7
|
+
* Spec reference: https://modelcontextprotocol.io/specification
|
|
8
|
+
*
|
|
9
|
+
* We implement: initialize, notifications/initialized, tools/list, tools/call.
|
|
10
|
+
* Everything else (resources, prompts, sampling, completions, logging,
|
|
11
|
+
* pagination cursors) is intentionally omitted.
|
|
12
|
+
*/
|
|
13
|
+
export declare const PROTOCOL_VERSION = "2025-06-18";
|
|
14
|
+
export declare const SERVER_INFO: {
|
|
15
|
+
readonly name: "sigil-mcp";
|
|
16
|
+
readonly version: "0.0.1";
|
|
17
|
+
};
|
|
18
|
+
export type McpId = string | number | null;
|
|
19
|
+
export interface McpRequest {
|
|
20
|
+
jsonrpc: '2.0';
|
|
21
|
+
id: McpId;
|
|
22
|
+
method: string;
|
|
23
|
+
params?: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface McpNotification {
|
|
26
|
+
jsonrpc: '2.0';
|
|
27
|
+
method: string;
|
|
28
|
+
params?: unknown;
|
|
29
|
+
}
|
|
30
|
+
export interface McpSuccess {
|
|
31
|
+
jsonrpc: '2.0';
|
|
32
|
+
id: McpId;
|
|
33
|
+
result: unknown;
|
|
34
|
+
}
|
|
35
|
+
export interface McpErrorBody {
|
|
36
|
+
code: number;
|
|
37
|
+
message: string;
|
|
38
|
+
data?: unknown;
|
|
39
|
+
}
|
|
40
|
+
export interface McpError {
|
|
41
|
+
jsonrpc: '2.0';
|
|
42
|
+
id: McpId;
|
|
43
|
+
error: McpErrorBody;
|
|
44
|
+
}
|
|
45
|
+
export type McpResponse = McpSuccess | McpError;
|
|
46
|
+
export declare const MCP_PARSE_ERROR = -32700;
|
|
47
|
+
export declare const MCP_INVALID_REQUEST = -32600;
|
|
48
|
+
export declare const MCP_METHOD_NOT_FOUND = -32601;
|
|
49
|
+
export declare const MCP_INVALID_PARAMS = -32602;
|
|
50
|
+
export declare const MCP_INTERNAL_ERROR = -32603;
|
|
51
|
+
export interface ToolInputSchema {
|
|
52
|
+
type: 'object';
|
|
53
|
+
properties: Record<string, unknown>;
|
|
54
|
+
required?: string[];
|
|
55
|
+
additionalProperties?: boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface ToolDefinition {
|
|
58
|
+
name: string;
|
|
59
|
+
description: string;
|
|
60
|
+
inputSchema: ToolInputSchema;
|
|
61
|
+
}
|
|
62
|
+
export type ToolContent = {
|
|
63
|
+
type: 'text';
|
|
64
|
+
text: string;
|
|
65
|
+
};
|
|
66
|
+
export interface ToolResult {
|
|
67
|
+
content: ToolContent[];
|
|
68
|
+
/** When omitted, treated as false. */
|
|
69
|
+
isError?: boolean;
|
|
70
|
+
/** Structured payload for clients that want typed access; supplemental to content. */
|
|
71
|
+
structuredContent?: unknown;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Parse a single NDJSON line into an MCP envelope.
|
|
75
|
+
*
|
|
76
|
+
* Returns:
|
|
77
|
+
* - `{ kind: 'request', request }` for an incoming request (has id + method)
|
|
78
|
+
* - `{ kind: 'notification', notification }` for an incoming notification (method, no id)
|
|
79
|
+
* - `{ kind: 'parse_error' }` for non-JSON
|
|
80
|
+
* - `{ kind: 'invalid', id, reason }` for a JSON object that isn't a valid envelope
|
|
81
|
+
*/
|
|
82
|
+
export type ParseResult = {
|
|
83
|
+
kind: 'request';
|
|
84
|
+
request: McpRequest;
|
|
85
|
+
} | {
|
|
86
|
+
kind: 'notification';
|
|
87
|
+
notification: McpNotification;
|
|
88
|
+
} | {
|
|
89
|
+
kind: 'parse_error';
|
|
90
|
+
} | {
|
|
91
|
+
kind: 'invalid';
|
|
92
|
+
id: McpId;
|
|
93
|
+
reason: string;
|
|
94
|
+
};
|
|
95
|
+
export declare function parseMessage(line: string): ParseResult;
|
|
96
|
+
export declare function encodeSuccess(id: McpId, result: unknown): string;
|
|
97
|
+
export declare function encodeError(id: McpId, code: number, message: string, data?: unknown): string;
|
|
98
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/mcp/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAE7C,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AAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,eAAe,CAAC;CAC9B;AAED,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnC,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,sCAAsC;IACtC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,sFAAsF;IACtF,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,UAAU,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,YAAY,EAAE,eAAe,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAyCtD;AAMD,wBAAgB,aAAa,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAGhE;AAED,wBAAgB,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAI5F"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal subset of the Model Context Protocol (MCP) wire format that sigil
|
|
3
|
+
* needs to act as a stdio tool server for Claude Code (and any other MCP
|
|
4
|
+
* client). MCP rides on JSON-RPC 2.0; this module defines the request,
|
|
5
|
+
* response, and notification shapes plus helpers for encoding.
|
|
6
|
+
*
|
|
7
|
+
* Spec reference: https://modelcontextprotocol.io/specification
|
|
8
|
+
*
|
|
9
|
+
* We implement: initialize, notifications/initialized, tools/list, tools/call.
|
|
10
|
+
* Everything else (resources, prompts, sampling, completions, logging,
|
|
11
|
+
* pagination cursors) is intentionally omitted.
|
|
12
|
+
*/
|
|
13
|
+
export const PROTOCOL_VERSION = '2025-06-18';
|
|
14
|
+
export const SERVER_INFO = {
|
|
15
|
+
name: 'sigil-mcp',
|
|
16
|
+
version: '0.0.1',
|
|
17
|
+
};
|
|
18
|
+
// Standard JSON-RPC 2.0 error codes (re-stated to keep this module self-contained).
|
|
19
|
+
export const MCP_PARSE_ERROR = -32700;
|
|
20
|
+
export const MCP_INVALID_REQUEST = -32600;
|
|
21
|
+
export const MCP_METHOD_NOT_FOUND = -32601;
|
|
22
|
+
export const MCP_INVALID_PARAMS = -32602;
|
|
23
|
+
export const MCP_INTERNAL_ERROR = -32603;
|
|
24
|
+
export function parseMessage(line) {
|
|
25
|
+
let parsed;
|
|
26
|
+
try {
|
|
27
|
+
parsed = JSON.parse(line);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return { kind: 'parse_error' };
|
|
31
|
+
}
|
|
32
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
33
|
+
return { kind: 'invalid', id: null, reason: 'message must be a JSON object' };
|
|
34
|
+
}
|
|
35
|
+
const obj = parsed;
|
|
36
|
+
if (obj['jsonrpc'] !== '2.0') {
|
|
37
|
+
return { kind: 'invalid', id: extractId(obj['id']), reason: 'jsonrpc must be "2.0"' };
|
|
38
|
+
}
|
|
39
|
+
if (typeof obj['method'] !== 'string' || obj['method'].length === 0) {
|
|
40
|
+
return { kind: 'invalid', id: extractId(obj['id']), reason: 'method must be a non-empty string' };
|
|
41
|
+
}
|
|
42
|
+
// Distinguish request vs notification by presence of id.
|
|
43
|
+
if (!('id' in obj)) {
|
|
44
|
+
return {
|
|
45
|
+
kind: 'notification',
|
|
46
|
+
notification: {
|
|
47
|
+
jsonrpc: '2.0',
|
|
48
|
+
method: obj['method'],
|
|
49
|
+
...(obj['params'] !== undefined ? { params: obj['params'] } : {}),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const rawId = obj['id'];
|
|
54
|
+
if (typeof rawId !== 'string' && typeof rawId !== 'number' && rawId !== null) {
|
|
55
|
+
return { kind: 'invalid', id: null, reason: 'id must be string, number, or null' };
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
kind: 'request',
|
|
59
|
+
request: {
|
|
60
|
+
jsonrpc: '2.0',
|
|
61
|
+
id: rawId,
|
|
62
|
+
method: obj['method'],
|
|
63
|
+
...(obj['params'] !== undefined ? { params: obj['params'] } : {}),
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function extractId(raw) {
|
|
68
|
+
return typeof raw === 'string' || typeof raw === 'number' || raw === null ? raw : null;
|
|
69
|
+
}
|
|
70
|
+
export function encodeSuccess(id, result) {
|
|
71
|
+
const r = { jsonrpc: '2.0', id, result };
|
|
72
|
+
return JSON.stringify(r);
|
|
73
|
+
}
|
|
74
|
+
export function encodeError(id, code, message, data) {
|
|
75
|
+
const error = data === undefined ? { code, message } : { code, message, data };
|
|
76
|
+
const r = { jsonrpc: '2.0', id, error };
|
|
77
|
+
return JSON.stringify(r);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/mcp/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAE7C,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,OAAO;CACR,CAAC;AAqCX,oFAAoF;AACpF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAK,CAA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,EAAE,MAAM,EAAE,CAAC;IACrD,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,EAAS,EAAE,IAAY,EAAE,OAAe,EAAE,IAAc;IAClF,MAAM,KAAK,GAAiB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC7F,MAAM,CAAC,GAAa,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;IAClD,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { MethodContext } from '../daemon/methods.js';
|
|
2
|
+
import { type McpId } from './protocol.js';
|
|
3
|
+
export interface McpServerOpts {
|
|
4
|
+
/**
|
|
5
|
+
* In-process method context: handles + audit. The MCP server invokes
|
|
6
|
+
* sign methods directly against this — no cross-process IPC.
|
|
7
|
+
*/
|
|
8
|
+
context: MethodContext;
|
|
9
|
+
/**
|
|
10
|
+
* Optional log sink for protocol-level events. Defaults to a no-op.
|
|
11
|
+
* The default binary entrypoint writes log events to stderr so they don't
|
|
12
|
+
* collide with stdio MCP traffic on stdout.
|
|
13
|
+
*/
|
|
14
|
+
onLog?: (event: McpLogEvent) => void;
|
|
15
|
+
}
|
|
16
|
+
export type McpLogEvent = {
|
|
17
|
+
kind: 'recv';
|
|
18
|
+
method: string;
|
|
19
|
+
id: McpId | null;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'send_ok';
|
|
22
|
+
id: McpId;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'send_error';
|
|
25
|
+
id: McpId;
|
|
26
|
+
code: number;
|
|
27
|
+
message: string;
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'initialized';
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Handle a single received line by dispatching it through the MCP protocol.
|
|
33
|
+
* Returns either a response string to send back, or `null` if the line was a
|
|
34
|
+
* notification (no response expected).
|
|
35
|
+
*/
|
|
36
|
+
export declare function handleLine(line: string, opts: McpServerOpts): string | null;
|
|
37
|
+
export interface McpStdioOpts extends McpServerOpts {
|
|
38
|
+
stdin: NodeJS.ReadableStream;
|
|
39
|
+
stdout: NodeJS.WritableStream;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Run the MCP server over arbitrary streams (stdin/stdout in production,
|
|
43
|
+
* mock streams in tests). Resolves when stdin closes.
|
|
44
|
+
*/
|
|
45
|
+
export declare function runMcpStdio(opts: McpStdioOpts): Promise<void>;
|
|
46
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/mcp/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAWL,KAAK,KAAK,EAEX,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,OAAO,EAAE,aAAa,CAAC;IACvB;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;CACtC;AAED,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,KAAK,GAAG,IAAI,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,KAAK,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC;AAE5B;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAkC3E;AA0CD,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;CAC/B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAuB7D"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { findTool, ToolError, TOOLS } from './tools.js';
|
|
2
|
+
import { encodeError, encodeSuccess, MCP_INTERNAL_ERROR, MCP_INVALID_PARAMS, MCP_INVALID_REQUEST, MCP_METHOD_NOT_FOUND, MCP_PARSE_ERROR, parseMessage, PROTOCOL_VERSION, SERVER_INFO, } from './protocol.js';
|
|
3
|
+
/**
|
|
4
|
+
* Handle a single received line by dispatching it through the MCP protocol.
|
|
5
|
+
* Returns either a response string to send back, or `null` if the line was a
|
|
6
|
+
* notification (no response expected).
|
|
7
|
+
*/
|
|
8
|
+
export function handleLine(line, opts) {
|
|
9
|
+
const parsed = parseMessage(line);
|
|
10
|
+
const log = (e) => opts.onLog?.(e);
|
|
11
|
+
if (parsed.kind === 'parse_error') {
|
|
12
|
+
log({ kind: 'send_error', id: null, code: MCP_PARSE_ERROR, message: 'parse error' });
|
|
13
|
+
return encodeError(null, MCP_PARSE_ERROR, 'parse error');
|
|
14
|
+
}
|
|
15
|
+
if (parsed.kind === 'invalid') {
|
|
16
|
+
log({ kind: 'send_error', id: parsed.id, code: MCP_INVALID_REQUEST, message: parsed.reason });
|
|
17
|
+
return encodeError(parsed.id, MCP_INVALID_REQUEST, parsed.reason);
|
|
18
|
+
}
|
|
19
|
+
if (parsed.kind === 'notification') {
|
|
20
|
+
log({ kind: 'recv', method: parsed.notification.method, id: null });
|
|
21
|
+
if (parsed.notification.method === 'notifications/initialized') {
|
|
22
|
+
log({ kind: 'initialized' });
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const req = parsed.request;
|
|
27
|
+
log({ kind: 'recv', method: req.method, id: req.id });
|
|
28
|
+
try {
|
|
29
|
+
const result = dispatch(req, opts);
|
|
30
|
+
log({ kind: 'send_ok', id: req.id });
|
|
31
|
+
return encodeSuccess(req.id, result);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (err instanceof ToolError) {
|
|
35
|
+
log({ kind: 'send_error', id: req.id, code: err.code, message: err.message });
|
|
36
|
+
return encodeError(req.id, err.code, err.message, err.data);
|
|
37
|
+
}
|
|
38
|
+
const message = `internal error: ${err.message}`;
|
|
39
|
+
log({ kind: 'send_error', id: req.id, code: MCP_INTERNAL_ERROR, message });
|
|
40
|
+
return encodeError(req.id, MCP_INTERNAL_ERROR, message);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function dispatch(req, opts) {
|
|
44
|
+
switch (req.method) {
|
|
45
|
+
case 'initialize':
|
|
46
|
+
return {
|
|
47
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
48
|
+
capabilities: { tools: { listChanged: false } },
|
|
49
|
+
serverInfo: SERVER_INFO,
|
|
50
|
+
};
|
|
51
|
+
case 'tools/list':
|
|
52
|
+
return { tools: TOOLS.map((t) => t.definition) };
|
|
53
|
+
case 'tools/call':
|
|
54
|
+
return invokeTool(req.params, opts);
|
|
55
|
+
case 'ping':
|
|
56
|
+
return {};
|
|
57
|
+
default:
|
|
58
|
+
throw new ToolError(MCP_METHOD_NOT_FOUND, `method not found: ${req.method}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function invokeTool(params, opts) {
|
|
62
|
+
if (typeof params !== 'object' || params === null || Array.isArray(params)) {
|
|
63
|
+
throw new ToolError(MCP_INVALID_PARAMS, 'tools/call: params must be an object');
|
|
64
|
+
}
|
|
65
|
+
const obj = params;
|
|
66
|
+
const name = obj['name'];
|
|
67
|
+
if (typeof name !== 'string' || name.length === 0) {
|
|
68
|
+
throw new ToolError(MCP_INVALID_PARAMS, 'tools/call: name must be a non-empty string');
|
|
69
|
+
}
|
|
70
|
+
const tool = findTool(name);
|
|
71
|
+
if (!tool) {
|
|
72
|
+
throw new ToolError(MCP_METHOD_NOT_FOUND, `unknown tool: ${name}`);
|
|
73
|
+
}
|
|
74
|
+
const args = obj['arguments'] ?? {};
|
|
75
|
+
return tool.handler(args, opts.context);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Run the MCP server over arbitrary streams (stdin/stdout in production,
|
|
79
|
+
* mock streams in tests). Resolves when stdin closes.
|
|
80
|
+
*/
|
|
81
|
+
export function runMcpStdio(opts) {
|
|
82
|
+
const { stdin, stdout } = opts;
|
|
83
|
+
stdin.setEncoding?.('utf8');
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
let buf = '';
|
|
86
|
+
let stdinEnded = false;
|
|
87
|
+
stdin.on('data', (chunk) => {
|
|
88
|
+
buf += typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
89
|
+
let nl;
|
|
90
|
+
while ((nl = buf.indexOf('\n')) !== -1) {
|
|
91
|
+
const line = buf.slice(0, nl);
|
|
92
|
+
buf = buf.slice(nl + 1);
|
|
93
|
+
if (line.length === 0)
|
|
94
|
+
continue;
|
|
95
|
+
const resp = handleLine(line, opts);
|
|
96
|
+
if (resp !== null)
|
|
97
|
+
stdout.write(resp + '\n');
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
stdin.on('end', () => {
|
|
101
|
+
stdinEnded = true;
|
|
102
|
+
if (stdinEnded)
|
|
103
|
+
resolve();
|
|
104
|
+
});
|
|
105
|
+
stdin.on('error', reject);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|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G,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBACpC,IAAI,IAAI,KAAK,IAAI;oBAAE,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACnB,UAAU,GAAG,IAAI,CAAC;YAClB,IAAI,UAAU;gBAAE,OAAO,EAAE,CAAC;QAC5B,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type MethodContext } from '../daemon/methods.js';
|
|
2
|
+
import { type ToolDefinition, type ToolResult } from './protocol.js';
|
|
3
|
+
export type ToolHandlerCtx = MethodContext;
|
|
4
|
+
export type ToolHandler = (args: unknown, ctx: ToolHandlerCtx) => ToolResult;
|
|
5
|
+
export interface Tool {
|
|
6
|
+
definition: ToolDefinition;
|
|
7
|
+
handler: ToolHandler;
|
|
8
|
+
}
|
|
9
|
+
export declare const TOOLS: readonly Tool[];
|
|
10
|
+
export declare function findTool(name: string): Tool | undefined;
|
|
11
|
+
export declare class ToolError extends Error {
|
|
12
|
+
readonly code: number;
|
|
13
|
+
readonly data: unknown;
|
|
14
|
+
constructor(code: number, message: string, data?: unknown);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,aAAa,EAAkB,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAsB,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAEzF,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC;AAE3C,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,KAAK,UAAU,CAAC;AAE7E,MAAM,WAAW,IAAI;IACnB,UAAU,EAAE,cAAc,CAAC;IAC3B,OAAO,EAAE,WAAW,CAAC;CACtB;AA6ED,eAAO,MAAM,KAAK,EAAE,SAAS,IAAI,EAK/B,CAAC;AAEH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAEvD;AAMD,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBACX,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;CAM1D"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { dispatch, RpcMethodError } from '../daemon/methods.js';
|
|
2
|
+
import { MCP_INTERNAL_ERROR } from './protocol.js';
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Tool definitions
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
const listPortals = {
|
|
7
|
+
definition: {
|
|
8
|
+
name: 'sigil_list_portals',
|
|
9
|
+
description: 'List the signing portals currently loaded in sigil. Returns each portal handle (e.g. "eth:executor"), its kind, and the public address it controls.',
|
|
10
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
11
|
+
},
|
|
12
|
+
handler: (args, ctx) => callMethod('sigil_list_portals', args, ctx),
|
|
13
|
+
};
|
|
14
|
+
const ethSignMessage = {
|
|
15
|
+
definition: {
|
|
16
|
+
name: 'sigil_eth_sign_message',
|
|
17
|
+
description: 'Sign an EIP-191 personal_sign message with the named portal. The message is supplied as 0x-prefixed hex bytes (encode strings to UTF-8 first). Returns the 65-byte r||s||v signature as 0x-prefixed hex.',
|
|
18
|
+
inputSchema: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
portal: { type: 'string', description: 'Portal handle, e.g. "eth:executor".' },
|
|
22
|
+
message: { type: 'string', description: '0x-prefixed hex of the bytes to sign.' },
|
|
23
|
+
},
|
|
24
|
+
required: ['portal', 'message'],
|
|
25
|
+
additionalProperties: false,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
handler: (args, ctx) => callMethod('sigil_eth_sign_message', args, ctx),
|
|
29
|
+
};
|
|
30
|
+
const ethSignTransaction = {
|
|
31
|
+
definition: {
|
|
32
|
+
name: 'sigil_eth_sign_transaction',
|
|
33
|
+
description: 'Sign an Ethereum transaction (legacy or EIP-1559) with the named portal. Returns the signed transaction as 0x-prefixed hex, ready for eth_sendRawTransaction.',
|
|
34
|
+
inputSchema: {
|
|
35
|
+
type: 'object',
|
|
36
|
+
properties: {
|
|
37
|
+
portal: { type: 'string', description: 'Portal handle.' },
|
|
38
|
+
tx: {
|
|
39
|
+
type: 'object',
|
|
40
|
+
description: 'Transaction fields. type="legacy" requires {chainId, nonce, gasPrice, gasLimit, to, value, data}. type="eip1559" requires {chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList?}. Numbers may be supplied as JSON numbers or decimal strings.',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
required: ['portal', 'tx'],
|
|
44
|
+
additionalProperties: false,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
handler: (args, ctx) => callMethod('sigil_eth_sign_transaction', args, ctx),
|
|
48
|
+
};
|
|
49
|
+
const ethSignTypedData = {
|
|
50
|
+
definition: {
|
|
51
|
+
name: 'sigil_eth_sign_typed_data',
|
|
52
|
+
description: 'Sign an EIP-712 typed data structure with the named portal. Returns the 65-byte signature as 0x-prefixed hex.',
|
|
53
|
+
inputSchema: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {
|
|
56
|
+
portal: { type: 'string', description: 'Portal handle.' },
|
|
57
|
+
typedData: {
|
|
58
|
+
type: 'object',
|
|
59
|
+
description: 'EIP-712 typed data: {types, primaryType, domain, message}.',
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
required: ['portal', 'typedData'],
|
|
63
|
+
additionalProperties: false,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
handler: (args, ctx) => callMethod('sigil_eth_sign_typed_data', args, ctx),
|
|
67
|
+
};
|
|
68
|
+
export const TOOLS = Object.freeze([
|
|
69
|
+
listPortals,
|
|
70
|
+
ethSignMessage,
|
|
71
|
+
ethSignTransaction,
|
|
72
|
+
ethSignTypedData,
|
|
73
|
+
]);
|
|
74
|
+
export function findTool(name) {
|
|
75
|
+
return TOOLS.find((t) => t.definition.name === name);
|
|
76
|
+
}
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Helpers
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
export class ToolError extends Error {
|
|
81
|
+
code;
|
|
82
|
+
data;
|
|
83
|
+
constructor(code, message, data) {
|
|
84
|
+
super(message);
|
|
85
|
+
this.name = 'ToolError';
|
|
86
|
+
this.code = code;
|
|
87
|
+
this.data = data;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Call into the in-process method dispatcher and wrap the result for MCP.
|
|
92
|
+
* Maps `RpcMethodError` (raised by the dispatcher on user errors or
|
|
93
|
+
* not-found method) into `ToolError` with the same code, so the original
|
|
94
|
+
* error semantics flow through to the MCP client unchanged.
|
|
95
|
+
*/
|
|
96
|
+
function callMethod(methodName, args, ctx) {
|
|
97
|
+
try {
|
|
98
|
+
const result = dispatch(methodName, args, ctx);
|
|
99
|
+
return textResult(result);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
if (err instanceof RpcMethodError) {
|
|
103
|
+
throw new ToolError(err.code, err.message, err.data);
|
|
104
|
+
}
|
|
105
|
+
throw new ToolError(MCP_INTERNAL_ERROR, `internal: ${err.message}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function textResult(payload) {
|
|
109
|
+
// JSON-serialize the response into the MCP text content slot.
|
|
110
|
+
// We also include structuredContent so MCP clients that support it can
|
|
111
|
+
// access the typed payload directly without re-parsing.
|
|
112
|
+
return {
|
|
113
|
+
content: [{ type: 'text', text: JSON.stringify(payload) }],
|
|
114
|
+
structuredContent: payload,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAwC,MAAM,eAAe,CAAC;AAWzF,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,MAAM,WAAW,GAAS;IACxB,UAAU,EAAE;QACV,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EACT,qJAAqJ;QACvJ,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE;KAC7E;IACD,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,oBAAoB,EAAE,IAAI,EAAE,GAAG,CAAC;CACpE,CAAC;AAEF,MAAM,cAAc,GAAS;IAC3B,UAAU,EAAE;QACV,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EACT,0MAA0M;QAC5M,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,qCAAqC,EAAE;gBAC9E,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,uCAAuC,EAAE;aAClF;YACD,QAAQ,EAAE,CAAC,QA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;IACxD,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1D,iBAAiB,EAAE,OAAO;KAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Policy, PolicyDecision, PolicyRequest } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Pure evaluator. Takes a (request, policy), returns Allow or Deny(reason).
|
|
4
|
+
*
|
|
5
|
+
* The reason string is what the caller writes into the audit log and surfaces
|
|
6
|
+
* as the RPC_POLICY_DENIED error message — write it for a human.
|
|
7
|
+
*
|
|
8
|
+
* Permissive mode short-circuits to Allow for everything. Strict mode walks
|
|
9
|
+
* the rules in a fixed order and returns the first failing one — the order
|
|
10
|
+
* doesn't matter for correctness, only for which reason the user sees first.
|
|
11
|
+
*/
|
|
12
|
+
export declare function evaluate(request: PolicyRequest, policy: Policy): PolicyDecision;
|
|
13
|
+
//# sourceMappingURL=evaluate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../../src/policy/evaluate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAExE;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAoB/E"}
|