Skip to content

Chrome DevTools for coding agents

fix: surface WebMCP tool exceptions in execute_webmcp_tool (#3107)

François Beaufortd80d22ef512a
diff --git a/src/McpPage.ts b/src/McpPage.ts
index 22d8538c..c73920d4 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/src/tools/webmcp.ts b/src/tools/webmcp.ts
index 61600762..2adf85a9 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/McpPage.test.ts b/tests/McpPage.test.ts
index a341d6f4..00f8d3a0 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();
diff --git a/tests/tools/webmcp.test.ts b/tests/tools/webmcp.test.ts
index 99037810..8fbe01fe 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,
),