Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(mcp): do not fail on wsl client w/ windows server (#38063)

Pavel Feldman1bc15f39ad4a
diff --git a/packages/playwright/src/mcp/sdk/server.ts b/packages/playwright/src/mcp/sdk/server.ts
index 5359ce9d2a..11ea8c438c 100644
--- a/packages/playwright/src/mcp/sdk/server.ts
+++ b/packages/playwright/src/mcp/sdk/server.ts
@@ -187,7 +187,12 @@ export function firstRootPath(clientInfo: ClientInfo): string | undefined {
return undefined;
const firstRootUri = clientInfo.roots[0]?.uri;
const url = firstRootUri ? new URL(firstRootUri) : undefined;
- return url ? fileURLToPath(url) : undefined;
+ try {
+ return url ? fileURLToPath(url) : undefined;
+ } catch (error) {
+ serverDebug(error);
+ return undefined;
+ }
}
function mergeTextParts(result: CallToolResult): CallToolResult {
diff --git a/tests/mcp/roots.spec.ts b/tests/mcp/roots.spec.ts
index 3a24b33e77..3a3615a113 100644
--- a/tests/mcp/roots.spec.ts
+++ b/tests/mcp/roots.spec.ts
@@ -100,6 +100,29 @@ test('should tolerate malformed roots', async ({ startClient, server }, testInfo
expect(file).toMatch(/mcp-.*/);
});
+test('should tolerate WSL client roots on Windows server', async ({ startClient, server }, testInfo) => {
+ test.skip(process.platform !== 'win32');
+ const { client } = await startClient({
+ clientName: 'client',
+ roots: [
+ {
+ name: 'test',
+ uri: 'file:///mnt/c/users/username/Desktop',
+ }
+ ],
+ });
+
+ 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);
}