Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(mcp): tolerate malformed roots (#37492)
Pavel Feldmanafb59a0ec022
diff --git a/packages/playwright/src/mcp/sdk/server.ts b/packages/playwright/src/mcp/sdk/server.tsindex 81e2f40e83..b95c575925 100644--- a/packages/playwright/src/mcp/sdk/server.ts+++ b/packages/playwright/src/mcp/sdk/server.ts@@ -97,7 +97,10 @@ const initializeServer = async (server: Server, backend: ServerBackend, runHeartconst capabilities = server.getClientCapabilities();let clientRoots: Root[] = [];if (capabilities?.roots) {- const { roots } = await server.listRoots();+ const { roots } = await server.listRoots().catch(e => {+ serverDebug(e);+ return { roots: [] };+ });clientRoots = roots;}diff --git a/tests/mcp/roots.spec.ts b/tests/mcp/roots.spec.tsindex 904a3265be..3a24b33e77 100644--- a/tests/mcp/roots.spec.ts+++ b/tests/mcp/roots.spec.ts@@ -78,6 +78,28 @@ test('should list all tools when listRoots is slow', async ({ startClient }) =>expect(tools.tools.length).toBeGreaterThan(10);});+test('should tolerate malformed roots', async ({ startClient, server }, testInfo) => {+ const { client } = await startClient({+ clientName: 'Visual Studio Code',+ roots: [+ {+ name: 'test',+ uri: 'bogus://' + p.replace(/\\/g, '/'),+ }+ ],+ });++ expect(await client.callTool({+ name: 'browser_navigate',+ arguments: { url: server.HELLO_WORLD },+ })).toHaveResponse({+ code: expect.stringContaining(`page.goto('http://localhost`),+ });++ const [file] = await fs.promises.readdir(testInfo.outputPath('ms-playwright'));+ expect(file).toMatch(/mcp-.*/);+});+function createHash(data: string): string {return crypto.createHash('sha256').update(data).digest('hex').slice(0, 7);}