Skip to content

Commit 2969ce2

Browse files
Address feedback | part 2
1 parent 74d44bb commit 2969ce2

4 files changed

Lines changed: 70 additions & 71 deletions

File tree

src/McpResponse.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ export class McpResponse implements Response {
381381
return this.#snapshotParams;
382382
}
383383

384+
get listWebMcpTools(): boolean | undefined {
385+
return this.#listWebMcpTools;
386+
}
387+
384388
async handle(
385389
toolName: string,
386390
context: McpContext,

tests/McpResponse.test.js.snapshot

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,25 @@ exports[`webmcp > includes webmcp tools in select_page response 2`] = `
13621362
}
13631363
`;
13641364

1365+
exports[`webmcp > list no webmcp tools if experimentalWebmcp is false 1`] = `
1366+
Successfully navigated to about:blank.
1367+
## Pages
1368+
1: about:blank [selected]
1369+
`;
1370+
1371+
exports[`webmcp > list no webmcp tools if experimentalWebmcp is false 2`] = `
1372+
{
1373+
"message": "Successfully navigated to about:blank.",
1374+
"pages": [
1375+
{
1376+
"id": 1,
1377+
"url": "about:blank",
1378+
"selected": true
1379+
}
1380+
]
1381+
}
1382+
`;
1383+
13651384
exports[`webmcp > list no webmcp tools if there are none 1`] = `
13661385
## WebMCP tools
13671386
No WebMCP tools available.

tests/McpResponse.test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,7 @@ describe('replaceHtmlElementsWithUids', () => {
14591459
describe('webmcp', () => {
14601460
async function testIncludesWebmcpTools(
14611461
t: it.TestContext,
1462+
parseArguments: ParsedArguments,
14621463
handlerAction: (
14631464
response: McpResponse,
14641465
context: McpContext,
@@ -1470,7 +1471,7 @@ describe('webmcp', () => {
14701471
response.setListWebMcpTools();
14711472

14721473
await handlerAction(response, context);
1473-
1474+
14741475
const page = context.getSelectedMcpPage().pptrPage;
14751476
await page.setContent(
14761477
html`<form
@@ -1494,13 +1495,14 @@ describe('webmcp', () => {
14941495
);
14951496
},
14961497
{args: ['--enable-features=WebMCPTesting,DevToolsWebMCPSupport']},
1497-
{experimentalWebmcp: true} as ParsedArguments,
1498+
parseArguments,
14981499
);
14991500
}
15001501

15011502
it('includes webmcp tools in list_pages response', async t => {
15021503
await testIncludesWebmcpTools(
15031504
t,
1505+
{experimentalWebmcp: true} as ParsedArguments,
15041506
async (response, context) => {
15051507
await listPages().handler({params: {}}, response, context);
15061508
},
@@ -1511,6 +1513,7 @@ describe('webmcp', () => {
15111513
it('includes webmcp tools in select_page response', async t => {
15121514
await testIncludesWebmcpTools(
15131515
t,
1516+
{experimentalWebmcp: true} as ParsedArguments,
15141517
async (response, context) => {
15151518
const pageId =
15161519
context.getPageId(context.getSelectedMcpPage().pptrPage) ?? 1;
@@ -1523,6 +1526,7 @@ describe('webmcp', () => {
15231526
it('includes webmcp tools in navigate_page response', async t => {
15241527
await testIncludesWebmcpTools(
15251528
t,
1529+
{experimentalWebmcp: true} as ParsedArguments,
15261530
async (response, context) => {
15271531
await navigatePage.handler(
15281532
{
@@ -1559,4 +1563,22 @@ describe('webmcp', () => {
15591563
{experimentalWebmcp: true} as ParsedArguments,
15601564
);
15611565
});
1566+
1567+
it('list no webmcp tools if experimentalWebmcp is false', async t => {
1568+
await testIncludesWebmcpTools(
1569+
t,
1570+
{experimentalWebmcp: false} as ParsedArguments,
1571+
async (response, context) => {
1572+
await navigatePage.handler(
1573+
{
1574+
params: {type: 'url', url: 'about:blank'},
1575+
page: context.getSelectedMcpPage(),
1576+
},
1577+
response,
1578+
context,
1579+
);
1580+
},
1581+
'navigate_page',
1582+
);
1583+
});
15621584
});

tests/tools/webmcp.test.ts

Lines changed: 23 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,80 +7,34 @@
77
import assert from 'node:assert';
88
import {describe, it} from 'node:test';
99

10-
import type {ParsedArguments} from '../../src/bin/chrome-devtools-mcp-cli-options.js';
11-
import {listWebMcpTools} from '../../src/tools/webmcp.js';
12-
import {getTextContent, html, withMcpContext} from '../utils.js';
10+
import {listPages, navigatePage, selectPage} from '../../src/tools/pages.js';
11+
import {withMcpContext} from '../utils.js';
1312

1413
describe('webmcp', () => {
15-
it('list webmcp tools successfully', async () => {
16-
await withMcpContext(
17-
async (response, context) => {
18-
const page = context.getSelectedMcpPage().pptrPage;
19-
await page.setContent(
20-
html`<form
21-
toolname="test_tool"
22-
tooldescription="A test tool"
23-
></form>`,
24-
);
25-
26-
await listWebMcpTools.handler(
27-
{params: {}, page: context.getSelectedMcpPage()},
28-
response,
29-
context,
30-
);
31-
32-
const formattedResponse = await response.handle('test', context);
33-
const textContent = getTextContent(formattedResponse.content[0]);
34-
assert.match(
35-
textContent,
36-
/name="test_tool", description="A test tool"/,
37-
);
38-
},
39-
{args: ['--enable-features=WebMCPTesting,DevToolsWebMCPSupport']},
40-
{experimentalWebmcp: true} as ParsedArguments,
41-
);
14+
it('list webmcp tools in navigate_page response', async () => {
15+
await withMcpContext(async (response, context) => {
16+
await navigatePage.handler(
17+
{params: {url: 'about:blank'}, page: context.getSelectedMcpPage()},
18+
response,
19+
context,
20+
);
21+
assert.ok(response.listWebMcpTools);
22+
});
4223
});
4324

44-
it('list no webmcp tools if there are none', async () => {
45-
await withMcpContext(
46-
async (response, context) => {
47-
await listWebMcpTools.handler(
48-
{params: {}, page: context.getSelectedMcpPage()},
49-
response,
50-
context,
51-
);
52-
53-
const formattedResponse = await response.handle('test', context);
54-
const textContent = getTextContent(formattedResponse.content[0]);
55-
assert.match(textContent, /No WebMCP tools available/);
56-
},
57-
{args: ['--enable-features=WebMCPTesting,DevToolsWebMCPSupport']},
58-
{experimentalWebmcp: true} as ParsedArguments,
59-
);
25+
it('list webmcp tools in list_pages response', async () => {
26+
await withMcpContext(async (response, context) => {
27+
await listPages().handler({params: {}}, response, context);
28+
assert.ok(response.listWebMcpTools);
29+
});
6030
});
6131

62-
it('does not list webmcp tools if not enabled', async () => {
63-
await withMcpContext(
64-
async (response, context) => {
65-
const page = context.getSelectedMcpPage().pptrPage;
66-
await page.setContent(
67-
html`<form
68-
toolname="test_tool"
69-
tooldescription="A test tool"
70-
></form>`,
71-
);
72-
73-
await listWebMcpTools.handler(
74-
{params: {}, page: context.getSelectedMcpPage()},
75-
response,
76-
context,
77-
);
78-
79-
const formattedResponse = await response.handle('test', context);
80-
const textContent = getTextContent(formattedResponse.content[0]);
81-
assert.ok(!textContent.includes('name="test_tool"'));
82-
},
83-
{args: ['--enable-features=WebMCPTesting,DevToolsWebMCPSupport']},
84-
);
32+
it('list webmcp tools in select_page response', async () => {
33+
await withMcpContext(async (response, context) => {
34+
const pageId =
35+
context.getPageId(context.getSelectedMcpPage().pptrPage) ?? 1;
36+
await selectPage.handler({params: {pageId}}, response, context);
37+
assert.ok(response.listWebMcpTools);
38+
});
8539
});
8640
});

0 commit comments

Comments
 (0)