craftdriver 1.7.0 → 1.8.0

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.
Files changed (175) hide show
  1. package/CHANGELOG.md +23 -11
  2. package/README.md +13 -4
  3. package/dist/cli/agentSession.d.ts +62 -0
  4. package/dist/cli/agentSession.d.ts.map +1 -0
  5. package/dist/cli/agentSession.js +100 -0
  6. package/dist/cli/agentSession.js.map +1 -0
  7. package/dist/cli/artifactPaths.d.ts +42 -0
  8. package/dist/cli/artifactPaths.d.ts.map +1 -0
  9. package/dist/cli/artifactPaths.js +144 -0
  10. package/dist/cli/artifactPaths.js.map +1 -0
  11. package/dist/cli/bounds.d.ts +88 -0
  12. package/dist/cli/bounds.d.ts.map +1 -0
  13. package/dist/cli/bounds.js +128 -0
  14. package/dist/cli/bounds.js.map +1 -0
  15. package/dist/cli/client.d.ts +3 -0
  16. package/dist/cli/client.d.ts.map +1 -1
  17. package/dist/cli/client.js +24 -8
  18. package/dist/cli/client.js.map +1 -1
  19. package/dist/cli/daemon.d.ts +3 -0
  20. package/dist/cli/daemon.d.ts.map +1 -1
  21. package/dist/cli/daemon.js +152 -39
  22. package/dist/cli/daemon.js.map +1 -1
  23. package/dist/cli/defaults.d.ts +23 -3
  24. package/dist/cli/defaults.d.ts.map +1 -1
  25. package/dist/cli/defaults.js +50 -5
  26. package/dist/cli/defaults.js.map +1 -1
  27. package/dist/cli/dispatcher.d.ts +54 -11
  28. package/dist/cli/dispatcher.d.ts.map +1 -1
  29. package/dist/cli/dispatcher.js +851 -54
  30. package/dist/cli/dispatcher.js.map +1 -1
  31. package/dist/cli/index.d.ts.map +1 -1
  32. package/dist/cli/index.js +305 -56
  33. package/dist/cli/index.js.map +1 -1
  34. package/dist/cli/init.d.ts +14 -14
  35. package/dist/cli/init.d.ts.map +1 -1
  36. package/dist/cli/init.js +328 -180
  37. package/dist/cli/init.js.map +1 -1
  38. package/dist/cli/journal.d.ts +153 -0
  39. package/dist/cli/journal.d.ts.map +1 -0
  40. package/dist/cli/journal.js +252 -0
  41. package/dist/cli/journal.js.map +1 -0
  42. package/dist/cli/lineReader.d.ts +33 -0
  43. package/dist/cli/lineReader.d.ts.map +1 -0
  44. package/dist/cli/lineReader.js +66 -0
  45. package/dist/cli/lineReader.js.map +1 -0
  46. package/dist/cli/locatorCandidates.d.ts +44 -0
  47. package/dist/cli/locatorCandidates.d.ts.map +1 -0
  48. package/dist/cli/locatorCandidates.js +190 -0
  49. package/dist/cli/locatorCandidates.js.map +1 -0
  50. package/dist/cli/mcp/artifacts.d.ts +39 -1
  51. package/dist/cli/mcp/artifacts.d.ts.map +1 -1
  52. package/dist/cli/mcp/artifacts.js +104 -9
  53. package/dist/cli/mcp/artifacts.js.map +1 -1
  54. package/dist/cli/mcp/bounds.d.ts +65 -0
  55. package/dist/cli/mcp/bounds.d.ts.map +1 -0
  56. package/dist/cli/mcp/bounds.js +124 -0
  57. package/dist/cli/mcp/bounds.js.map +1 -0
  58. package/dist/cli/mcp/params.d.ts +38 -0
  59. package/dist/cli/mcp/params.d.ts.map +1 -0
  60. package/dist/cli/mcp/params.js +174 -0
  61. package/dist/cli/mcp/params.js.map +1 -0
  62. package/dist/cli/mcp/server.d.ts +94 -16
  63. package/dist/cli/mcp/server.d.ts.map +1 -1
  64. package/dist/cli/mcp/server.js +304 -150
  65. package/dist/cli/mcp/server.js.map +1 -1
  66. package/dist/cli/mcp/tools.d.ts +62 -17
  67. package/dist/cli/mcp/tools.d.ts.map +1 -1
  68. package/dist/cli/mcp/tools.js +373 -158
  69. package/dist/cli/mcp/tools.js.map +1 -1
  70. package/dist/cli/pageSemantics.d.ts +42 -0
  71. package/dist/cli/pageSemantics.d.ts.map +1 -0
  72. package/dist/cli/pageSemantics.js +194 -0
  73. package/dist/cli/pageSemantics.js.map +1 -0
  74. package/dist/cli/parseArgs.d.ts +6 -18
  75. package/dist/cli/parseArgs.d.ts.map +1 -1
  76. package/dist/cli/parseArgs.js +689 -45
  77. package/dist/cli/parseArgs.js.map +1 -1
  78. package/dist/cli/protocol.d.ts +8 -0
  79. package/dist/cli/protocol.d.ts.map +1 -1
  80. package/dist/cli/sessionRegistry.d.ts +42 -0
  81. package/dist/cli/sessionRegistry.d.ts.map +1 -0
  82. package/dist/cli/sessionRegistry.js +99 -0
  83. package/dist/cli/sessionRegistry.js.map +1 -0
  84. package/dist/cli/snapshot.d.ts +100 -18
  85. package/dist/cli/snapshot.d.ts.map +1 -1
  86. package/dist/cli/snapshot.js +248 -102
  87. package/dist/cli/snapshot.js.map +1 -1
  88. package/dist/cli/stateStore.d.ts +50 -0
  89. package/dist/cli/stateStore.d.ts.map +1 -0
  90. package/dist/cli/stateStore.js +122 -0
  91. package/dist/cli/stateStore.js.map +1 -0
  92. package/dist/index.d.ts +1 -1
  93. package/dist/index.d.ts.map +1 -1
  94. package/dist/index.js.map +1 -1
  95. package/dist/lib/bidi/index.d.ts +1 -1
  96. package/dist/lib/bidi/index.d.ts.map +1 -1
  97. package/dist/lib/bidi/index.js +2 -2
  98. package/dist/lib/bidi/index.js.map +1 -1
  99. package/dist/lib/bidi/logs.d.ts +3 -0
  100. package/dist/lib/bidi/logs.d.ts.map +1 -1
  101. package/dist/lib/bidi/logs.js +7 -0
  102. package/dist/lib/bidi/logs.js.map +1 -1
  103. package/dist/lib/bidi/network.d.ts +14 -1
  104. package/dist/lib/bidi/network.d.ts.map +1 -1
  105. package/dist/lib/bidi/network.js +45 -7
  106. package/dist/lib/bidi/network.js.map +1 -1
  107. package/dist/lib/bidi/storage.d.ts +30 -6
  108. package/dist/lib/bidi/storage.d.ts.map +1 -1
  109. package/dist/lib/bidi/storage.js +190 -45
  110. package/dist/lib/bidi/storage.js.map +1 -1
  111. package/dist/lib/bidi/types.d.ts +7 -2
  112. package/dist/lib/bidi/types.d.ts.map +1 -1
  113. package/dist/lib/browser.d.ts +6 -3
  114. package/dist/lib/browser.d.ts.map +1 -1
  115. package/dist/lib/browser.js +140 -30
  116. package/dist/lib/browser.js.map +1 -1
  117. package/dist/lib/browserContext.d.ts +54 -18
  118. package/dist/lib/browserContext.d.ts.map +1 -1
  119. package/dist/lib/browserContext.js +295 -92
  120. package/dist/lib/browserContext.js.map +1 -1
  121. package/dist/lib/by.d.ts +3 -3
  122. package/dist/lib/by.d.ts.map +1 -1
  123. package/dist/lib/by.js +7 -3
  124. package/dist/lib/by.js.map +1 -1
  125. package/dist/lib/driver.d.ts +7 -0
  126. package/dist/lib/driver.d.ts.map +1 -1
  127. package/dist/lib/driver.js +12 -0
  128. package/dist/lib/driver.js.map +1 -1
  129. package/dist/lib/errors.d.ts +8 -0
  130. package/dist/lib/errors.d.ts.map +1 -1
  131. package/dist/lib/errors.js +8 -0
  132. package/dist/lib/errors.js.map +1 -1
  133. package/dist/lib/initScript.d.ts +9 -0
  134. package/dist/lib/initScript.d.ts.map +1 -0
  135. package/dist/lib/initScript.js +14 -0
  136. package/dist/lib/initScript.js.map +1 -0
  137. package/dist/lib/page.d.ts +22 -0
  138. package/dist/lib/page.d.ts.map +1 -1
  139. package/dist/lib/page.js +48 -0
  140. package/dist/lib/page.js.map +1 -1
  141. package/dist/lib/secureFile.d.ts +8 -0
  142. package/dist/lib/secureFile.d.ts.map +1 -0
  143. package/dist/lib/secureFile.js +67 -0
  144. package/dist/lib/secureFile.js.map +1 -0
  145. package/dist/lib/sessionStateValidation.d.ts +35 -0
  146. package/dist/lib/sessionStateValidation.d.ts.map +1 -0
  147. package/dist/lib/sessionStateValidation.js +223 -0
  148. package/dist/lib/sessionStateValidation.js.map +1 -0
  149. package/dist/lib/tracing.d.ts +2 -1
  150. package/dist/lib/tracing.d.ts.map +1 -1
  151. package/dist/lib/tracing.js +12 -1
  152. package/dist/lib/tracing.js.map +1 -1
  153. package/docs/agents.md +56 -61
  154. package/docs/api-reference.md +2 -1
  155. package/docs/browser-api.md +24 -4
  156. package/docs/browser-context.md +18 -12
  157. package/docs/cli.md +346 -26
  158. package/docs/error-codes.md +5 -4
  159. package/docs/getting-started.md +6 -1
  160. package/docs/index.md +1 -1
  161. package/docs/mcp.md +129 -62
  162. package/docs/public/examples/agent-actions.html +48 -0
  163. package/docs/public/examples/agent-debug.html +86 -0
  164. package/docs/public/examples/agent-late-mutation.html +18 -0
  165. package/docs/public/examples/agent-ref-shift.html +33 -0
  166. package/docs/recipes/login-once-reuse-session.md +32 -4
  167. package/docs/session-management.md +64 -3
  168. package/docs/why-craftdriver.md +1 -1
  169. package/package.json +3 -1
  170. package/skills/craftdriver/SKILL.md +59 -75
  171. package/skills/craftdriver/agents/openai.yaml +4 -0
  172. package/skills/craftdriver/cheatsheet.md +18 -4
  173. package/skills/craftdriver/cli.md +194 -68
  174. package/skills/craftdriver/patterns.md +14 -8
  175. package/skills/craftdriver/workflow.md +149 -0
@@ -1,182 +1,317 @@
1
1
  /**
2
- * MCP server — JSON-RPC 2.0 over stdio.
2
+ * MCP server — JSON-RPC 2.0 over newline-delimited stdio.
3
3
  *
4
- * Hand-rolled because the spec we use (initialize / tools/list /
5
- * tools/call) is ~6 methods, and pulling `@modelcontextprotocol/sdk`
6
- * would multiply our runtime-dep footprint. If the spec grows we can
7
- * swap in the SDK without changing tool definitions in `tools.ts`.
8
- *
9
- * Protocol version we advertise: 2024-11-05. If the client offers a
10
- * newer one we just echo theirs back — the methods we implement are
11
- * stable across versions to date.
12
- *
13
- * Lifecycle:
14
- * client → initialize → server returns capabilities + info
15
- * client → notifications/initialized (no response)
16
- * client ⇆ tools/list, tools/call, ...
17
- * stdin EOF (or SIGINT/SIGTERM) → close browser, exit 0
4
+ * The protocol functions in this module only decode, classify, route, and
5
+ * render messages. Browser commands always execute through AgentSession.
18
6
  */
19
- import { Browser } from '../../lib/browser.js';
7
+ import { readFileSync } from 'node:fs';
8
+ import { dirname, resolve as resolvePath } from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
20
10
  import { assertLocalOnlyLaunch } from '../../lib/launchTarget.js';
21
11
  import { CraftdriverError, ErrorCode } from '../../lib/errors.js';
22
- import { createBrowserHandle } from '../dispatcher.js';
23
- import { TOOLS, getTool, runTool } from './tools.js';
24
- import { renderDelta, renderFull, takeSnapshot } from '../snapshot.js';
25
- import { ArtifactStore, resolveSpillBytes, spillPreview, } from './artifacts.js';
26
- const PROTOCOL_VERSION = '2024-11-05';
12
+ import { AgentSession, } from '../agentSession.js';
13
+ import { TOOLS, getTool, inputSchemaFor, validateToolArgs, runToolDetailed, } from './tools.js';
14
+ import { renderFull } from '../snapshot.js';
15
+ import { BoundedLineReader, MAX_FRAME_BYTES } from '../lineReader.js';
16
+ import { boundToolResult, resolveMaxResponseBytes, truncateUtf8 } from './bounds.js';
17
+ import { ArtifactStore, ArtifactQuotaError, resolveSpillBytes, spillPreview, } from './artifacts.js';
18
+ /**
19
+ * Protocol versions this server has actually been tested against, newest
20
+ * first. Negotiation picks from this list and never echoes an unknown
21
+ * requested version: claiming to speak a revision nobody verified is how a
22
+ * client ends up relying on behaviour that was never implemented.
23
+ */
24
+ const SUPPORTED_PROTOCOL_VERSIONS = ['2025-06-18', '2025-03-26', '2024-11-05'];
25
+ const PROTOCOL_VERSION = SUPPORTED_PROTOCOL_VERSIONS[SUPPORTED_PROTOCOL_VERSIONS.length - 1];
27
26
  const SERVER_NAME = 'craftdriver';
28
- const SERVER_VERSION = '0.1.0';
27
+ /**
28
+ * Read from the installed package rather than a hand-maintained constant,
29
+ * which had drifted to 0.1.0 against a 1.7.0 package — so every client was
30
+ * told the wrong server version.
31
+ */
32
+ function readServerVersion() {
33
+ try {
34
+ const here = dirname(fileURLToPath(import.meta.url));
35
+ // dist/cli/mcp/server.js and src/cli/mcp/server.ts are both three levels
36
+ // below the package root.
37
+ const pkg = JSON.parse(readFileSync(resolvePath(here, '..', '..', '..', 'package.json'), 'utf8'));
38
+ return typeof pkg.version === 'string' && pkg.version.length > 0 ? pkg.version : '0.0.0';
39
+ }
40
+ catch {
41
+ return '0.0.0';
42
+ }
43
+ }
44
+ const SERVER_VERSION = readServerVersion();
45
+ /**
46
+ * Choose the protocol version to answer with.
47
+ *
48
+ * A client asking for a version we support gets it. Anything else — unknown,
49
+ * malformed, or missing — gets our default, which the spec allows and which
50
+ * is honest about what this server actually implements.
51
+ */
52
+ export function negotiateProtocolVersion(requested) {
53
+ return typeof requested === 'string' &&
54
+ SUPPORTED_PROTOCOL_VERSIONS.includes(requested)
55
+ ? requested
56
+ : PROTOCOL_VERSION;
57
+ }
58
+ /** Maximum UTF-8 payload for one MCP JSON line. Shared with the daemon. */
59
+ export const MCP_MAX_FRAME_BYTES = MAX_FRAME_BYTES;
60
+ /** Decode exactly one JSON value after newline framing has completed. */
61
+ export function decodeJsonLine(line) {
62
+ return JSON.parse(line);
63
+ }
64
+ /** Classify by presence of an `id`; validation remains a separate concern. */
65
+ export function classifyJsonRpcMessage(value) {
66
+ const message = value;
67
+ return {
68
+ kind: Object.prototype.hasOwnProperty.call(message, 'id')
69
+ ? 'request'
70
+ : 'notification',
71
+ message,
72
+ };
73
+ }
74
+ export function serializeJsonRpcResponse(response) {
75
+ return JSON.stringify(response) + '\n';
76
+ }
77
+ export function sendJsonRpcResponse(output, response) {
78
+ output.write(serializeJsonRpcResponse(response));
79
+ }
29
80
  export async function runMcpServer(opts) {
30
81
  // The MCP server is a local dev tool only — never reachable against a
31
82
  // Grid/cloud. Fail fast at startup, not on first browser use.
32
83
  assertLocalOnlyLaunch(opts.launch);
33
84
  const input = opts.input ?? process.stdin;
34
85
  const output = opts.output ?? process.stdout;
35
- const handle = createBrowserHandle(() => Browser.launch(opts.launch));
36
- const ctx = { handle, launchOptions: opts.launch };
37
- // Snapshot state: one most-recent snapshot per session for diffing.
38
- let lastSnapshot = null;
39
- const snapshotsOn = opts.snapshot !== 'none';
40
- // Artifact store: large content blocks spill here so they don't burn
41
- // context tokens on every turn.
42
- const artifacts = new ArtifactStore(opts.artifactsDir);
43
- const spillBytes = opts.spillBytes ?? resolveSpillBytes();
44
- function send(msg) {
45
- output.write(JSON.stringify(msg) + '\n');
46
- }
47
- async function handleRequest(req) {
48
- const id = req.id ?? null;
49
- try {
50
- switch (req.method) {
51
- case 'initialize':
52
- return ok(id, {
53
- protocolVersion: req.params?.protocolVersion ?? PROTOCOL_VERSION,
54
- capabilities: { tools: {} },
55
- serverInfo: { name: SERVER_NAME, version: SERVER_VERSION },
56
- instructions: 'craftdriver browser automation. Probe selectors with browser_exists ' +
57
- 'before acting; errors carry a stable `code` field; the post-action ' +
58
- 'a11y snapshot diff tells you what changed.',
59
- });
60
- case 'notifications/initialized':
61
- return null; // notification — no response
62
- case 'ping':
63
- return ok(id, {});
64
- case 'tools/list':
65
- return ok(id, {
66
- tools: TOOLS.map((t) => ({
67
- name: t.name,
68
- description: t.description,
69
- inputSchema: t.inputSchema,
70
- })),
71
- });
72
- case 'tools/call': {
73
- const name = req.params?.name;
74
- const args = req.params?.arguments ?? {};
75
- if (!name)
76
- return rpcError(id, -32602, 'tools/call: missing "name"');
77
- const tool = getTool(name);
78
- if (!tool) {
79
- return ok(id, toolError(`unknown tool: ${name}`, ErrorCode.INVALID_ARGUMENT));
80
- }
81
- const result = await callTool(ctx, tool, args, {
82
- snapshotsOn,
83
- getPrev: () => lastSnapshot,
84
- setLast: (s) => {
85
- lastSnapshot = s;
86
- },
87
- artifacts,
88
- spillBytes,
89
- });
90
- return ok(id, result);
91
- }
92
- case 'resources/list':
93
- // Resources land with Item 7 (trace summaries). Empty list now
94
- // keeps clients that probe for resource capability happy.
95
- return ok(id, { resources: [] });
96
- default:
97
- return rpcError(id, -32601, `method not found: ${req.method}`);
86
+ const signalSource = opts.signalSource ?? process;
87
+ const session = opts.sessionFactory?.() ?? new AgentSession({
88
+ launchOptions: opts.launch,
89
+ autoSnapshot: opts.snapshot !== 'none',
90
+ });
91
+ const router = {
92
+ session,
93
+ snapshotState: {
94
+ snapshotsOn: opts.snapshot !== 'none',
95
+ artifacts: new ArtifactStore(opts.artifactsDir),
96
+ spillBytes: opts.spillBytes ?? resolveSpillBytes(),
97
+ maxResponseBytes: opts.maxResponseBytes ?? resolveMaxResponseBytes(),
98
+ },
99
+ };
100
+ const reader = new BoundedLineReader();
101
+ const pending = new Set();
102
+ let routeTail = Promise.resolve();
103
+ let accepting = true;
104
+ const trackMessage = (classified) => {
105
+ const route = async () => {
106
+ const response = await routeJsonRpcMethod(classified, router);
107
+ if (response)
108
+ sendJsonRpcResponse(output, response);
109
+ };
110
+ const isToolCall = classified.message.method === 'tools/call';
111
+ const task = isToolCall ? routeTail.then(route) : route();
112
+ if (isToolCall)
113
+ routeTail = task.catch(() => undefined);
114
+ pending.add(task);
115
+ void task.then(() => pending.delete(task), () => pending.delete(task));
116
+ };
117
+ const onData = (chunk) => {
118
+ if (!accepting)
119
+ return;
120
+ for (const event of reader.push(chunk)) {
121
+ if (event.kind === 'oversized') {
122
+ sendJsonRpcResponse(output, rpcError(null, -32700, `input frame exceeds ${MCP_MAX_FRAME_BYTES}-byte limit`));
123
+ continue;
98
124
  }
99
- }
100
- catch (e) {
101
- return rpcError(id, -32000, e.message ?? String(e));
102
- }
103
- }
104
- // Line-delimited JSON over stdin. Tolerate \r\n and trailing whitespace.
105
- let buf = '';
106
- input.setEncoding?.('utf8');
107
- input.on('data', (chunk) => {
108
- buf += typeof chunk === 'string' ? chunk : chunk.toString('utf8');
109
- let nl;
110
- while ((nl = buf.indexOf('\n')) !== -1) {
111
- const line = buf.slice(0, nl).trim();
112
- buf = buf.slice(nl + 1);
125
+ const line = event.line.trim();
113
126
  if (!line)
114
127
  continue;
115
- let parsed;
116
128
  try {
117
- parsed = JSON.parse(line);
129
+ trackMessage(classifyJsonRpcMessage(decodeJsonLine(line)));
118
130
  }
119
131
  catch {
120
- send({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'parse error' } });
121
- continue;
132
+ sendJsonRpcResponse(output, rpcError(null, -32700, 'parse error'));
122
133
  }
123
- // Run async; responses may interleave but each carries its own id.
124
- void handleRequest(parsed).then((resp) => {
125
- if (resp)
126
- send(resp);
127
- });
128
134
  }
135
+ };
136
+ input.setEncoding?.('utf8');
137
+ input.on('data', onData);
138
+ let finish;
139
+ const stopped = new Promise((resolve) => {
140
+ finish = resolve;
129
141
  });
130
- await new Promise((resolve) => {
131
- const done = () => resolve();
132
- input.once('end', done);
133
- input.once('close', done);
134
- process.once('SIGINT', done);
135
- process.once('SIGTERM', done);
136
- });
137
- await handle.close();
142
+ let stopping = false;
143
+ const stop = () => {
144
+ if (stopping)
145
+ return;
146
+ stopping = true;
147
+ accepting = false;
148
+ finish();
149
+ };
150
+ input.once('end', stop);
151
+ input.once('close', stop);
152
+ signalSource.once('SIGINT', stop);
153
+ signalSource.once('SIGTERM', stop);
154
+ try {
155
+ await stopped;
156
+ await Promise.allSettled([...pending]);
157
+ }
158
+ finally {
159
+ input.removeListener('data', onData);
160
+ input.removeListener('end', stop);
161
+ input.removeListener('close', stop);
162
+ signalSource.off('SIGINT', stop);
163
+ signalSource.off('SIGTERM', stop);
164
+ await session.close();
165
+ }
166
+ }
167
+ export async function routeJsonRpcMethod(classified, ctx) {
168
+ const req = classified.message;
169
+ const id = req.id ?? null;
170
+ // JSON-RPC forbids replying to a notification. Only `notifications/
171
+ // initialized` was handled explicitly, so every other notification fell
172
+ // through to the method-not-found default and got an unsolicited
173
+ // `id: null` error frame — which strict MCP clients treat as a protocol
174
+ // violation. Silence is the correct response to all of them.
175
+ if (classified.kind === 'notification')
176
+ return null;
177
+ try {
178
+ switch (req.method) {
179
+ case 'initialize':
180
+ return ok(id, {
181
+ protocolVersion: negotiateProtocolVersion(req.params?.protocolVersion),
182
+ capabilities: { tools: {} },
183
+ serverInfo: { name: SERVER_NAME, version: SERVER_VERSION },
184
+ instructions: 'craftdriver browser automation. Probe selectors with browser_exists ' +
185
+ 'before acting; errors carry a stable `code` field; the post-action ' +
186
+ 'a11y snapshot diff tells you what changed.',
187
+ });
188
+ case 'ping':
189
+ return ok(id, {});
190
+ case 'tools/list':
191
+ return ok(id, {
192
+ tools: TOOLS.map((tool) => ({
193
+ name: tool.name,
194
+ description: tool.description,
195
+ inputSchema: inputSchemaFor(tool),
196
+ annotations: tool.annotations,
197
+ })),
198
+ });
199
+ case 'tools/call': {
200
+ const name = req.params?.name;
201
+ const args = req.params?.arguments ?? {};
202
+ if (!name)
203
+ return rpcError(id, -32602, 'tools/call: missing "name"');
204
+ const tool = getTool(name);
205
+ // A tool that does not exist is a caller mistake about the protocol,
206
+ // not a browser failure, so it is a JSON-RPC error rather than a
207
+ // successful result carrying isError. Normal action failures — a
208
+ // missing element, a timeout — stay successful results.
209
+ if (!tool)
210
+ return rpcError(id, -32602, `tools/call: unknown tool "${name}"`);
211
+ let validated;
212
+ try {
213
+ // Validate before the session queue: a malformed call should not
214
+ // wait behind a slow browser action to be told it was malformed,
215
+ // and nothing invalid should reach the dispatcher at all.
216
+ validated = validateToolArgs(tool, args);
217
+ }
218
+ catch (error) {
219
+ const message = error instanceof Error ? error.message : String(error);
220
+ return rpcError(id, -32602, message, {
221
+ ...(error instanceof CraftdriverError && error.detail ? { detail: error.detail } : {}),
222
+ });
223
+ }
224
+ try {
225
+ const invocation = await invokeTool(ctx.session, tool, validated, ctx.snapshotState);
226
+ return ok(id, await serializeToolSuccess(tool, invocation.value, {
227
+ artifacts: ctx.snapshotState.artifacts,
228
+ spillBytes: ctx.snapshotState.spillBytes,
229
+ delta: invocation.delta,
230
+ maxResponseBytes: ctx.snapshotState.maxResponseBytes,
231
+ }));
232
+ }
233
+ catch (error) {
234
+ return ok(id, serializeToolFailure(error, ctx.snapshotState.maxResponseBytes));
235
+ }
236
+ }
237
+ case 'resources/list':
238
+ return ok(id, { resources: [] });
239
+ default:
240
+ return rpcError(id, -32601, `method not found: ${req.method}`);
241
+ }
242
+ }
243
+ catch (error) {
244
+ return rpcError(id, -32000, error.message ?? String(error));
245
+ }
138
246
  }
139
- async function callTool(ctx, tool, args, snap) {
140
- // Screenshot path allocation: if the caller didn't supply a path,
141
- // give them one inside the artifact directory so the PNG bytes are
142
- // actually persisted somewhere they can read.
143
- if (tool.name === 'browser_screenshot' && !args.path) {
144
- args = { ...args, path: await snap.artifacts.allocate('screenshot.png') };
247
+ async function invokeTool(session, tool, inputArgs, snapshotState) {
248
+ let args = inputArgs;
249
+ let screenshotPath;
250
+ if (tool.name === 'browser_screenshot') {
251
+ // Always server-allocated. The tool takes no destination, so this is the
252
+ // only path a screenshot can land on, which is what its description says.
253
+ screenshotPath = await snapshotState.artifacts.allocate('screenshot.png');
254
+ args = {
255
+ ...args,
256
+ path: screenshotPath,
257
+ };
145
258
  }
146
- let value;
259
+ // The session captures the post-action snapshot in the same operation
260
+ // as the action, against the one baseline explicit snapshots also
261
+ // advance. The adapter renders that result; it never owns a second one.
262
+ let detailed;
147
263
  try {
148
- value = await runTool(ctx, tool, args);
264
+ detailed = await runToolDetailed(session, tool, args);
265
+ if (screenshotPath)
266
+ await snapshotState.artifacts.commitAllocated(screenshotPath);
149
267
  }
150
- catch (e) {
151
- if (e instanceof CraftdriverError) {
152
- return toolError(e.message, e.code, e.hint, compactErrorDetail(e.detail));
153
- }
154
- return toolError(e.message ?? String(e), ErrorCode.DRIVER_ERROR);
268
+ catch (error) {
269
+ if (screenshotPath)
270
+ await snapshotState.artifacts.releaseAllocated(screenshotPath);
271
+ throw error;
155
272
  }
273
+ if (!snapshotState.snapshotsOn)
274
+ return { value: detailed.value };
275
+ return { value: detailed.value, ...(detailed.delta ? { delta: detailed.delta } : {}) };
276
+ }
277
+ /** Render an already-computed tool value without invoking browser work. */
278
+ export async function serializeToolSuccess(tool, value, ctx) {
156
279
  const content = [];
157
- // Render result. The snapshot tool returns a structured shape we
158
- // know how to print compactly; everything else falls through to
159
- // the generic summariser. Both paths run through `maybeSpill` so
160
- // large payloads land on disk instead of in the context window.
161
280
  let primaryText;
162
- if (tool.name === 'browser_snapshot' && value && typeof value === 'object' && 'lines' in value) {
163
- primaryText = await maybeSpill(renderFull(value), 'snapshot.txt', snap.artifacts, snap.spillBytes);
281
+ if (tool.name === 'browser_snapshot' &&
282
+ value &&
283
+ typeof value === 'object' &&
284
+ 'lines' in value) {
285
+ primaryText = await maybeSpill(renderFull(value), 'snapshot.txt', ctx.artifacts, ctx.spillBytes);
164
286
  }
165
287
  else {
166
- primaryText = await summariseValue(tool.name, value, snap.artifacts, snap.spillBytes);
288
+ primaryText = await summariseValue(tool.name, value, ctx.artifacts, ctx.spillBytes);
167
289
  }
168
290
  content.push({ type: 'text', text: primaryText });
169
- // Post-action a11y diff, when this tool changed page state.
170
- if (tool.mutating && snap.snapshotsOn) {
171
- const next = await takeSnapshot(await ctx.handle.get()).catch(() => null);
172
- const delta = renderDelta(snap.getPrev(), next);
173
- if (delta) {
174
- const block = await maybeSpill(delta, 'snapshot.txt', snap.artifacts, snap.spillBytes);
175
- content.push({ type: 'text', text: block });
176
- }
177
- snap.setLast(next);
291
+ if (ctx.delta) {
292
+ content.push({
293
+ type: 'text',
294
+ text: await maybeSpill(ctx.delta, 'snapshot.txt', ctx.artifacts, ctx.spillBytes),
295
+ });
178
296
  }
179
- return { content, structuredContent: { result: value } };
297
+ // Bound the complete response, not just the content blocks. Spilling a
298
+ // large value to an artifact while attaching the same value in full as
299
+ // structuredContent left a 50 KB eval on the wire behind a 514-byte preview.
300
+ return boundToolResult({ content, structuredContent: { result: value } }, ctx.maxResponseBytes ?? resolveMaxResponseBytes());
301
+ }
302
+ /**
303
+ * Render a tool failure without requiring a session or transport.
304
+ *
305
+ * Bounded like a success. An error carries page-derived text — an assertion
306
+ * message quoting a whole element, a driver error echoing a selector — so
307
+ * leaving the failure path unbounded left the envelope cap trivially
308
+ * bypassable by whatever the page put in the message.
309
+ */
310
+ export function serializeToolFailure(error, maxResponseBytes = resolveMaxResponseBytes()) {
311
+ const result = error instanceof CraftdriverError
312
+ ? toolError(error.message, error.code, error.hint, compactErrorDetail(error.detail))
313
+ : toolError(error?.message ?? String(error), ErrorCode.DRIVER_ERROR);
314
+ return boundToolResult(result, maxResponseBytes);
180
315
  }
181
316
  async function summariseValue(toolName, value, artifacts, spillBytes) {
182
317
  if (value === null || value === undefined)
@@ -188,8 +323,17 @@ async function maybeSpill(text, nameHint, artifacts, spillBytes) {
188
323
  const size = Buffer.byteLength(text, 'utf8');
189
324
  if (size <= spillBytes)
190
325
  return text;
191
- const written = await artifacts.write(nameHint, text);
192
- return spillPreview(text, written);
326
+ try {
327
+ const written = await artifacts.write(nameHint, text);
328
+ return spillPreview(text, written);
329
+ }
330
+ catch (error) {
331
+ if (!(error instanceof ArtifactQuotaError))
332
+ throw error;
333
+ // A full artifact store must not fail the command the agent asked for.
334
+ // Fall back to an inline value; the envelope bound trims it either way.
335
+ return truncateUtf8(text, spillBytes) + `\n… (truncated — ${error.message})`;
336
+ }
193
337
  }
194
338
  function safeJson(value) {
195
339
  try {
@@ -225,7 +369,17 @@ function toolError(message, code, hint, detail) {
225
369
  function ok(id, result) {
226
370
  return { jsonrpc: '2.0', id, result };
227
371
  }
228
- function rpcError(id, code, message) {
229
- return { jsonrpc: '2.0', id, error: { code, message } };
372
+ function rpcError(id, code, message, extra) {
373
+ return {
374
+ jsonrpc: '2.0',
375
+ id,
376
+ error: {
377
+ code,
378
+ message,
379
+ // `data` carries the machine-readable part (which field, what was
380
+ // allowed) so a client need not parse the message to correct itself.
381
+ ...(extra?.detail !== undefined ? { data: extra.detail } : {}),
382
+ },
383
+ };
230
384
  }
231
385
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/cli/mcp/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,OAAO,EAAsB,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAwB,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAgB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CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9B,CAAC;IACF,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnD,iBAAiB,EAAE,EAAE,KAAK,EAAE;KAC7B,CAAC;AACJ,CAAC;AAED,SAAS,EAAE,CAAC,EAA0B,EAAE,MAAe;IACrD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;AACxC,CAAC;AAED,SAAS,QAAQ,CACf,EAA0B,EAC1B,IAAY,EACZ,OAAe,EACf,KAA4B;IAE5B,OAAO;QACL,OAAO,EAAE,KAAK;QACd,EAAE;QACF,KAAK,EAAE;YACL,IAAI;YACJ,OAAO;YACP,kEAAkE;YAClE,qEAAqE;YACrE,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/D;KACF,CAAC;AACJ,CAAC"}
@@ -1,33 +1,78 @@
1
1
  /**
2
2
  * MCP tool registry.
3
3
  *
4
- * Each tool: a JSON Schema for the model + a thin handler that maps
5
- * the arguments onto the existing dispatcher. The dispatcher already
6
- * speaks `{ cmd, args }` and throws `CraftdriverError` with stable
7
- * codes — we reuse it untouched so library, CLI, and MCP all behave
8
- * identically when given the same selector.
4
+ * Each tool is a parameter descriptor plus a thin mapping onto an existing
5
+ * dispatcher command. Three rules keep this an adapter rather than a second
6
+ * implementation:
9
7
  *
10
- * Compact set per §6 of the AI-productivity plan: ~12 tools, one-line
11
- * descriptions and merged variants behind options.
8
+ * - **No MCP-only browser semantics.** Every tool dispatches a command the CLI
9
+ * also has, with the same arguments. Where the CLI command takes an `action`,
10
+ * the tool does too — mirroring its shape rather than inventing a nicer one
11
+ * is what keeps the two from drifting.
12
+ * - **One declaration per argument.** `params` produces both the advertised
13
+ * `inputSchema` and the runtime validation, so a tool cannot promise a
14
+ * constraint it does not enforce.
15
+ * - **Whether an action mutates the page is not declared here.** The
16
+ * dispatcher's `MUTATING` set decides, and the presence of a post-action
17
+ * delta is the only signal. A per-tool flag was a second source of truth
18
+ * once already: it marked `browser_advanced_eval` mutating while the
19
+ * dispatcher did not, so the one tool that can rewrite a page never
20
+ * reported its changes.
21
+ *
22
+ * The set is kept deliberately smaller than the CLI's command list. Every tool
23
+ * costs context in `tools/list` on every agent turn, so element actions that
24
+ * share a signature are grouped behind one `action` argument instead of
25
+ * becoming seven tools.
12
26
  */
13
- import type { DispatchContext } from '../dispatcher.js';
27
+ import type { AgentDetailedResult, AgentSessionRunner } from '../agentSession.js';
28
+ import { type ParamSpecs } from './params.js';
29
+ /**
30
+ * MCP tool annotations.
31
+ *
32
+ * Accuracy matters more than completeness here: a client may use these to
33
+ * decide what to auto-approve, so a wrong `readOnlyHint` is worse than an
34
+ * absent one.
35
+ */
36
+ export interface ToolAnnotations {
37
+ title: string;
38
+ /** Does not change the page or any persistent state. */
39
+ readOnlyHint: boolean;
40
+ /** May destroy state a user would not want destroyed. */
41
+ destructiveHint: boolean;
42
+ /** Repeating the call with the same arguments changes nothing further. */
43
+ idempotentHint: boolean;
44
+ /** Interacts with the outside world (the web, the filesystem). */
45
+ openWorldHint: boolean;
46
+ }
14
47
  export interface ToolDef {
15
48
  name: string;
16
49
  description: string;
17
- /** JSON Schema, restricted to types MCP clients reliably support. */
18
- inputSchema: Record<string, unknown>;
19
- /** Map MCP args → dispatcher args. Defaults to identity. */
50
+ params: ParamSpecs;
51
+ annotations: ToolAnnotations;
52
+ /** Map validated MCP args → dispatcher args. */
20
53
  toDispatch: (args: Record<string, unknown>) => {
21
54
  cmd: string;
22
55
  args: Record<string, unknown>;
23
56
  };
24
- /** When true, this action mutates page state — caller should take a snapshot. */
25
- mutating: boolean;
26
- /** When true, the result includes binary content (image bytes). */
27
- returnsImage?: boolean;
28
57
  }
29
58
  export declare const TOOLS: ToolDef[];
30
59
  export declare function getTool(name: string): ToolDef | undefined;
31
- /** Run a tool against the dispatcher. Throws CraftdriverError on failure. */
32
- export declare function runTool(ctx: DispatchContext, tool: ToolDef, args: Record<string, unknown>): Promise<unknown>;
60
+ /** The advertised schema for a tool, derived from its parameter descriptor. */
61
+ export declare function inputSchemaFor(tool: ToolDef): Record<string, unknown>;
62
+ /**
63
+ * Validate arguments against the tool's descriptor.
64
+ *
65
+ * Separate from dispatch so the server can reject before touching the session
66
+ * queue: an invalid call should not wait behind a slow browser action to be
67
+ * told it was malformed.
68
+ */
69
+ export declare function validateToolArgs(tool: ToolDef, args: unknown): Record<string, unknown>;
70
+ /** Map a tool to a dispatcher command and run it through the shared session. */
71
+ export declare function runTool(session: AgentSessionRunner, tool: ToolDef, args: Record<string, unknown>): Promise<unknown>;
72
+ /**
73
+ * As {@link runTool}, but keeps the post-action snapshot the session captured
74
+ * in the same operation. The MCP adapter renders that as the second content
75
+ * block; it does not compute or own it.
76
+ */
77
+ export declare function runToolDetailed(session: AgentSessionRunner, tool: ToolDef, args: Record<string, unknown>): Promise<AgentDetailedResult>;
33
78
  //# sourceMappingURL=tools.d.ts.map