Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/tools/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,19 @@ export const newPage = defineTool({
},
schema: {
url: zod.string().describe('URL to load in a new page.'),
headers: zod
.record(zod.string())
.optional()
.describe('Optional headers to send with the navigation request.'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the headers would be sent for all requests on the page until the headers are removed so this description is not correct. Could you clarify what use case you have? Would #692 work better for the use case? cc @natorion @Lightning00Blade

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we always have an application, which will be test in a prod env.
this test condition, need to divide different with really prod env which user use.
the best way, is to use a special headers

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the #692 send with header in the whole mcp lives.
may be in this, can be more flexible

...timeoutSchema,
},
handler: async (request, response, context) => {
const page = await context.newPage();

if (request.params.headers) {
await page.setExtraHTTPHeaders(request.params.headers);
}

await context.waitForEventsAfterAction(async () => {
await page.goto(request.params.url, {
timeout: request.params.timeout,
Expand All @@ -118,6 +126,10 @@ export const navigatePage = defineTool({
'Navigate the page by URL, back or forward in history, or reload.',
),
url: zod.string().optional().describe('Target URL (only type=url)'),
headers: zod
.record(zod.string())
.optional()
.describe('Optional headers to send with the all request.'),
ignoreCache: zod
.boolean()
.optional()
Expand All @@ -130,6 +142,10 @@ export const navigatePage = defineTool({
timeout: request.params.timeout,
};

if (request.params.headers) {
await page.setExtraHTTPHeaders(request.params.headers);
}

if (!request.params.type && !request.params.url) {
throw new Error('Either URL or a type is required.');
}
Expand Down