Skip to content

Commit 348bad2

Browse files
committed
Integrate with network request
1 parent e8ec461 commit 348bad2

File tree

7 files changed

+25
-42
lines changed

7 files changed

+25
-42
lines changed

docs/tool-reference.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,12 @@
255255

256256
### `get_network_request`
257257

258-
**Description:** Gets a network request by URL. You can get all requests by calling [`list_network_requests`](#list_network_requests).
258+
**Description:** Gets a network request by reqid. You can get all requests by calling [`list_network_requests`](#list_network_requests).
259+
Get the request currently selected in the DevTools UI by ommitting reqid
259260

260261
**Parameters:**
261262

262-
- **reqid** (number) **(required)**: The reqid of a request on the page from the listed network requests
263+
- **reqid** (number) _(optional)_: The reqid of the network request. If omitted, looks up the current request selected in DevTools UI.
263264

264265
---
265266

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: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,32 @@ 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(
108+
`Nothing is currently selected in DevTools UI.`,
109+
);
110+
}
111+
}
99112
},
100113
});

tests/McpResponse.test.js.snapshot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ exports[`McpResponse > list pages 1`] = `
8989
exports[`McpResponse > returns correctly formatted snapshot for a simple tree 1`] = `
9090
# test response
9191
## Page content
92-
uid=1_0 RootWebArea "My test page" url="about:blank"
92+
uid=1_0 RootWebArea "My test page"
9393
uid=1_1 button "Click me" focusable focused
9494
uid=1_2 textbox value="Input"
9595

@@ -98,7 +98,7 @@ uid=1_0 RootWebArea "My test page" url="about:blank"
9898
exports[`McpResponse > returns values for textboxes 1`] = `
9999
# test response
100100
## Page content
101-
uid=1_0 RootWebArea "My test page" url="about:blank"
101+
uid=1_0 RootWebArea "My test page"
102102
uid=1_1 StaticText "username"
103103
uid=1_2 textbox "username" focusable focused value="mcp"
104104

@@ -107,7 +107,7 @@ uid=1_0 RootWebArea "My test page" url="about:blank"
107107
exports[`McpResponse > returns verbose snapshot 1`] = `
108108
# test response
109109
## Page content
110-
uid=1_0 RootWebArea "My test page" url="about:blank"
110+
uid=1_0 RootWebArea "My test page"
111111
uid=1_1 ignored
112112
uid=1_2 ignored
113113
uid=1_3 complementary
@@ -123,7 +123,7 @@ Saved snapshot to <file>
123123
`;
124124

125125
exports[`McpResponse > saves snapshot to file 2`] = `
126-
uid=1_0 RootWebArea "My test page" url="about:blank"
126+
uid=1_0 RootWebArea "My test page"
127127
uid=1_1 ignored
128128
uid=1_2 ignored
129129
uid=1_3 complementary

0 commit comments

Comments
 (0)