Skip to content

Commit 74d44bb

Browse files
Address feedback | part 1
1 parent dc50cb9 commit 74d44bb

3 files changed

Lines changed: 206 additions & 5 deletions

File tree

src/McpResponse.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ export class McpResponse implements Response {
236236
}
237237

238238
setListWebMcpTools(): void {
239-
if (this.#args.experimentalWebmcp) {
240-
this.#listWebMcpTools = true;
241-
}
239+
this.#listWebMcpTools = true;
242240
}
243241

244242
setIncludeNetworkRequests(
@@ -498,7 +496,7 @@ export class McpResponse implements Response {
498496
}
499497

500498
let webmcpTools: WebMCPTool[] | undefined;
501-
if (this.#listWebMcpTools) {
499+
if (this.#listWebMcpTools && this.#args.experimentalWebmcp) {
502500
const page = this.#page ?? context.getSelectedMcpPage();
503501
webmcpTools = context.getWebMcpTools(page);
504502
}
@@ -900,7 +898,14 @@ Call ${handleDialog.name} to handle it before continuing.`);
900898
}
901899

902900
if (this.#listWebMcpTools && data.webmcpTools) {
903-
structuredContent.webmcpTools = data.webmcpTools;
901+
structuredContent.webmcpTools = data.webmcpTools.map(
902+
({name, description, inputSchema, annotations}) => ({
903+
name,
904+
description,
905+
inputSchema,
906+
annotations,
907+
}),
908+
);
904909
response.push('## WebMCP tools');
905910
if (data.webmcpTools.length === 0) {
906911
response.push('No WebMCP tools available.');

tests/McpResponse.test.js.snapshot

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,3 +1281,94 @@ exports[`lighthouse > includes lighthouse report paths 2`] = `
12811281
}
12821282
}
12831283
`;
1284+
1285+
exports[`webmcp > includes webmcp tools in list_pages response 1`] = `
1286+
## Pages
1287+
1: about:blank [selected]
1288+
## WebMCP tools
1289+
name="test_tool", description="A test tool", inputSchema={}, annotations=undefined
1290+
`;
1291+
1292+
exports[`webmcp > includes webmcp tools in list_pages response 2`] = `
1293+
{
1294+
"pages": [
1295+
{
1296+
"id": 1,
1297+
"url": "about:blank",
1298+
"selected": true
1299+
}
1300+
],
1301+
"webmcpTools": [
1302+
{
1303+
"name": "test_tool",
1304+
"description": "A test tool",
1305+
"inputSchema": {}
1306+
}
1307+
]
1308+
}
1309+
`;
1310+
1311+
exports[`webmcp > includes webmcp tools in navigate_page response 1`] = `
1312+
Successfully navigated to about:blank.
1313+
## Pages
1314+
1: about:blank [selected]
1315+
## WebMCP tools
1316+
name="test_tool", description="A test tool", inputSchema={}, annotations=undefined
1317+
`;
1318+
1319+
exports[`webmcp > includes webmcp tools in navigate_page response 2`] = `
1320+
{
1321+
"message": "Successfully navigated to about:blank.",
1322+
"pages": [
1323+
{
1324+
"id": 1,
1325+
"url": "about:blank",
1326+
"selected": true
1327+
}
1328+
],
1329+
"webmcpTools": [
1330+
{
1331+
"name": "test_tool",
1332+
"description": "A test tool",
1333+
"inputSchema": {}
1334+
}
1335+
]
1336+
}
1337+
`;
1338+
1339+
exports[`webmcp > includes webmcp tools in select_page response 1`] = `
1340+
## Pages
1341+
1: about:blank [selected]
1342+
## WebMCP tools
1343+
name="test_tool", description="A test tool", inputSchema={}, annotations=undefined
1344+
`;
1345+
1346+
exports[`webmcp > includes webmcp tools in select_page response 2`] = `
1347+
{
1348+
"pages": [
1349+
{
1350+
"id": 1,
1351+
"url": "about:blank",
1352+
"selected": true
1353+
}
1354+
],
1355+
"webmcpTools": [
1356+
{
1357+
"name": "test_tool",
1358+
"description": "A test tool",
1359+
"inputSchema": {}
1360+
}
1361+
]
1362+
}
1363+
`;
1364+
1365+
exports[`webmcp > list no webmcp tools if there are none 1`] = `
1366+
## WebMCP tools
1367+
No WebMCP tools available.
1368+
`;
1369+
1370+
exports[`webmcp > list no webmcp tools if there are none 2`] = `
1371+
{
1372+
"webmcpTools": []
1373+
}
1374+
`;

tests/McpResponse.test.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,3 +1455,108 @@ describe('replaceHtmlElementsWithUids', () => {
14551455
}
14561456
});
14571457
});
1458+
1459+
describe('webmcp', () => {
1460+
async function testIncludesWebmcpTools(
1461+
t: it.TestContext,
1462+
handlerAction: (
1463+
response: McpResponse,
1464+
context: McpContext,
1465+
) => Promise<void>,
1466+
toolName: string,
1467+
) {
1468+
await withMcpContext(
1469+
async (response, context) => {
1470+
response.setListWebMcpTools();
1471+
1472+
await handlerAction(response, context);
1473+
1474+
const page = context.getSelectedMcpPage().pptrPage;
1475+
await page.setContent(
1476+
html`<form
1477+
toolname="test_tool"
1478+
tooldescription="A test tool"
1479+
></form>`,
1480+
);
1481+
1482+
const {content, structuredContent} = await response.handle(
1483+
toolName,
1484+
context,
1485+
);
1486+
assert.ok(getTextContent(content[0]));
1487+
t.assert.snapshot?.(getTextContent(content[0]));
1488+
t.assert.snapshot?.(
1489+
JSON.stringify(
1490+
stabilizeStructuredContent(structuredContent),
1491+
null,
1492+
2,
1493+
),
1494+
);
1495+
},
1496+
{args: ['--enable-features=WebMCPTesting,DevToolsWebMCPSupport']},
1497+
{experimentalWebmcp: true} as ParsedArguments,
1498+
);
1499+
}
1500+
1501+
it('includes webmcp tools in list_pages response', async t => {
1502+
await testIncludesWebmcpTools(
1503+
t,
1504+
async (response, context) => {
1505+
await listPages().handler({params: {}}, response, context);
1506+
},
1507+
'list_pages',
1508+
);
1509+
});
1510+
1511+
it('includes webmcp tools in select_page response', async t => {
1512+
await testIncludesWebmcpTools(
1513+
t,
1514+
async (response, context) => {
1515+
const pageId =
1516+
context.getPageId(context.getSelectedMcpPage().pptrPage) ?? 1;
1517+
await selectPage.handler({params: {pageId}}, response, context);
1518+
},
1519+
'select_page',
1520+
);
1521+
});
1522+
1523+
it('includes webmcp tools in navigate_page response', async t => {
1524+
await testIncludesWebmcpTools(
1525+
t,
1526+
async (response, context) => {
1527+
await navigatePage.handler(
1528+
{
1529+
params: {type: 'url', url: 'about:blank'},
1530+
page: context.getSelectedMcpPage(),
1531+
},
1532+
response,
1533+
context,
1534+
);
1535+
},
1536+
'navigate_page',
1537+
);
1538+
});
1539+
1540+
it('list no webmcp tools if there are none', async t => {
1541+
await withMcpContext(
1542+
async (response, context) => {
1543+
response.setListWebMcpTools();
1544+
const {content, structuredContent} = await response.handle(
1545+
'test',
1546+
context,
1547+
);
1548+
assert.ok(getTextContent(content[0]));
1549+
t.assert.snapshot?.(getTextContent(content[0]));
1550+
t.assert.snapshot?.(
1551+
JSON.stringify(
1552+
stabilizeStructuredContent(structuredContent),
1553+
null,
1554+
2,
1555+
),
1556+
);
1557+
},
1558+
{args: ['--enable-features=WebMCPTesting,DevToolsWebMCPSupport']},
1559+
{experimentalWebmcp: true} as ParsedArguments,
1560+
);
1561+
});
1562+
});

0 commit comments

Comments
 (0)