Skip to content

Commit afb59a0

Browse files
authored
fix(mcp): tolerate malformed roots (#37492)
1 parent c7b7f3f commit afb59a0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

packages/playwright/src/mcp/sdk/server.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ const initializeServer = async (server: Server, backend: ServerBackend, runHeart
9797
const capabilities = server.getClientCapabilities();
9898
let clientRoots: Root[] = [];
9999
if (capabilities?.roots) {
100-
const { roots } = await server.listRoots();
100+
const { roots } = await server.listRoots().catch(e => {
101+
serverDebug(e);
102+
return { roots: [] };
103+
});
101104
clientRoots = roots;
102105
}
103106

tests/mcp/roots.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ test('should list all tools when listRoots is slow', async ({ startClient }) =>
7878
expect(tools.tools.length).toBeGreaterThan(10);
7979
});
8080

81+
test('should tolerate malformed roots', async ({ startClient, server }, testInfo) => {
82+
const { client } = await startClient({
83+
clientName: 'Visual Studio Code',
84+
roots: [
85+
{
86+
name: 'test',
87+
uri: 'bogus://' + p.replace(/\\/g, '/'),
88+
}
89+
],
90+
});
91+
92+
expect(await client.callTool({
93+
name: 'browser_navigate',
94+
arguments: { url: server.HELLO_WORLD },
95+
})).toHaveResponse({
96+
code: expect.stringContaining(`page.goto('http://localhost`),
97+
});
98+
99+
const [file] = await fs.promises.readdir(testInfo.outputPath('ms-playwright'));
100+
expect(file).toMatch(/mcp-.*/);
101+
});
102+
81103
function createHash(data: string): string {
82104
return crypto.createHash('sha256').update(data).digest('hex').slice(0, 7);
83105
}

0 commit comments

Comments
 (0)