Chrome DevTools for coding agents
fix: return message when page exposes no 3p developer tools (#3197)
Wolfgang Beyer663f3c3ffc9f
diff --git a/src/McpResponse.ts b/src/McpResponse.tsindex 1735a821..5a22ee6c 100644--- a/src/McpResponse.ts+++ b/src/McpResponse.ts@@ -621,7 +621,7 @@ export class McpResponse implements Response {return undefined;}- async #handleThirdPartyDevelopeTools(): Promise<ToolGroups | undefined> {+ async #handleThirdPartyDeveloperTools(): Promise<ToolGroups | undefined> {if (this.#args.categoryExperimentalThirdParty &&this.#listThirdPartyDeveloperTools &&@@ -804,7 +804,7 @@ export class McpResponse implements Response {this.#handleSnapshot(context),this.#handleAttachedNetworkRequest(context),this.#handleAttachedConsoleMessage(),- this.#handleThirdPartyDevelopeTools(),+ this.#handleThirdPartyDeveloperTools(),this.#handleWebMCP(),this.#handleConsoleList(context),this.#handleNetworkRequestList(context),@@ -1615,20 +1615,24 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);}const thirdPartyDeveloperTools = data.thirdPartyDeveloperTools;- if (thirdPartyDeveloperTools?.length) {+ if (this.#listThirdPartyDeveloperTools && thirdPartyDeveloperTools) {structuredContent.thirdPartyDeveloperTools = thirdPartyDeveloperTools;response.push('## Third-party developer tools');- for (const toolGroup of thirdPartyDeveloperTools) {- response.push(`${toolGroup.name}: ${toolGroup.description}`);- response.push('Available tools:');- const toolDefinitionsMessage = toolGroup.tools- .map(tool => {- return `name="${tool.name}", description="${tool.description}", inputSchema=${JSON.stringify(- tool.inputSchema,- )}`;- })- .join('\n');- response.push(toolDefinitionsMessage);+ if (thirdPartyDeveloperTools.length === 0) {+ response.push('No third-party developer tools available.');+ } else {+ for (const toolGroup of thirdPartyDeveloperTools) {+ response.push(`${toolGroup.name}: ${toolGroup.description}`);+ response.push('Available tools:');+ const toolDefinitionsMessage = toolGroup.tools+ .map(tool => {+ return `name="${tool.name}", description="${tool.description}", inputSchema=${JSON.stringify(+ tool.inputSchema,+ )}`;+ })+ .join('\n');+ response.push(toolDefinitionsMessage);+ }}}diff --git a/tests/McpResponse.test.js.snapshot b/tests/McpResponse.test.js.snapshotindex 940955cc..7508f604 100644--- a/tests/McpResponse.test.js.snapshot+++ b/tests/McpResponse.test.js.snapshot@@ -1470,6 +1470,17 @@ exports[`lighthouse > rounds category scores and shows unscored categories as n/}`;+exports[`third-party developer tools > lists no third-party developer tools if there are none 1`] = `+## Third-party developer tools+No third-party developer tools available.+`;++exports[`third-party developer tools > lists no third-party developer tools if there are none 2`] = `+{+ "thirdPartyDeveloperTools": []+}+`;+exports[`third-party developer tools > lists third-party developer tools 1`] = `## Third-party developer toolsMy Tool Group: A group of toolsdiff --git a/tests/McpResponse.test.ts b/tests/McpResponse.test.tsindex f68a847b..e1493749 100644--- a/tests/McpResponse.test.ts+++ b/tests/McpResponse.test.ts@@ -1180,6 +1180,23 @@ describe('third-party developer tools', () => {);});+ it('lists no third-party developer tools if there are none', async t => {+ const response = new McpResponse(+ createMockParsedArguments({categoryExperimentalThirdParty: true}),+ );+ const page = createMockMcpPage();+ page.getToolGroups.resolves([]);+ response.setPage(page);+ response.setListThirdPartyDeveloperTools();++ const context = createMockMcpContext();+ const {content, structuredContent} = await response.handle(context);+ const firstContent = content[0];+ assert.ok(firstContent);+ t.assert.snapshot(getTextContent(firstContent));+ t.assert.snapshot(stabilizeStructuredContent(structuredContent));+ });+async function testIncludesThirdPartyDeveloperTools(handlerAction: (response: McpResponse,diff --git a/tests/tools/thirdPartyDeveloper.test.ts b/tests/tools/thirdPartyDeveloper.test.tsindex 73cf76f7..5e322e2b 100644--- a/tests/tools/thirdPartyDeveloper.test.ts+++ b/tests/tools/thirdPartyDeveloper.test.ts@@ -17,9 +17,8 @@ import {executeThirdPartyDeveloperTool,listThirdPartyDeveloperTools,} from '../../src/tools/thirdPartyDeveloper.js';-import type {ToolGroups} from '../../src/tools/thirdPartyDeveloper.js';import {createHandlerMocks} from '../mocks.js';-import {withMcpContext} from '../utils.js';+import {getTextContent, withMcpContext} from '../utils.js';describe('thirdPartyDeveloperTools', () => {afterEach(() => {@@ -108,13 +107,14 @@ describe('thirdPartyDeveloperTools', () => {const result = await response.handle(context);assert.ok(result.structuredContent);- assert.deepStrictEqual(- (- result.structuredContent as {- thirdPartyDeveloperTools?: ToolGroups;- }- ).thirdPartyDeveloperTools,- undefined,+ assert.deepStrictEqual(result.structuredContent, {+ thirdPartyDeveloperTools: [],+ });+ const firstContent = result.content[0];+ assert.ok(firstContent);+ assert.strictEqual(+ getTextContent(firstContent),+ '## Third-party developer tools\nNo third-party developer tools available.',);},undefined,@@ -141,13 +141,14 @@ describe('thirdPartyDeveloperTools', () => {const result = await response.handle(context);assert.ok(result.structuredContent);- assert.deepStrictEqual(- (- result.structuredContent as {- thirdPartyDeveloperTools?: ToolGroups;- }- ).thirdPartyDeveloperTools,- undefined,+ assert.deepStrictEqual(result.structuredContent, {+ thirdPartyDeveloperTools: [],+ });+ const firstContent = result.content[0];+ assert.ok(firstContent);+ assert.strictEqual(+ getTextContent(firstContent),+ '## Third-party developer tools\nNo third-party developer tools available.',);},undefined,@@ -168,13 +169,14 @@ describe('thirdPartyDeveloperTools', () => {const result = await response.handle(context);assert.ok(result.structuredContent);- assert.deepStrictEqual(- (- result.structuredContent as {- thirdPartyDeveloperTools?: ToolGroups;- }- ).thirdPartyDeveloperTools,- undefined,+ assert.deepStrictEqual(result.structuredContent, {+ thirdPartyDeveloperTools: [],+ });+ const firstContent = result.content[0];+ assert.ok(firstContent);+ assert.strictEqual(+ getTextContent(firstContent),+ '## Third-party developer tools\nNo third-party developer tools available.',);},undefined,