Skip to content

Chrome DevTools for coding agents

test: list tools in-process instead of starting a server per flag (#3193)

Alex Rudenko8ddce8fc0185
diff --git a/tests/McpServer.test.ts b/tests/McpServer.test.ts
index 23152091..c16f5a6a 100644
--- a/tests/McpServer.test.ts
+++ b/tests/McpServer.test.ts
@@ -5,16 +5,22 @@
*/
import assert from 'node:assert';
+import fs from 'node:fs';
import path from 'node:path';
import {afterEach, describe, it} from 'node:test';
+import {Client, InMemoryTransport} from '@modelcontextprotocol/client';
import sinon from 'sinon';
import {BrowserManager} from '../src/BrowserManager.js';
+import {getOffByDefaultCategories} from '../src/config/category-options.js';
import {ConfigParser} from '../src/config/ConfigParser.js';
+import {mcpOptions} from '../src/config/mcp-options.js';
import {McpServer} from '../src/index.js';
import {McpContext} from '../src/McpContext.js';
import {ClearcutLogger} from '../src/telemetry/ClearcutLogger.js';
+import type {ToolCategory} from '../src/tools/categories.js';
+import type {ToolDefinition} from '../src/tools/ToolDefinition.js';
import {createMockMcpContext, createMockPuppeteerBrowser} from './mocks.js';
@@ -136,4 +142,134 @@ describe('McpServer', () => {
]);
});
});
+
+ describe('tool list', () => {
+ async function listToolNames(extraArgs: string[] = []): Promise<string[]> {
+ const {server} = await createTestServer(extraArgs);
+ const [clientTransport, serverTransport] =
+ InMemoryTransport.createLinkedPair();
+ await server.connect(serverTransport);
+ const client = new Client({name: 'test', version: '1.0.0'});
+ await client.connect(clientTransport);
+ try {
+ const {tools} = await client.listTools();
+ return tools.map(tool => tool.name).sort();
+ } finally {
+ await client.close();
+ await server.close();
+ }
+ }
+
+ it('has all tools with off by default categories', async () => {
+ const exposedNames = await listToolNames(
+ getOffByDefaultCategories().map(category => `--category-${category}`),
+ );
+ const definedNames = await getToolsWithFilteredCategories();
+ assert.deepStrictEqual(exposedNames, definedNames.sort());
+ });
+
+ it('has all tools', async () => {
+ const exposedNames = await listToolNames();
+ const definedNames = await getToolsWithFilteredCategories(
+ getOffByDefaultCategories(),
+ );
+ assert.deepStrictEqual(exposedNames, definedNames.sort());
+ });
+
+ it('has experimental third-party developer tools', async () => {
+ const names = await listToolNames([
+ '--category-experimental-third-party',
+ ]);
+ assert.ok(names.includes('list_3p_developer_tools'));
+ });
+
+ it('has experimental extensions tools', async () => {
+ const names = await listToolNames(['--category-extensions']);
+ assert.ok(names.includes('install_extension'));
+ });
+
+ it('has experimental vision tools', async () => {
+ const names = await listToolNames(['--experimental-vision']);
+ assert.ok(names.includes('click_at'));
+ });
+
+ it('has experimental interop tools', async () => {
+ const names = await listToolNames(['--experimental-interop-tools']);
+ assert.ok(names.includes('get_tab_id'));
+ });
+
+ it('has experimental webmcp', async () => {
+ const names = await listToolNames(['--categoryExperimentalWebmcp']);
+ assert.ok(names.includes('list_webmcp_tools'));
+ assert.ok(names.includes('execute_webmcp_tool'));
+ });
+
+ it('has memory debugging tools', async () => {
+ const names = await listToolNames(['--memoryDebugging']);
+ assert.ok(names.includes('get_heapsnapshot_summary'));
+ });
+
+ it('can disable javascript evaluation tools', async () => {
+ const names = await listToolNames(['--no-javascript-evaluation']);
+ assert.ok(!names.includes('evaluate_script'));
+ });
+ });
});
+
+async function getToolsWithFilteredCategories(
+ filterOutCategories: ToolCategory[] = [],
+): Promise<string[]> {
+ const files = fs.readdirSync('build/src/tools');
+ const definedNames = [];
+ for (const file of files) {
+ if (
+ !file.endsWith('.js') ||
+ file === 'ToolDefinition.js' ||
+ file === 'tools.js' ||
+ file === 'slim'
+ ) {
+ continue;
+ }
+ const fileTools = await import(`../src/tools/${file}`);
+
+ for (const maybeTool of Object.values(fileTools)) {
+ if (typeof maybeTool !== 'function') {
+ continue;
+ }
+ const tool = maybeTool({});
+
+ // Skipping all files that are not tool files
+ if (tool === null || typeof tool !== 'object' || !('name' in tool)) {
+ continue;
+ }
+
+ if (toolShouldBeSkipped(tool, filterOutCategories)) {
+ continue;
+ }
+ definedNames.push(tool.name);
+ }
+ }
+ return definedNames;
+}
+
+function toolShouldBeSkipped(
+ tool: ToolDefinition,
+ filteredOutCategories: ToolCategory[],
+) {
+ if (tool.annotations?.conditions) {
+ for (const condition of tool.annotations.conditions) {
+ const option = mcpOptions[condition as keyof typeof mcpOptions];
+ if (!option || !('default' in option) || option.default !== true) {
+ return true;
+ }
+ }
+ }
+ if (
+ tool.annotations?.category &&
+ filteredOutCategories.includes(tool.annotations?.category)
+ ) {
+ return true;
+ }
+
+ return false;
+}
diff --git a/tests/index.test.ts b/tests/index.test.ts
index f336c402..a3c70933 100644
--- a/tests/index.test.ts
+++ b/tests/index.test.ts
@@ -5,7 +5,6 @@
*/
import assert from 'node:assert';
-import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import {describe, it} from 'node:test';
@@ -15,11 +14,7 @@ import {executablePath} from 'puppeteer';
import {Client, type ClientCapabilities} from '@modelcontextprotocol/client';
import {StdioClientTransport} from '@modelcontextprotocol/client/stdio';
-import {mcpOptions} from '../src/config/mcp-options.js';
-import {getOffByDefaultCategories} from '../src/config/category-options.js';
import type {TextContent} from '../src/third_party/index.js';
-import type {ToolCategory} from '../src/tools/categories.js';
-import type {ToolDefinition} from '../src/tools/ToolDefinition.js';
import {createTempDir} from './utils.js';
@@ -123,123 +118,6 @@ describe('e2e', {concurrency: true}, () => {
});
});
- // These tests only list tools, so the server does not launch a browser.
- describe('tool list', {concurrency: true}, () => {
- it('has all tools with off by default categories', async () => {
- await withClient(
- async client => {
- const {tools} = await client.listTools();
- const exposedNames = tools.map(t => t.name).sort();
- const definedNames = await getToolsWithFilteredCategories();
- definedNames.sort();
- assert.deepStrictEqual(exposedNames, definedNames);
- },
- getOffByDefaultCategories().map(category => `--category-${category}`),
- );
- });
-
- it('has all tools', async () => {
- await withClient(async client => {
- const {tools} = await client.listTools();
- const exposedNames = tools.map(t => t.name).sort();
- const definedNames = await getToolsWithFilteredCategories(
- getOffByDefaultCategories(),
- );
- definedNames.sort();
- assert.deepStrictEqual(exposedNames, definedNames);
- });
- });
-
- it('has experimental third-party developer tools', async () => {
- await withClient(
- async client => {
- const {tools} = await client.listTools();
- const listThirdPartyDeveloperTools = tools.find(
- t => t.name === 'list_3p_developer_tools',
- );
- assert.ok(listThirdPartyDeveloperTools);
- },
- ['--category-experimental-third-party'],
- );
- });
-
- it('has experimental extensions tools', async () => {
- await withClient(
- async client => {
- const {tools} = await client.listTools();
- const installExtension = tools.find(
- t => t.name === 'install_extension',
- );
- assert.ok(installExtension);
- },
- ['--category-extensions'],
- );
- });
-
- it('has experimental vision tools', async () => {
- await withClient(
- async client => {
- const {tools} = await client.listTools();
- const clickAt = tools.find(t => t.name === 'click_at');
- assert.ok(clickAt);
- },
- ['--experimental-vision'],
- );
- });
-
- it('has experimental interop tools', async () => {
- await withClient(
- async client => {
- const {tools} = await client.listTools();
- const getTabId = tools.find(t => t.name === 'get_tab_id');
- assert.ok(getTabId);
- },
- ['--experimental-interop-tools'],
- );
- });
-
- it('has experimental webmcp', async () => {
- await withClient(
- async client => {
- const {tools} = await client.listTools();
- const listWebMcpTools = tools.find(
- t => t.name === 'list_webmcp_tools',
- );
- const executeWebMcpTool = tools.find(
- t => t.name === 'execute_webmcp_tool',
- );
- assert.ok(listWebMcpTools);
- assert.ok(executeWebMcpTool);
- },
- ['--categoryExperimentalWebmcp'],
- );
- });
-
- it('has memory debugging tools', async () => {
- await withClient(
- async client => {
- const {tools} = await client.listTools();
- const getHeapSnapshotSummary = tools.find(
- t => t.name === 'get_heapsnapshot_summary',
- );
- assert.ok(getHeapSnapshotSummary);
- },
- ['--memoryDebugging'],
- );
- });
-
- it('can disable javascript evaluation tools', async () => {
- await withClient(
- async client => {
- const {tools} = await client.listTools();
- const evaluateScript = tools.find(t => t.name === 'evaluate_script');
- assert.strictEqual(evaluateScript, undefined);
- },
- ['--no-javascript-evaluation'],
- );
- });
- });
-
it('updates roots when client notifies', async () => {
const roots = [{uri: 'file:///test-root', name: 'test-root'}];
let resolvePromise: () => void;
@@ -543,61 +421,3 @@ describe('e2e', {concurrency: true}, () => {
});
});
});
-
-async function getToolsWithFilteredCategories(
- filterOutCategories: ToolCategory[] = [],
-): Promise<string[]> {
- const files = fs.readdirSync('build/src/tools');
- const definedNames = [];
- for (const file of files) {
- if (
- !file.endsWith('.js') ||
- file === 'ToolDefinition.js' ||
- file === 'tools.js' ||
- file === 'slim'
- ) {
- continue;
- }
- const fileTools = await import(`../src/tools/${file}`);
-
- for (const maybeTool of Object.values(fileTools)) {
- if (typeof maybeTool !== 'function') {
- continue;
- }
- const tool = maybeTool({});
-
- // Skipping all files that are not tool files
- if (tool === null || typeof tool !== 'object' || !('name' in tool)) {
- continue;
- }
-
- if (toolShouldBeSkipped(tool, filterOutCategories)) {
- continue;
- }
- definedNames.push(tool.name);
- }
- }
- return definedNames;
-}
-
-function toolShouldBeSkipped(
- tool: ToolDefinition,
- filteredOutCategories: ToolCategory[],
-) {
- if (tool.annotations?.conditions) {
- for (const condition of tool.annotations.conditions) {
- const option = mcpOptions[condition as keyof typeof mcpOptions];
- if (!option || !('default' in option) || option.default !== true) {
- return true;
- }
- }
- }
- if (
- tool.annotations?.category &&
- filteredOutCategories.includes(tool.annotations?.category)
- ) {
- return true;
- }
-
- return false;
-}