Skip to content

Commit e807815

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

File tree

5 files changed

+16
-36
lines changed

5 files changed

+16
-36
lines changed

src/McpResponse.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,6 @@ 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-
}
340-
341332
const networkConditions = context.getNetworkConditions();
342333
if (networkConditions) {
343334
response.push(`## Network emulation`);

src/main.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ 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';
2524
import * as emulationTools from './tools/emulation.js';
2625
import * as inputTools from './tools/input.js';
2726
import * as networkTools from './tools/network.js';
@@ -170,7 +169,6 @@ function registerTool(tool: ToolDefinition): void {
170169

171170
const tools = [
172171
...Object.values(consoleTools),
173-
...Object.values(devtoolsTools),
174172
...Object.values(emulationTools),
175173
...Object.values(inputTools),
176174
...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: 0 additions & 21 deletions
This file was deleted.

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)