diff --git a/src/mcp/server.ts b/src/mcp/server.ts index b79ad17..3ac389e 100644 --- a/src/mcp/server.ts +++ b/src/mcp/server.ts @@ -54,6 +54,7 @@ export function createServer(backend: ServerBackend, runHeartbeat: boolean): Ser server.setRequestHandler(ListToolsRequestSchema, async () => { serverDebug('listTools'); + await initializedPromise; const tools = await backend.listTools(); return { tools }; }); diff --git a/tests/fixtures.ts b/tests/fixtures.ts index 3c91edd..c02d5c4 100644 --- a/tests/fixtures.ts +++ b/tests/fixtures.ts @@ -47,6 +47,7 @@ type TestFixtures = { args?: string[], config?: Config, roots?: { name: string, uri: string }[], + rootsResponseDelay?: number, }) => Promise<{ client: Client, stderr: () => string }>; wsEndpoint: string; cdpServer: CDPServer; @@ -89,6 +90,8 @@ export const test = baseTest.extend( client = new Client({ name: options?.clientName ?? 'test', version: '1.0.0' }, options?.roots ? { capabilities: { roots: {} } } : undefined); if (options?.roots) { client.setRequestHandler(ListRootsRequestSchema, async request => { + if (options.rootsResponseDelay) + await new Promise(resolve => setTimeout(resolve, options.rootsResponseDelay)); return { roots: options.roots, }; diff --git a/tests/roots.spec.ts b/tests/roots.spec.ts index 0032d8b..a94191e 100644 --- a/tests/roots.spec.ts +++ b/tests/roots.spec.ts @@ -50,7 +50,7 @@ for (const mode of ['default', 'proxy']) { }); - test('check that trace is saved in workspace', async ({ startClient, server, mcpMode }, testInfo) => { + test('check that trace is saved in workspace', async ({ startClient, server }, testInfo) => { const rootPath = testInfo.outputPath('workspace'); const { client } = await startClient({ args: ['--save-trace', ...extraArgs], @@ -73,5 +73,15 @@ for (const mode of ['default', 'proxy']) { const [file] = await fs.promises.readdir(path.join(rootPath, '.playwright-mcp')); expect(file).toContain('traces'); }); + + test('should list all tools when listRoots is slow', async ({ startClient, server }, testInfo) => { + const { client } = await startClient({ + clientName: 'Visual Studio Code', // Simulate VS Code client, roots only work with it + roots: [], + rootsResponseDelay: 1000, + }); + const tools = await client.listTools(); + expect(tools.tools.length).toBeGreaterThan(20); + }); }); }