Chrome DevTools for coding agents
refactor: register all tools upfront across modes (#3163)
Nikolay Vitkov58f8d1f5c8b0
diff --git a/src/index.ts b/src/index.tsindex 4e68ab08..7feb87cd 100644--- a/src/index.ts+++ b/src/index.ts@@ -27,7 +27,6 @@ import {import {ToolHandler} from './ToolHandler.js';import {type DefinedPageTool,- isAvailableInMode,type ToolDefinition,} from './tools/ToolDefinition.js';import {createTools} from './tools/tools.js';@@ -212,10 +211,7 @@ export class McpServer {async #init(): Promise<void> {for (const tool of createTools(this.#serverArgs)) {- // Slim and regular tools may share names, only register the current mode.- if (isAvailableInMode(tool, this.#serverArgs)) {- this.#registerTool(tool);- }+ this.#registerTool(tool);}await loadIssueDescriptions();}diff --git a/src/tools/ToolDefinition.ts b/src/tools/ToolDefinition.tsindex 6a7483d3..3f0d2d0a 100644--- a/src/tools/ToolDefinition.ts+++ b/src/tools/ToolDefinition.ts@@ -94,8 +94,8 @@ export interface BaseToolDefinition<readOnlyHint: boolean;/*** If `'slim'` is included, the tool is only available with `--slim`. Tools- * without `'slim'` are only available without `--slim`. Slim tools may- * reuse the names of other tools, see {@link isAvailableInMode}.+ * without `'slim'` are only available without `--slim`, see+ * {@link isAvailableInMode}.*/conditions?: Array<keyof ParsedArguments>;};@@ -619,10 +619,8 @@ export function isSlimTool(}/**- * Slim mode replaces the regular tools with the slim tools. Only the tools of- * the current mode are registered, so a slim tool may share its name with a- * regular tool. `--slim` requires a restart, so the mode never changes while- * the server is running.+ * Slim mode replaces the regular tools with the slim tools. `--slim` requires+ * a restart, so the mode never changes while the server is running.*/export function isAvailableInMode(tool: Pick<BaseToolDefinition, 'annotations'>,diff --git a/tests/McpServer.test.ts b/tests/McpServer.test.tsindex 12cd5081..3124e59e 100644--- a/tests/McpServer.test.ts+++ b/tests/McpServer.test.ts@@ -88,23 +88,28 @@ describe('McpServer', () => {});describe('slim mode', () => {- it('does not register slim tools without --slim', async () => {+ it('disables slim tools without --slim', async () => {const {server} = await createTestServer();const result = await server.callTool('navigate', {url: 'about:blank'});+ assert.strictEqual(result.isError, true);assert.deepStrictEqual(result.content, [- {type: 'text', text: 'Tool navigate not found'},+ {type: 'text', text: 'Tool navigate is only available with --slim.'},]);});- it('registers only slim tools with --slim', async () => {+ it('disables non-slim tools with --slim', async () => {const {server} = await createTestServer(['--slim']);const result = await server.callTool('list_pages');+ assert.strictEqual(result.isError, true);assert.deepStrictEqual(result.content, [- {type: 'text', text: 'Tool list_pages not found'},+ {+ type: 'text',+ text: 'Tool list_pages is not available with --slim.',+ },]);});});diff --git a/tests/tools/tools.test.ts b/tests/tools/tools.test.tsindex 01d09637..6e6545ff 100644--- a/tests/tools/tools.test.ts+++ b/tests/tools/tools.test.ts@@ -8,23 +8,18 @@ import assert from 'node:assert';import {describe, it} from 'node:test';import {ConfigParser} from '../../src/config/ConfigParser.js';-import {isAvailableInMode} from '../../src/tools/ToolDefinition.js';import {createTools} from '../../src/tools/tools.js';describe('createTools', () => {- for (const extraArgs of [[], ['--slim']]) {- it(`has unique tool names with [${extraArgs.join(' ')}]`, () => {- const serverArgs = new ConfigParser(- '0.0.0',- ['node', 'script.js', ...extraArgs],- {},- ).parse();+ it('has unique tool names', () => {+ const serverArgs = new ConfigParser(+ '0.0.0',+ ['node', 'script.js'],+ {},+ ).parse();- const names = createTools(serverArgs)- .filter(tool => isAvailableInMode(tool, serverArgs))- .map(tool => tool.name);+ const names = createTools(serverArgs).map(tool => tool.name);- assert.strictEqual(new Set(names).size, names.length);- });- }+ assert.strictEqual(new Set(names).size, names.length);+ });});