diff --git a/src/McpPage.ts b/src/McpPage.ts index 2fc9590b9..85f66b0f0 100644 --- a/src/McpPage.ts +++ b/src/McpPage.ts @@ -13,8 +13,8 @@ import type { Viewport, WebMCPTool, } from './third_party/index.js'; -import type {ToolGroup, ToolDefinition} from './tools/inPage.js'; import {takeSnapshot} from './tools/snapshot.js'; +import type {ToolGroup, ToolDefinition} from './tools/thirdPartyDeveloper.js'; import type { ContextPage, DevToolsData, @@ -58,7 +58,7 @@ export class McpPage implements ContextPage { #dialog?: Dialog; #dialogHandler: (dialog: Dialog) => void; - inPageTools: ToolGroup | undefined; + thirdPartyDeveloperTools: ToolGroup | undefined; constructor(page: Page, id: number) { this.pptrPage = page; @@ -89,8 +89,8 @@ export class McpPage implements ContextPage { } } - getInPageTools(): ToolGroup | undefined { - return this.inPageTools; + getThirdPartyDeveloperTools(): ToolGroup | undefined { + return this.thirdPartyDeveloperTools; } getWebMcpTools(): WebMCPTool[] { @@ -144,7 +144,7 @@ export class McpPage implements ContextPage { this.pptrPage.off('dialog', this.#dialogHandler); } - async executeInPageTool( + async executeThirdPartyDeveloperTool( toolName: string, params: Record, response: Response, diff --git a/src/McpResponse.ts b/src/McpResponse.ts index 246536b77..65cc08cc4 100644 --- a/src/McpResponse.ts +++ b/src/McpResponse.ts @@ -27,8 +27,8 @@ import type { JSONSchema7Definition, Extension, } from './third_party/index.js'; -import type {ToolGroup, ToolDefinition} from './tools/inPage.js'; import {handleDialog} from './tools/pages.js'; +import type {ToolGroup, ToolDefinition} from './tools/thirdPartyDeveloper.js'; import type { DevToolsData, ImageContentData, @@ -196,7 +196,7 @@ export class McpResponse implements Response { includePreservedMessages?: boolean; }; #listExtensions?: boolean; - #listInPageTools?: boolean; + #listThirdPartyDeveloperTools?: boolean; #listWebMcpTools?: boolean; #devToolsData?: DevToolsData; #tabId?: string; @@ -244,9 +244,9 @@ export class McpResponse implements Response { this.#listExtensions = true; } - setListInPageTools(): void { - if (this.#args.categoryInPageTools) { - this.#listInPageTools = true; + setListThirdPartyDeveloperTools(): void { + if (this.#args.categoryThirdPartyDeveloperTools) { + this.#listThirdPartyDeveloperTools = true; } } @@ -552,11 +552,11 @@ export class McpResponse implements Response { extensions = await context.listExtensions(); } - let inPageTools: ToolGroup | undefined; - if (this.#listInPageTools) { + let thirdPartyDeveloperTools: ToolGroup | undefined; + if (this.#listThirdPartyDeveloperTools) { const page = this.#page ?? context.getSelectedMcpPage(); - inPageTools = await getToolGroup(page); - page.inPageTools = inPageTools; + thirdPartyDeveloperTools = await getToolGroup(page); + page.thirdPartyDeveloperTools = thirdPartyDeveloperTools; } let webmcpTools: WebMCPTool[] | undefined; @@ -669,7 +669,7 @@ export class McpResponse implements Response { traceSummary: this.#attachedTraceSummary, extensions, lighthouseResult: this.#attachedLighthouseResult, - inPageTools, + thirdPartyDeveloperTools, webmcpTools, errorMessage: this.#error?.message, }); @@ -688,7 +688,7 @@ export class McpResponse implements Response { traceInsight?: TraceInsightData; extensions?: Map; lighthouseResult?: LighthouseData; - inPageTools?: ToolGroup; + thirdPartyDeveloperTools?: ToolGroup; webmcpTools?: WebMCPTool[]; errorMessage?: string; }, @@ -705,7 +705,7 @@ export class McpResponse implements Response { traceInsights?: Array<{insightName: string; insightKey: string}>; lighthouseResult?: object; extensions?: object[]; - inPageTools?: object; + thirdPartyDeveloperTools?: object; webmcpTools?: object[]; message?: string; networkConditions?: string; @@ -1004,13 +1004,17 @@ Call ${handleDialog.name} to handle it before continuing.`); } } - if (this.#listInPageTools) { - structuredContent.inPageTools = data.inPageTools ?? undefined; - response.push('## In-page tools'); - if (!data.inPageTools || !data.inPageTools.tools) { - response.push('No in-page tools available.'); + if (this.#listThirdPartyDeveloperTools) { + structuredContent.thirdPartyDeveloperTools = + data.thirdPartyDeveloperTools ?? undefined; + response.push('## Third-party developer tools'); + if ( + !data.thirdPartyDeveloperTools || + !data.thirdPartyDeveloperTools.tools + ) { + response.push('No third-party developer tools available.'); } else { - const toolGroup = data.inPageTools; + const toolGroup = data.thirdPartyDeveloperTools; response.push(`${toolGroup.name}: ${toolGroup.description}`); response.push('Available tools:'); const toolDefinitionsMessage = toolGroup.tools diff --git a/src/TextSnapshot.ts b/src/TextSnapshot.ts index 3af4a7cfb..eac0cb3ee 100644 --- a/src/TextSnapshot.ts +++ b/src/TextSnapshot.ts @@ -149,8 +149,8 @@ export class TextSnapshot { } // ExtraHandles represent DOM nodes which might not be part of the accessibility tree, e.g. DOM nodes - // returned by in-page tools. We insert them into the tree by finding the closest ancestor in the - // tree and inserting the node as a child. The ancestor's child nodes are re-parented if necessary. + // returned by third-party developer tools. We insert them into the tree by finding the closest ancestor + // in the tree and inserting the node as a child. The ancestor's child nodes are re-parented if necessary. private static async insertExtraNodes( page: McpPage, idToNode: Map, diff --git a/src/bin/chrome-devtools-mcp-cli-options.ts b/src/bin/chrome-devtools-mcp-cli-options.ts index 09a78d8cb..9d2a1b061 100644 --- a/src/bin/chrome-devtools-mcp-cli-options.ts +++ b/src/bin/chrome-devtools-mcp-cli-options.ts @@ -237,11 +237,11 @@ export const cliOptions = { describe: 'Set to true to include tools related to extensions. Note: This feature is currently only supported with a pipe connection. autoConnect, browserUrl, and wsEndpoint are not supported with this feature until 149 will be released.', }, - categoryInPageTools: { + categoryThirdPartyDeveloperTools: { type: 'boolean', hidden: true, describe: - 'Set to true to enable tools exposed by the inspected page itself', + 'Set to true to enable third-party developer tools exposed by the inspected page itself', }, performanceCrux: { type: 'boolean', diff --git a/src/index.ts b/src/index.ts index f98539ef5..651b96aa0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -168,8 +168,8 @@ export async function createMcpServer( return; } if ( - tool.annotations.category === ToolCategory.IN_PAGE && - !serverArgs.categoryInPageTools + tool.annotations.category === ToolCategory['3P_DEVELOPER'] && + !serverArgs.categoryThirdPartyDeveloperTools ) { return; } diff --git a/src/telemetry/flag_usage_metrics.json b/src/telemetry/flag_usage_metrics.json index 79053998d..c615eaabc 100644 --- a/src/telemetry/flag_usage_metrics.json +++ b/src/telemetry/flag_usage_metrics.json @@ -191,11 +191,11 @@ "flagType": "boolean" }, { - "name": "category_in_page_tools", + "name": "category_third_party_developer_tools", "flagType": "boolean" }, { - "name": "category_in_page_tools_present", + "name": "category_third_party_developer_tools_present", "flagType": "boolean" }, { diff --git a/src/telemetry/tool_call_metrics.json b/src/telemetry/tool_call_metrics.json index 2a8765790..01b1931ec 100644 --- a/src/telemetry/tool_call_metrics.json +++ b/src/telemetry/tool_call_metrics.json @@ -115,7 +115,7 @@ ] }, { - "name": "execute_in_page_tool", + "name": "execute_3p_developer_tool", "args": [ { "name": "tool_name_length", @@ -253,7 +253,7 @@ "args": [] }, { - "name": "list_in_page_tools", + "name": "list_3p_developer_tools", "args": [] }, { diff --git a/src/tools/ToolDefinition.ts b/src/tools/ToolDefinition.ts index 8acc24be3..18da7b2ad 100644 --- a/src/tools/ToolDefinition.ts +++ b/src/tools/ToolDefinition.ts @@ -28,8 +28,8 @@ import type {PaginationOptions} from '../utils/types.js'; import type {ToolCategory} from './categories.js'; import type { ToolGroup, - ToolDefinition as InPageToolDefinition, -} from './inPage.js'; + ToolDefinition as ThirdPartyDeveloperToolDefinition, +} from './thirdPartyDeveloper.js'; export interface BaseToolDefinition< Schema extends zod.ZodRawShape = zod.ZodRawShape, @@ -151,7 +151,7 @@ export interface Response { ): void; setListExtensions(): void; attachLighthouseResult(result: LighthouseData): void; - setListInPageTools(): void; + setListThirdPartyDeveloperTools(): void; setListWebMcpTools(): void; } @@ -261,8 +261,10 @@ export type ContextPage = Readonly<{ action: () => Promise, options?: {timeout?: number; handleDialog?: 'accept' | 'dismiss' | string}, ): Promise; - getInPageTools(): ToolGroup | undefined; - executeInPageTool( + getThirdPartyDeveloperTools(): + | ToolGroup + | undefined; + executeThirdPartyDeveloperTool( toolName: string, params: Record, response: Response, diff --git a/src/tools/categories.ts b/src/tools/categories.ts index b0abe8bb5..8b023b263 100644 --- a/src/tools/categories.ts +++ b/src/tools/categories.ts @@ -12,7 +12,7 @@ export enum ToolCategory { NETWORK = 'network', DEBUGGING = 'debugging', EXTENSIONS = 'extensions', - IN_PAGE = 'in-page', + '3P_DEVELOPER' = '3p-developer', MEMORY = 'memory', } @@ -24,7 +24,7 @@ export const labels = { [ToolCategory.NETWORK]: 'Network', [ToolCategory.DEBUGGING]: 'Debugging', [ToolCategory.EXTENSIONS]: 'Extensions', - [ToolCategory.IN_PAGE]: 'In-page tools', + [ToolCategory['3P_DEVELOPER']]: 'Third-party developer tools', [ToolCategory.MEMORY]: 'Memory', }; diff --git a/src/tools/pages.ts b/src/tools/pages.ts index ac4a15fbd..faaf5d9e8 100644 --- a/src/tools/pages.ts +++ b/src/tools/pages.ts @@ -87,7 +87,7 @@ export const listPages = defineTool(args => { blockedByDialog: false, handler: async (_request, response) => { response.setIncludePages(true); - response.setListInPageTools(); + response.setListThirdPartyDeveloperTools(); response.setListWebMcpTools(); }, }; @@ -116,7 +116,7 @@ export const selectPage = defineTool({ const page = context.getPageById(request.params.pageId); context.selectPage(page); response.setIncludePages(true); - response.setListInPageTools(); + response.setListThirdPartyDeveloperTools(); response.setListWebMcpTools(); if (request.params.bringToFront) { await page.pptrPage.bringToFront(); @@ -148,7 +148,7 @@ export const closePage = defineTool({ } } response.setIncludePages(true); - response.setListInPageTools(); + response.setListThirdPartyDeveloperTools(); }, }); @@ -206,7 +206,7 @@ export const newPage = defineTool(args => { ); response.setIncludePages(true); - response.setListInPageTools(); + response.setListThirdPartyDeveloperTools(); }, }; }); @@ -373,7 +373,7 @@ export const navigatePage = definePageTool(args => { } response.setIncludePages(true); - response.setListInPageTools(); + response.setListThirdPartyDeveloperTools(); response.setListWebMcpTools(); }, }; diff --git a/src/tools/inPage.ts b/src/tools/thirdPartyDeveloper.ts similarity index 69% rename from src/tools/inPage.ts rename to src/tools/thirdPartyDeveloper.ts index 74f05d496..0b3a00561 100644 --- a/src/tools/inPage.ts +++ b/src/tools/thirdPartyDeveloper.ts @@ -36,34 +36,34 @@ declare global { } } -export const listInPageTools = definePageTool({ - name: 'list_in_page_tools', - description: `Lists all in-page tools the page exposes for providing runtime information. - In-page tools can be called via the 'execute_in_page_tool()' MCP tool. - Alternatively, in-page tools can be executed by calling 'evaluate_script' and adding the +export const listThirdPartyDeveloperTools = definePageTool({ + name: 'list_3p_developer_tools', + description: `Lists all third-party developer tools the page exposes for providing runtime information. + Third-party developer tools can be called via the 'execute_3p_developer_tool()' MCP tool. + Alternatively, third-party developer tools can be executed by calling 'evaluate_script' and adding the following command to the script: 'window.__dtmcp.executeTool(toolName, params)' - This might be helpful when the in-page-tools return non-serializable values or when composing - the in-page-tools with additional functionality.`, + This might be helpful when the third-party developer tools return non-serializable values or when composing + third-party developer tools with additional functionality.`, annotations: { - category: ToolCategory.IN_PAGE, + category: ToolCategory['3P_DEVELOPER'], readOnlyHint: true, - conditions: ['inPageTools'], + conditions: ['thirdPartyDeveloperTools'], }, schema: {}, blockedByDialog: false, handler: async (_request, response, _context) => { - response.setListInPageTools(); + response.setListThirdPartyDeveloperTools(); }, }); -export const executeInPageTool = definePageTool({ - name: 'execute_in_page_tool', +export const executeThirdPartyDeveloperTool = definePageTool({ + name: 'execute_3p_developer_tool', description: `Executes a tool exposed by the page.`, annotations: { - category: ToolCategory.IN_PAGE, + category: ToolCategory['3P_DEVELOPER'], readOnlyHint: false, - conditions: ['inPageTools'], + conditions: ['thirdPartyDeveloperTools'], }, schema: { toolName: zod.string().describe('The name of the tool to execute'), @@ -90,7 +90,7 @@ export const executeInPageTool = definePageTool({ } } - const toolGroup = request.page.getInPageTools(); + const toolGroup = request.page.getThirdPartyDeveloperTools(); const tool = toolGroup?.tools.find(t => t.name === toolName); if (!tool) { throw new Error(`Tool ${toolName} not found`); @@ -104,6 +104,10 @@ export const executeInPageTool = definePageTool({ ); } - await request.page.executeInPageTool(toolName, params, response); + await request.page.executeThirdPartyDeveloperTool( + toolName, + params, + response, + ); }, }); diff --git a/src/tools/tools.ts b/src/tools/tools.ts index b3477b906..5366f867d 100644 --- a/src/tools/tools.ts +++ b/src/tools/tools.ts @@ -9,7 +9,6 @@ import type {ParsedArguments} from '../bin/chrome-devtools-mcp-cli-options.js'; import * as consoleTools from './console.js'; import * as emulationTools from './emulation.js'; import * as extensionTools from './extensions.js'; -import * as inPageTools from './inPage.js'; import * as inputTools from './input.js'; import * as lighthouseTools from './lighthouse.js'; import * as memoryTools from './memory.js'; @@ -21,6 +20,7 @@ import * as screenshotTools from './screenshot.js'; import * as scriptTools from './script.js'; import * as slimTools from './slim/tools.js'; import * as snapshotTools from './snapshot.js'; +import * as thirdPartyDeveloperTools from './thirdPartyDeveloper.js'; import type {ToolDefinition} from './ToolDefinition.js'; import * as webmcpTools from './webmcp.js'; @@ -31,7 +31,6 @@ export const createTools = (args: ParsedArguments) => { ...Object.values(consoleTools), ...Object.values(emulationTools), ...Object.values(extensionTools), - ...Object.values(inPageTools), ...Object.values(inputTools), ...Object.values(lighthouseTools), ...Object.values(memoryTools), @@ -42,6 +41,7 @@ export const createTools = (args: ParsedArguments) => { ...Object.values(screenshotTools), ...Object.values(scriptTools), ...Object.values(snapshotTools), + ...Object.values(thirdPartyDeveloperTools), ...Object.values(webmcpTools), ]; diff --git a/tests/McpResponse.test.js.snapshot b/tests/McpResponse.test.js.snapshot index 11a7be78e..5129174eb 100644 --- a/tests/McpResponse.test.js.snapshot +++ b/tests/McpResponse.test.js.snapshot @@ -1206,16 +1206,16 @@ exports[`extensions > lists extensions 2`] = ` } `; -exports[`inPage tools > lists in-page tools 1`] = ` -## In-page tools +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[`inPage tools > lists in-page tools 2`] = ` +exports[`third-party developer tools > lists third-party developer tools 2`] = ` { - "inPageTools": { + "thirdPartyDeveloperTools": { "name": "My Tool Group", "description": "A group of tools", "tools": [ diff --git a/tests/McpResponse.test.ts b/tests/McpResponse.test.ts index 295450b49..caf96dbe1 100644 --- a/tests/McpResponse.test.ts +++ b/tests/McpResponse.test.ts @@ -1040,7 +1040,7 @@ describe('lighthouse', () => { }); }); -describe('inPage tools', () => { +describe('third-party developer tools', () => { function stubToolDiscovery(page: object) { // @ts-expect-error Internal API const client = page._client(); @@ -1067,15 +1067,15 @@ describe('inPage tools', () => { }); } - it('lists in-page tools', async t => { + it('lists third-party developer tools', async t => { await withMcpContext( async (response, context) => { - response.setListInPageTools(); + response.setListThirdPartyDeveloperTools(); const emptyResult = await response.handle('test', context); const emptyText = getTextContent(emptyResult.content[0]); assert.ok( - emptyText.includes('No in-page tools available.'), - 'Should show message for empty in-page tools', + emptyText.includes('No third-party developer tools available.'), + 'Should show message for empty third-party developer tools', ); response.resetResponseLineForTesting(); @@ -1097,7 +1097,7 @@ describe('inPage tools', () => { }, ], }); - response.setListInPageTools(); + response.setListThirdPartyDeveloperTools(); const {content, structuredContent} = await response.handle( 'test', context, @@ -1111,11 +1111,11 @@ describe('inPage tools', () => { t.assert.snapshot?.(JSON.stringify(structuredContent, null, 2)); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); - async function testIncludesInPageTools( + async function testIncludesThirdPartyDeveloperTools( handlerAction: ( response: McpResponse, context: McpContext, @@ -1130,11 +1130,11 @@ describe('inPage tools', () => { const initScript = ` window.__dtmcp = { toolGroup: { - name: 'In-Page group', + name: 'Tool group name', description: 'Test tools', tools: [ { - name: 'inPageTool', + name: '3pDeveloperTool', description: 'A test tool', inputSchema: { type: 'object', @@ -1157,42 +1157,42 @@ describe('inPage tools', () => { const {content} = await response.handle(toolName, context); const responseText = getTextContent(content[0]); assert.ok( - responseText.includes('inPageTool'), - `Should include in-page tool name in the ${toolName} response`, + responseText.includes('3pDeveloperTool'), + `Should include third-party developer tool name in the ${toolName} response`, ); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); } - it('includes in-page tools in list_pages response', async () => { - await testIncludesInPageTools(async (response, context) => { + it('includes third-party developer tools in list_pages response', async () => { + await testIncludesThirdPartyDeveloperTools(async (response, context) => { const listPagesDef = listPages({ - categoryInPageTools: true, + categoryThirdPartyDeveloperTools: true, } as ParsedArguments); await listPagesDef.handler({params: {}}, response, context); }, 'list_pages'); }); - it('includes in-page tools in select_page response', async () => { - await testIncludesInPageTools(async (response, context) => { + it('includes third-party developer tools in select_page response', async () => { + await testIncludesThirdPartyDeveloperTools(async (response, context) => { const pageId = context.getPageId(context.getSelectedMcpPage().pptrPage) ?? 1; await selectPage.handler({params: {pageId}}, response, context); }, 'select_page'); }); - it('includes in-page tools in close_page response', async () => { - await testIncludesInPageTools(async (response, context) => { + it('includes third-party developer tools in close_page response', async () => { + await testIncludesThirdPartyDeveloperTools(async (response, context) => { const pageId = context.getPageId(context.getSelectedMcpPage().pptrPage) ?? 1; await closePage.handler({params: {pageId}}, response, context); }, 'close_page'); }); - it('includes in-page tools in navigate_page response', async () => { - await testIncludesInPageTools(async (response, context) => { + it('includes third-party developer tools in navigate_page response', async () => { + await testIncludesThirdPartyDeveloperTools(async (response, context) => { await navigatePage().handler( { params: {type: 'url', url: 'about:blank'}, @@ -1204,9 +1204,9 @@ describe('inPage tools', () => { }, 'navigate_page'); }); - it('includes in-page tools in new_page response', async () => { - await testIncludesInPageTools(async (response, context) => { - // Workaround to ensure the test environment's new page contain in-page tools + it('includes third-party developer tools in new_page response', async () => { + await testIncludesThirdPartyDeveloperTools(async (response, context) => { + // Workaround to ensure the test environment's new page contain third-party developer tools sinon.stub(context, 'newPage').resolves(context.getSelectedMcpPage()); await newPage().handler( diff --git a/tests/index.test.ts b/tests/index.test.ts index 34b35e5b6..c37106cae 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -105,16 +105,16 @@ describe('e2e', () => { }); }); - it('has experimental in-Page tools', async () => { + it('has experimental third-party developer tools', async () => { await withClient( async client => { const {tools} = await client.listTools(); - const listInPageTools = tools.find( - t => t.name === 'list_in_page_tools', + const listThirdPartyDeveloperTools = tools.find( + t => t.name === 'list_3p_developer_tools', ); - assert.ok(listInPageTools); + assert.ok(listThirdPartyDeveloperTools); }, - ['--category-in-page-tools'], + ['--category-third-party-developer-tools'], ); }); diff --git a/tests/tools/inPage.test.ts b/tests/tools/thirdPartyDeveloper.test.ts similarity index 80% rename from tests/tools/inPage.test.ts rename to tests/tools/thirdPartyDeveloper.test.ts index 413efe396..2b33b9375 100644 --- a/tests/tools/inPage.test.ts +++ b/tests/tools/thirdPartyDeveloper.test.ts @@ -13,12 +13,18 @@ import type {ParsedArguments} from '../../src/bin/chrome-devtools-mcp-cli-option import type {McpContext} from '../../src/McpContext.js'; import type {McpResponse} from '../../src/McpResponse.js'; import {TextSnapshot} from '../../src/TextSnapshot.js'; -import {executeInPageTool, listInPageTools} from '../../src/tools/inPage.js'; -import type {ToolGroup, ToolDefinition} from '../../src/tools/inPage.js'; +import { + executeThirdPartyDeveloperTool, + listThirdPartyDeveloperTools, +} from '../../src/tools/thirdPartyDeveloper.js'; +import type { + ToolGroup, + ToolDefinition, +} from '../../src/tools/thirdPartyDeveloper.js'; import {withMcpContext} from '../utils.js'; -describe('inPage', () => { - describe('list_in_page_tools', () => { +describe('thirdPartyDeveloperTools', () => { + describe('list_3p_developer_tools', () => { it('lists tools', async () => { await withMcpContext( async (response, context) => { @@ -51,11 +57,18 @@ describe('inPage', () => { }); }); - await listInPageTools.handler({params: {}, page}, response, context); + await listThirdPartyDeveloperTools.handler( + {params: {}, page}, + response, + context, + ); - const result = await response.handle('list_in_page_tools', context); - // @ts-expect-error `structuredContent` has `inPageTools` - const actualGroup = result.structuredContent.inPageTools; + const result = await response.handle( + 'list_3p_developer_tools', + context, + ); + // @ts-expect-error `structuredContent` has `thirdPartyDeveloperTools` + const actualGroup = result.structuredContent.thirdPartyDeveloperTools; assert.strictEqual(actualGroup.name, 'test-group'); assert.strictEqual(actualGroup.description, 'test description'); assert.strictEqual(actualGroup.tools.length, 1); @@ -72,7 +85,7 @@ describe('inPage', () => { }); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); @@ -88,21 +101,28 @@ describe('inPage', () => { }); }); - await listInPageTools.handler({params: {}, page}, response, context); + await listThirdPartyDeveloperTools.handler( + {params: {}, page}, + response, + context, + ); - const result = await response.handle('list_in_page_tools', context); - assert.ok('inPageTools' in result.structuredContent); + const result = await response.handle( + 'list_3p_developer_tools', + context, + ); + assert.ok('thirdPartyDeveloperTools' in result.structuredContent); assert.deepEqual( ( result.structuredContent as { - inPageTools: ToolGroup; + thirdPartyDeveloperTools: ToolGroup; } - ).inPageTools, + ).thirdPartyDeveloperTools, {}, ); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); @@ -117,21 +137,28 @@ describe('inPage', () => { }); }); - await listInPageTools.handler({params: {}, page}, response, context); + await listThirdPartyDeveloperTools.handler( + {params: {}, page}, + response, + context, + ); - const result = await response.handle('list_in_page_tools', context); - assert.ok('inPageTools' in result.structuredContent); + const result = await response.handle( + 'list_3p_developer_tools', + context, + ); + assert.ok('thirdPartyDeveloperTools' in result.structuredContent); assert.strictEqual( ( result.structuredContent as { - inPageTools: ToolGroup; + thirdPartyDeveloperTools: ToolGroup; } - ).inPageTools, + ).thirdPartyDeveloperTools, undefined, ); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); @@ -140,23 +167,31 @@ describe('inPage', () => { async (response, context) => { const page = await context.newPage(); response.setPage(page); - await listInPageTools.handler({params: {}, page}, response, context); + await listThirdPartyDeveloperTools.handler( + {params: {}, page}, + response, + context, + ); - const result = await response.handle('list_in_page_tools', context); - assert.ok('inPageTools' in result.structuredContent); + const result = await response.handle( + 'list_3p_developer_tools', + context, + ); + assert.ok('thirdPartyDeveloperTools' in result.structuredContent); assert.strictEqual( - (result.structuredContent as {inPageTools: undefined}).inPageTools, + (result.structuredContent as {thirdPartyDeveloperTools: undefined}) + .thirdPartyDeveloperTools, undefined, ); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); }); - describe('execute_in_page_tool', () => { - async function setupInPageTools( + describe('execute_3p_developer_tool', () => { + async function setupThirdPartyDeveloperTools( response: McpResponse, context: McpContext, evaluateFn: () => void, @@ -164,14 +199,18 @@ describe('inPage', () => { const page = await context.newPage(); response.setPage(page); await page.pptrPage.evaluate(evaluateFn); - await listInPageTools.handler({params: {}, page}, response, context); - await response.handle('list_in_page_tools', context); + await listThirdPartyDeveloperTools.handler( + {params: {}, page}, + response, + context, + ); + await response.handle('list_3p_developer_tools', context); } it('executes a tool', async () => { await withMcpContext( async (response, context) => { - await setupInPageTools(response, context, () => { + await setupThirdPartyDeveloperTools(response, context, () => { window.__dtmcp = { toolGroup: { name: 'test-group', @@ -198,7 +237,7 @@ describe('inPage', () => { }); }); - await executeInPageTool.handler( + await executeThirdPartyDeveloperTool.handler( { params: { toolName: 'test-tool', @@ -215,13 +254,13 @@ describe('inPage', () => { ); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); it('throws if tool not found in list', async () => { await withMcpContext(async (response, context) => { - await setupInPageTools(response, context, () => { + await setupThirdPartyDeveloperTools(response, context, () => { window.__dtmcp = { toolGroup: { name: 'test-group', @@ -237,7 +276,7 @@ describe('inPage', () => { await assert.rejects( async () => { - await executeInPageTool.handler( + await executeThirdPartyDeveloperTool.handler( { params: { toolName: 'missing-tool', @@ -257,7 +296,7 @@ describe('inPage', () => { it('throws if parameters are invalid', async () => { await withMcpContext( async (response, context) => { - await setupInPageTools(response, context, () => { + await setupThirdPartyDeveloperTools(response, context, () => { window.__dtmcp = { toolGroup: { name: 'test-group', @@ -286,7 +325,7 @@ describe('inPage', () => { await assert.rejects( async () => { - await executeInPageTool.handler( + await executeThirdPartyDeveloperTool.handler( { params: { toolName: 'test-tool', @@ -302,14 +341,14 @@ describe('inPage', () => { ); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); it('handles JSON result', async () => { await withMcpContext( async (response, context) => { - await setupInPageTools(response, context, () => { + await setupThirdPartyDeveloperTools(response, context, () => { window.__dtmcp = { toolGroup: { name: 'test-group', @@ -330,7 +369,7 @@ describe('inPage', () => { }); }); - await executeInPageTool.handler( + await executeThirdPartyDeveloperTool.handler( { params: { toolName: 'test-tool', @@ -347,7 +386,7 @@ describe('inPage', () => { ); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); @@ -356,7 +395,7 @@ describe('inPage', () => { const page = await context.newPage(); response.setPage(page); - page.inPageTools = { + page.thirdPartyDeveloperTools = { name: 'test-group', description: 'test description', tools: [ @@ -415,7 +454,7 @@ describe('inPage', () => { throw new Error('Not found'); }; - await executeInPageTool.handler( + await executeThirdPartyDeveloperTool.handler( { params: { toolName: 'test-tool', @@ -445,7 +484,7 @@ describe('inPage', () => { it('processToolResult replaces functions with ""', async () => { await withMcpContext( async (response, context) => { - await setupInPageTools(response, context, () => { + await setupThirdPartyDeveloperTools(response, context, () => { window.__dtmcp = { toolGroup: { name: 'test-group', @@ -469,7 +508,7 @@ describe('inPage', () => { }); }); - await executeInPageTool.handler( + await executeThirdPartyDeveloperTool.handler( { params: { toolName: 'test-tool', @@ -486,14 +525,14 @@ describe('inPage', () => { ); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); it('processToolResult replaces circular references with ""', async () => { await withMcpContext( async (response, context) => { - await setupInPageTools(response, context, () => { + await setupThirdPartyDeveloperTools(response, context, () => { window.__dtmcp = { toolGroup: { name: 'test-group', @@ -518,7 +557,7 @@ describe('inPage', () => { }); }); - await executeInPageTool.handler( + await executeThirdPartyDeveloperTool.handler( { params: { toolName: 'test-tool', @@ -535,14 +574,14 @@ describe('inPage', () => { ); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); it('processToolResult replaces non-plain objects with ""', async () => { await withMcpContext( async (response, context) => { - await setupInPageTools(response, context, () => { + await setupThirdPartyDeveloperTools(response, context, () => { class CustomClass { val = 'value'; } @@ -569,7 +608,7 @@ describe('inPage', () => { }); }); - await executeInPageTool.handler( + await executeThirdPartyDeveloperTool.handler( { params: { toolName: 'test-tool', @@ -590,7 +629,7 @@ describe('inPage', () => { ); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); @@ -600,7 +639,7 @@ describe('inPage', () => { const page = await context.newPage(); response.setPage(page); - page.inPageTools = { + page.thirdPartyDeveloperTools = { name: 'test-group', description: 'test description', tools: [ @@ -627,7 +666,7 @@ describe('inPage', () => { .stub(page, 'resolveCdpElementId') .returns('mock-uid'); - await executeInPageTool.handler( + await executeThirdPartyDeveloperTool.handler( { params: { toolName: 'test-tool', @@ -647,17 +686,17 @@ describe('inPage', () => { stub.restore(); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); - it('creates a new snapshot if the in-page tool response contains a DOM element', async () => { + it('creates a new snapshot if the third-party developer tool response contains a DOM element', async () => { await withMcpContext( async (response, context) => { const page = await context.newPage(); response.setPage(page); - page.inPageTools = { + page.thirdPartyDeveloperTools = { name: 'test-group', description: 'test description', tools: [ @@ -688,7 +727,7 @@ describe('inPage', () => { .stub(page, 'resolveCdpElementId') .returns('mock-uid'); - await executeInPageTool.handler( + await executeThirdPartyDeveloperTool.handler( { params: { toolName: 'test-tool', @@ -713,17 +752,17 @@ describe('inPage', () => { stubSnapshot.restore(); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); - it('does not create a new snapshot if the in-page tool response does not contain a DOM element', async () => { + it('does not create a new snapshot if the third-party developer tool response does not contain a DOM element', async () => { await withMcpContext( async (response, context) => { const page = await context.newPage(); response.setPage(page); - page.inPageTools = { + page.thirdPartyDeveloperTools = { name: 'test-group', description: 'test description', tools: [ @@ -747,7 +786,7 @@ describe('inPage', () => { .stub(TextSnapshot, 'create') .resolves({} as TextSnapshot); - await executeInPageTool.handler( + await executeThirdPartyDeveloperTool.handler( { params: { toolName: 'test-tool', @@ -771,7 +810,7 @@ describe('inPage', () => { stubSnapshot.restore(); }, undefined, - {categoryInPageTools: true} as ParsedArguments, + {categoryThirdPartyDeveloperTools: true} as ParsedArguments, ); }); });