Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/McpPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 3 additions & 2 deletions src/tools/webmcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
},
}));
28 changes: 28 additions & 0 deletions tests/McpPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
73 changes: 71 additions & 2 deletions tests/tools/webmcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ describe('webmcp', () => {
id: 'call-1',
status: 'Completed',
output: {ok: true},
errorText: undefined,
});
page.getWebMcpTools.returns([tool]);

Expand All @@ -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,
),
Expand Down
Loading