mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2025-10-12 00:25:14 +03:00
fix: wait for initialization to complete before listing tools (#886)
This commit is contained in:
@@ -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 };
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user