fix: wait for initialization to complete before listing tools (#886)

This commit is contained in:
Yury Semikhatsky
2025-08-13 17:29:10 -07:00
committed by GitHub
parent 73adb0fdf0
commit 12942b81d6
3 changed files with 15 additions and 1 deletions

View File

@@ -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 };
});

View File

@@ -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<TestFixtures & TestOptions, WorkerFixtures>(
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,
};

View File

@@ -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);
});
});
}