Chrome DevTools for coding agents
fix: print the no-roots temp-directory warning under default flags (#2927)
Matt Van Horn0dd8ed979ed1
diff --git a/src/index.ts b/src/index.tsindex 6a3549b7..7cfcaa2a 100644--- a/src/index.ts+++ b/src/index.ts@@ -10,6 +10,7 @@ import {pathToFileURL} from 'node:url';import {BrowserManager} from './BrowserManager.js';import {type ParsedArguments} from './config/ConfigParser.js';+import {DEFAULT_FILESYSTEM_ROOT} from './config/mcp-options.js';import {loadIssueDescriptions} from './devtools/issueDescriptions.js';import {McpContext} from './McpContext.js';import {HeapSnapshotManager} from './processors/HeapSnapshotManager.js';@@ -136,7 +137,8 @@ export class McpServer {);} else if (!this.#serverArgs.allowUnrestrictedPaths &&- (this.#serverArgs.filesystemRoot ?? []).length === 0+ ((this.#serverArgs.filesystemRoot ?? []).length === 0 ||+ this.#serverArgs.filesystemRoot === DEFAULT_FILESYSTEM_ROOT)) {console.warn('[chrome-devtools-mcp] The connecting client did not negotiate the MCP roots ' +diff --git a/tests/McpServer.test.ts b/tests/McpServer.test.tsindex c16f5a6a..47e827b0 100644--- a/tests/McpServer.test.ts+++ b/tests/McpServer.test.ts@@ -23,6 +23,7 @@ import type {ToolCategory} from '../src/tools/categories.js';import type {ToolDefinition} from '../src/tools/ToolDefinition.js';import {createMockMcpContext, createMockPuppeteerBrowser} from './mocks.js';+import {createTempFile} from './utils.js';describe('McpServer', () => {afterEach(() => {@@ -143,6 +144,78 @@ describe('McpServer', () => {});});+ describe('oninitialized', () => {+ const tempDirectoryWarning =+ '[chrome-devtools-mcp] The connecting client did not negotiate the MCP roots ' ++ 'capability. Tools that read or write local files will be restricted to the OS temp directory. ' ++ 'To restore the previous unrestricted behavior, start the server with ' ++ '--allow-unrestricted-paths.';++ async function warnOnInitialized(+ extraArgs: string[] = [],+ clientHasRoots = false,+ ) {+ const {server} = await createTestServer(extraArgs);+ const protocol = server.server.server;+ sinon+ .stub(protocol, 'getClientCapabilities')+ .returns(clientHasRoots ? {roots: {}} : {});+ sinon.stub(protocol, 'getClientVersion').returns(undefined);+ if (clientHasRoots) {+ sinon.stub(protocol, 'request').resolves({roots: []});+ }+ const warnStub = sinon.stub(console, 'warn');+ const oninitialized = protocol.oninitialized;+ assert.ok(oninitialized);+ oninitialized();+ await Promise.resolve();+ return warnStub;+ }++ it('warns when default flags meet a client without roots', async () => {+ const warnStub = await warnOnInitialized();++ sinon.assert.calledOnceWithExactly(warnStub, tempDirectoryWarning);+ });++ it('warns when filesystem roots are explicitly empty', async () => {+ using configFile = createTempFile(+ JSON.stringify({filesystemRoot: []}),+ 'cd4a.test.config.empty-filesystem-root.json',+ );++ const warnStub = await warnOnInitialized(['--config', configFile.path]);++ sinon.assert.calledOnceWithExactly(warnStub, tempDirectoryWarning);+ });++ it('does not warn for an explicit workspace', async () => {+ const warnStub = await warnOnInitialized([+ '--workspace=/tmp/explicit-workspace',+ ]);++ sinon.assert.notCalled(warnStub);+ });++ it('does not warn when unrestricted paths are allowed', async () => {+ const warnStub = await warnOnInitialized(['--allow-unrestricted-paths']);++ sinon.assert.notCalled(warnStub);+ });++ it('does not warn when started via the CLI', async () => {+ const warnStub = await warnOnInitialized(['--viaCli']);++ sinon.assert.notCalled(warnStub);+ });++ it('does not warn when the client negotiates roots', async () => {+ const warnStub = await warnOnInitialized([], true);++ sinon.assert.notCalled(warnStub);+ });+ });+describe('tool list', () => {async function listToolNames(extraArgs: string[] = []): Promise<string[]> {const {server} = await createTestServer(extraArgs);