From 2a7179068d9a6a6276fe7eed2af4c67c1f622cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= Date: Tue, 13 Oct 2026 16:21:24 +0200 Subject: [PATCH 1/2] fix: surface WebMCP tool exceptions in execute_webmcp_tool When a page's WebMCP tool throws, Chrome reports the thrown value in `exception` and leaves `errorText` empty, so the error was lost. Report a single `error` field that prefers the exception description and falls back to `errorText` for non-throw failures. --- src/tools/webmcp.ts | 5 +-- tests/tools/webmcp.test.ts | 73 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/src/tools/webmcp.ts b/src/tools/webmcp.ts index 61600762f9..2adf85a938 100644 --- a/src/tools/webmcp.ts +++ b/src/tools/webmcp.ts @@ -68,9 +68,10 @@ export const executeWebMcpTool = definePageTool(() => ({ throw new Error(`Tool ${toolName} not found`); } - const {status, output, errorText} = await tool.execute(input); + const {status, output, errorText, exception} = await tool.execute(input); + const error = exception?.description ?? exception?.value ?? errorText; response.appendResponseLine( - JSON.stringify({status, output, errorText}, null, 2), + JSON.stringify({status, output, error}, null, 2), ); }, })); diff --git a/tests/tools/webmcp.test.ts b/tests/tools/webmcp.test.ts index 99037810f6..8fbe01fe6e 100644 --- a/tests/tools/webmcp.test.ts +++ b/tests/tools/webmcp.test.ts @@ -144,7 +144,6 @@ describe('webmcp', () => { id: 'call-1', status: 'Completed', output: {ok: true}, - errorText: undefined, }); page.getWebMcpTools.returns([tool]); @@ -162,7 +161,77 @@ describe('webmcp', () => { sinon.assert.calledOnceWithExactly( response.appendResponseLine, JSON.stringify( - {status: 'Completed', output: {ok: true}, errorText: undefined}, + {status: 'Completed', output: {ok: true}, error: undefined}, + null, + 2, + ), + ); + }); + + it('reports the exception description as error when the tool throws', async () => { + const {page, context, response, args} = createHandlerMocks(); + const tool = createMockWebMCPTool({ + name: 'my_tool', + }); + tool.execute.resolves({ + id: 'call-1', + status: 'Error', + exception: { + type: 'object', + subtype: 'error', + className: 'Error', + description: 'Error: boom\n at foo (app.js:1:1)', + objectId: '1', + }, + }); + page.getWebMcpTools.returns([tool]); + + await executeWebMcpTool(args).handler( + { + params: {toolName: 'my_tool'}, + page, + }, + response, + context, + ); + + sinon.assert.calledOnceWithExactly(tool.execute, {}); + sinon.assert.calledOnceWithExactly( + response.appendResponseLine, + JSON.stringify( + {status: 'Error', error: 'Error: boom\n at foo (app.js:1:1)'}, + null, + 2, + ), + ); + }); + + it('reports errorText as error when there is no exception', async () => { + const {page, context, response, args} = createHandlerMocks(); + const tool = createMockWebMCPTool({ + name: 'my_tool', + }); + tool.execute.resolves({ + id: 'call-1', + status: 'Error', + errorText: 'Invalid input arguments', + }); + page.getWebMcpTools.returns([tool]); + + await executeWebMcpTool(args).handler( + { + params: {toolName: 'my_tool'}, + page, + }, + response, + context, + ); + + sinon.assert.calledOnceWithExactly(tool.execute, {}); + sinon.assert.calledOnceWithExactly( + response.appendResponseLine, + JSON.stringify( + {status: 'Error', error: 'Invalid input arguments'}, null, 2, ), From c5400fb7a1422b622e88f2ba1284fbe013566588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= Date: Tue, 13 Oct 2026 17:50:45 +0200 Subject: [PATCH 2/2] fix: surface WebMCP debugging tool exceptions executeThirdPartyDeveloperTool only used errorText, which Chrome leaves empty when the tool throws, so callers always got the generic "Tool execution failed: Error". Prefer the exception description, as execute_webmcp_tool does. --- src/McpPage.ts | 8 ++++++-- tests/McpPage.test.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/McpPage.ts b/src/McpPage.ts index 22d8538c1e..c73920d467 100644 --- a/src/McpPage.ts +++ b/src/McpPage.ts @@ -658,9 +658,13 @@ export class McpPage implements ContextPage { .tools() .find(t => t.name === toolName && isDebuggingWebMcpTool(t)); if (webmcpTool) { - const {status, output, errorText} = await webmcpTool.execute(params); + const {status, output, errorText, exception} = + await webmcpTool.execute(params); if (status !== 'Completed') { - throw new Error(errorText || `Tool execution failed: ${status}`); + const error = exception?.description ?? exception?.value ?? errorText; + throw new Error( + error ? String(error) : `Tool execution failed: ${status}`, + ); } if (output !== undefined) { response.appendResponseLine(JSON.stringify(output, null, 2)); diff --git a/tests/McpPage.test.ts b/tests/McpPage.test.ts index a341d6f468..00f8d3a05f 100644 --- a/tests/McpPage.test.ts +++ b/tests/McpPage.test.ts @@ -1569,6 +1569,34 @@ describe('McpPage', () => { ); }); + it('throws the exception description when the WebMCP tool throws in executeThirdPartyDeveloperTool()', async () => { + const {mcpPage, pptrPage} = await createMcpPage(); + const mockTool = createMockWebMCPTool({ + name: 'webmcp_tool', + annotations: {debugging: true}, + }); + mockTool.execute.resolves({ + id: 'call-1', + status: 'Error', + errorText: '', + exception: { + type: 'object', + subtype: 'error', + className: 'Error', + description: 'Error: boom\n at foo (app.js:1:1)', + objectId: '1', + }, + }); + pptrPage.webmcp.tools.returns([mockTool]); + const response = createMockMcpResponse(); + + await assert.rejects( + () => + mcpPage.executeThirdPartyDeveloperTool('webmcp_tool', {}, response), + {message: 'Error: boom\n at foo (app.js:1:1)'}, + ); + }); + it('excludes debugging WebMCP tools from getWebMcpTools()', async () => { const {mcpPage, pptrPage} = await createMcpPage();