fix: only require a page in page-scoped tools (#2030)

getSelectedMcpPage and getPageById throw if the page is not found, so
these should only be called for page-scoped tools.
This commit is contained in:
Alex Rudenko
2026-05-11 11:39:23 +02:00
committed by GitHub
parent be4a34c19a
commit 8e06761572
3 changed files with 41 additions and 41 deletions
+10 -10
View File
@@ -291,17 +291,17 @@ export async function createMcpServer(
response.setRedactNetworkHeaders(serverArgs.redactNetworkHeaders);
try {
const page =
serverArgs.experimentalPageIdRouting &&
params.pageId &&
!serverArgs.slim
? context.getPageById(params.pageId)
: context.getSelectedMcpPage();
response.setPage(page);
if (tool.blockedByDialog) {
page.throwIfDialogOpen();
}
if ('pageScoped' in tool && tool.pageScoped) {
const page =
serverArgs.experimentalPageIdRouting &&
params.pageId &&
!serverArgs.slim
? context.getPageById(params.pageId)
: context.getSelectedMcpPage();
response.setPage(page);
if (tool.blockedByDialog) {
page.throwIfDialogOpen();
}
await tool.handler(
{
params,
+30 -30
View File
@@ -1206,36 +1206,6 @@ exports[`extensions > lists extensions 2`] = `
}
`;
exports[`third-party developer tools > lists third-party developer tools 1`] = `
## Third-party developer tools
My Tool Group: A group of tools
Available tools:
name="myTool", description="Does something", inputSchema={"type":"object","properties":{"foo":{"type":"string"}}}
`;
exports[`third-party developer tools > lists third-party developer tools 2`] = `
{
"thirdPartyDeveloperTools": {
"name": "My Tool Group",
"description": "A group of tools",
"tools": [
{
"name": "myTool",
"description": "Does something",
"inputSchema": {
"type": "object",
"properties": {
"foo": {
"type": "string"
}
}
}
}
]
}
}
`;
exports[`lighthouse > includes lighthouse report paths 1`] = `
## Lighthouse Audit Results
Mode: navigation
@@ -1282,6 +1252,36 @@ exports[`lighthouse > includes lighthouse report paths 2`] = `
}
`;
exports[`third-party developer tools > lists third-party developer tools 1`] = `
## Third-party developer tools
My Tool Group: A group of tools
Available tools:
name="myTool", description="Does something", inputSchema={"type":"object","properties":{"foo":{"type":"string"}}}
`;
exports[`third-party developer tools > lists third-party developer tools 2`] = `
{
"thirdPartyDeveloperTools": {
"name": "My Tool Group",
"description": "A group of tools",
"tools": [
{
"name": "myTool",
"description": "Does something",
"inputSchema": {
"type": "object",
"properties": {
"foo": {
"type": "string"
}
}
}
}
]
}
}
`;
exports[`webmcp > includes webmcp tools in list_pages response 1`] = `
## Pages
1: about:blank [selected]
+1 -1
View File
@@ -7,7 +7,7 @@ exports[`e2e > Dialogs > when dialog is open and tool is blocked, returns an err
`;
exports[`e2e > Dialogs > when dialog is open and tool is not blocked, executes tool 1`] = `
{"content":[{"type":"text","text":"# Open dialog\\nalert: test dialog.\\nCall handle_dialog to handle it before continuing.\\n## Pages\\n1: about:blank\\n2: data:text/html,<button id=\\"test\\" onclick=\\"alert('test dialog')\\">Click me</button>\\n3: data:text/html,<h1>New</h1> [selected]"}]}
{"content":[{"type":"text","text":"## Pages\\n1: about:blank\\n2: data:text/html,<button id=\\"test\\" onclick=\\"alert('test dialog')\\">Click me</button>\\n3: data:text/html,<h1>New</h1> [selected]"}]}
`;
exports[`e2e > calls a tool 1`] = `