Skip to content

Commit 30cbfce

Browse files
committed
Integrate with network request
1 parent 377aa63 commit 30cbfce

File tree

5 files changed

+41
-28
lines changed

5 files changed

+41
-28
lines changed

src/McpResponse.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,15 @@ export class McpResponse implements Response {
329329
response.push(line);
330330
}
331331

332-
response.push('## Network requests inspected in DevTools');
333-
if (data.devToolsData?.requestId) {
334-
response.push(`Network request: reqid=${data.devToolsData?.requestId}`);
335-
} else {
336-
response.push(
337-
`Nothing inspected right now. Call list_pages to check if anything is selected by the user in DevTools.`,
338-
);
339-
}
332+
// if (data.devToolsData?.requestId) {
333+
// response.push('## Network requests inspected in DevTools');
334+
// response.push(`Network request: reqid=${data.devToolsData?.requestId}`);
335+
// } else {
336+
// response.push('## Network requests inspected in DevTools');
337+
// response.push(
338+
// `Nothing inspected right now. Call list_pages to check if anything is selected by the user in DevTools.`,
339+
// );
340+
// }
340341

341342
const networkConditions = context.getNetworkConditions();
342343
if (networkConditions) {

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from './third_party/index.js';
2222
import {ToolCategory} from './tools/categories.js';
2323
import * as consoleTools from './tools/console.js';
24-
import * as devtoolsTools from './tools/devtools.js';
24+
// import * as devtoolsTools from './tools/devtools.js';
2525
import * as emulationTools from './tools/emulation.js';
2626
import * as inputTools from './tools/input.js';
2727
import * as networkTools from './tools/network.js';
@@ -170,7 +170,7 @@ function registerTool(tool: ToolDefinition): void {
170170

171171
const tools = [
172172
...Object.values(consoleTools),
173-
...Object.values(devtoolsTools),
173+
// ...Object.values(devtoolsTools),
174174
...Object.values(emulationTools),
175175
...Object.values(inputTools),
176176
...Object.values(networkTools),

src/tools/ToolDefinition.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export type Context = Readonly<{
103103
text: string;
104104
timeout?: number | undefined;
105105
}): Promise<Element>;
106+
getDevToolsData(): Promise<undefined | {requestId?: number}>;
106107
}>;
107108

108109
export function defineTool<Schema extends zod.ZodRawShape>(

src/tools/devtools.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {ToolCategory} from './categories.js';
8-
import {defineTool} from './ToolDefinition.js';
7+
// import {ToolCategory} from './categories.js';
8+
// import {defineTool} from './ToolDefinition.js';
99

10-
export const emulateNetwork = defineTool({
11-
name: 'list_devtools_data',
12-
description: `Returns data (network requests) that the user is currently inspecting in DevTools.`,
13-
annotations: {
14-
category: ToolCategory.DEBUGGING,
15-
readOnlyHint: true,
16-
},
17-
schema: {},
18-
handler: async (_request, response, _context) => {
19-
response.includeDevtoolsData(true);
20-
},
21-
});
10+
// export const listDevToolsData = defineTool({
11+
// name: 'list_devtools_data',
12+
// description: `Returns data (network requests) that the user is currently inspecting in DevTools.`,
13+
// annotations: {
14+
// category: ToolCategory.DEBUGGING,
15+
// readOnlyHint: true,
16+
// },
17+
// schema: {},
18+
// handler: async (_request, response, _context) => {
19+
// response.includeDevtoolsData(true);
20+
// },
21+
// });

src/tools/network.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,30 @@ export const listNetworkRequests = defineTool({
8282

8383
export const getNetworkRequest = defineTool({
8484
name: 'get_network_request',
85-
description: `Gets a network request by URL. You can get all requests by calling ${listNetworkRequests.name}.`,
85+
description: `Gets a network request by reqid. You can get all requests by calling ${listNetworkRequests.name}.
86+
Get the request currently selected in the DevTools UI by ommitting reqid`,
8687
annotations: {
8788
category: ToolCategory.NETWORK,
8889
readOnlyHint: true,
8990
},
9091
schema: {
9192
reqid: zod
9293
.number()
94+
.optional()
9395
.describe(
94-
'The reqid of a request on the page from the listed network requests',
96+
'The reqid of the network request. If omitted, looks up the current request selected in DevTools UI.',
9597
),
9698
},
97-
handler: async (request, response, _context) => {
98-
response.attachNetworkRequest(request.params.reqid);
99+
handler: async (request, response, context) => {
100+
if (request.params.reqid) {
101+
response.attachNetworkRequest(request.params.reqid);
102+
} else {
103+
const data = await context.getDevToolsData();
104+
if (data?.requestId) {
105+
response.attachNetworkRequest(data?.requestId);
106+
} else {
107+
response.appendResponseLine(`Nothing is currently selected in DevTools UI.`)
108+
}
109+
}
99110
},
100111
});

0 commit comments

Comments
 (0)