@@ -1385,7 +1385,7 @@ const setup = (tools, origin) => {
13851385 delete globalThis.__tools; delete globalThis.__origin;
13861386 const page = globalThis, stringify = JSON.stringify, parse = JSON.parse, names = tools.map(t => t.name);
13871387 let executed = [], count = 0;
1388- Object.defineProperty(page, "__take", { value: () => { const taken = stringify(executed); executed = []; return taken; } });
1388+ Object.defineProperty(page, "__take", { value: () => { const taken = stringify({ executed, complete: count <= 128 } ); executed = []; return taken; } });
13891389 page.window = page.self = page;
13901390 page.location = { origin, href: origin + "/" };
13911391 page.console = { log() {}, info() {}, warn() {}, error() {}, debug() {} };
@@ -1413,10 +1413,13 @@ for (const [page, expressions] of pages.entries()) {
14131413 for (const expression of expressions) {
14141414 try {
14151415 run(expression);
1416- } catch {
1416+ } catch (error) {
1417+ if (error?.code === "ERR_SCRIPT_EXECUTION_TIMEOUT") throw error;
14171418 // A page error still keeps the executions that ran before it.
14181419 }
1419- for (const [tool, input] of JSON.parse(run("__take()")))
1420+ const { executed, complete } = JSON.parse(run("__take()"));
1421+ if (!complete) throw new Error("WebMCP replay exceeded 128 tool executions.");
1422+ for (const [tool, input] of executed)
14201423 process.stdout.write(JSON.stringify([page, tool, input]) + "\n");
14211424 }
14221425}` ;
@@ -1443,10 +1446,9 @@ export const executeWebMcp = (
14431446 maxBuffer : 16 * 1024 * 1024 ,
14441447 } ,
14451448 ) ;
1446- // A hung or oversized page keeps what it printed; a child that never started is a harness fault.
1447- const code = ( child . error as NodeJS . ErrnoException | undefined ) ?. code ;
1448- if ( child . error !== undefined && code !== "ETIMEDOUT" && code !== "ENOBUFS" ) throw child . error ;
1449- if ( child . error === undefined && ( child . status !== 0 || child . signal !== null ) ) {
1449+ // An incomplete replay cannot establish that a forbidden tool was never called.
1450+ if ( child . error !== undefined ) throw child . error ;
1451+ if ( child . status !== 0 || child . signal !== null ) {
14501452 throw new Error (
14511453 `WebMCP replay terminated with status ${ child . status } and signal ${ child . signal } .` ,
14521454 ) ;
0 commit comments