playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[MCP]: explicit filename fails with EPERM when the server cwd is C:\Windows\System32 (no fallback as in #40544)

Open igorsaevets opened this issue 2 weeks ago • 2 comments

What's going on?

I hit this in Claude Desktop (chat) on Windows. Claude Desktop sends no MCP roots (its initialize has no roots capability) and starts stdio servers with cwd C:\Windows\System32.

Without roots, an explicit filename is resolved against the server cwd. That is by design (#42487, microsoft/playwright-mcp#1595) and I am not asking to change it. The problem is that this fallback is used even when the cwd is a directory that #40544 already treats as unsuitable for output. Every explicitly named file then fails. The same call without filename works, because the output dir falls back to %TEMP%\.playwright-mcp. --output-dir does not help, since it only moves automatically named files. Claude Desktop's MCP log on my machine shows this failure 19 times since May. Each time it was an explicitly named file directly in System32 (.png, .md, .jpeg, .json).

Steps to reproduce (Windows 11, non-elevated user, Node v24.21.0)

  1. Save repro.mjs from below. It is a minimal stdio client that does not advertise roots.
  2. Run node repro.mjs C:\Windows\System32. It starts npx -y @playwright/[email protected] --headless --isolated in that cwd and calls:
call result
browser_take_screenshot {} ok, saved as %TEMP%\.playwright-mcp\page-<timestamp>.png
browser_take_screenshot { filename: "shot.png" } Error: EPERM: operation not permitted, open 'C:\Windows\System32\shot.png'
browser_evaluate { function: "() => 1", filename: "result.json" } EPERM: operation not permitted, open 'C:\Windows\System32\result.json'

The same calls with other settings:

  • cwd = a writable folder: both named files are written there.
  • --output-dir <writable folder>: the unnamed screenshot goes there, but both named calls still fail.
  • A client that answers roots/list: both named files land in the root.
repro.mjs (no dependencies)
// Usage: node repro.mjs <cwd for the server>
import { spawn, execSync } from 'node:child_process';

const cwd = process.argv[2] ?? process.cwd();
const server = spawn('npx -y @playwright/[email protected] --headless --isolated', { cwd, shell: true, stdio: ['pipe', 'pipe', 'inherit'] });
const pending = new Map();
let buffer = '', nextId = 0;
const send = msg => server.stdin.write(JSON.stringify({ jsonrpc: '2.0', ...msg }) + '\n');
server.stdout.on('data', chunk => {
  buffer += chunk;
  for (let i; (i = buffer.indexOf('\n')) >= 0;) {
    const line = buffer.slice(0, i).trim();
    buffer = buffer.slice(i + 1);
    if (!line) continue;
    const msg = JSON.parse(line);
    if (msg.method && msg.id !== undefined) send({ id: msg.id, result: {} }); // answer ping
    else if (msg.id !== undefined) pending.get(msg.id)?.(msg);
  }
});
const request = (method, params) => new Promise(resolve => { pending.set(++nextId, resolve); send({ id: nextId, method, params }); });
const tool = async (name, args) => {
  const { result } = await request('tools/call', { name, arguments: args });
  const text = result.content.map(c => c.text ?? '').join('\n');
  const line = text.split('\n').find(l => /EPERM|EACCES|ENOENT|\]\(/.test(l)) ?? '';
  console.log(`${name} ${JSON.stringify(args)} -> ${result.isError ? 'ERROR' : 'ok'} ${line.trim()}`);
};

await request('initialize', { protocolVersion: '2025-06-18', capabilities: {}, clientInfo: { name: 'repro', version: '1.0.0' } });
send({ method: 'notifications/initialized' });
await tool('browser_navigate', { url: 'about:blank' });
await tool('browser_take_screenshot', {});
await tool('browser_take_screenshot', { filename: 'shot.png' });
await tool('browser_evaluate', { function: '() => 1', filename: 'result.json' });
await tool('browser_close', {});
server.stdin.end();
if (process.platform === 'win32') try { execSync(`taskkill /pid ${server.pid} /T /F`, { stdio: 'ignore' }); } catch {}
else server.kill();
process.exit(0);

Expected

The cwd fallback for explicit names should apply the same check as outputDir(). When there are no roots and the cwd is a system or unwritable directory, relative names would resolve against outputDir(). If you prefer to keep the resolution, then at least an error that says the name was resolved against the server cwd because the client sent no roots. The model can recover from that by dropping filename.

Cause (main @ b4d016a; the same functions are in the 0.0.85 bundle)

Second finding: isWritable() passes for protected folders on Windows

isWritable() (fileUtils.ts#L48-L55) uses fs.accessSync(dir, W_OK). On Windows that call "does not check the ACL". Here it passes for C:\Windows\System32 and C:\Program Files, while real writes to both fail with EPERM. So on Windows the #40544 fallback works only through isSystemDirectory(), and the fix above would depend on the same check. With node repro.mjs "C:\Program Files" even the first call fails:

browser_navigate {"url":"about:blank"} -> ERROR Error: EPERM: operation not permitted, mkdir 'C:\Program Files\.playwright-mcp'

I have not seen a client start servers in that folder.

Environment: Windows 11 Pro 10.0.26200 x64, Node v24.21.0, npx, default browser (Chrome). The client is Claude Desktop (clientInfo.name claude-ai), and the bug reproduces with the minimal client above.

Related: #40544, microsoft/playwright-mcp#1582, #42487, #42528.

Version

@playwright/mcp 0.0.85 (playwright-core 1.66.0-alpha-2026-11-09)

igorsaevets avatar Nov 16 '26 11:11 igorsaevets

Hi, I'm the Playwright bot. I started triaging this issue on Windows: agent run

Hi, I'm the Playwright bot. I reproduced this on Windows.

Reproduced at 826ce42b8664ea940424e77ce51f1cdf96dcd37f (1.66.0-next). Explicit relative filenames bypass the fallback used for automatically named files. The proposed fix applies the same directory check to both paths, including a real write check for Windows permissions. Writable workspaces, absolute filenames and file reads keep their current behavior.

Reproduction and checks

The regression uses a fixture-owned directory with file and directory creation denied, rather than writing into System32:

const cwd = testInfo.outputPath('readonly');
const outputDir = testInfo.outputPath('output');
await fs.promises.mkdir(cwd);
execFileSync('icacls', [cwd, '/deny', '*S-1-1-0:(WD,AD)']);
const { client } = await startClient({
  cwd,
  args: ['--file-paths=absolute', `--output-dir=${outputDir}`],
});
await client.callTool({
  name: 'browser_navigate',
  arguments: { url: server.HELLO_WORLD },
});
await client.callTool({
  name: 'browser_take_screenshot',
  arguments: { filename: 'sub/screenshot.png' },
});
expect(fs.existsSync(path.join(outputDir, 'sub', 'screenshot.png'))).toBe(true);

Without the fix, Chrome fails with EPERM creating readonly\sub. With the fix, the filename tests pass in Chrome, Chromium, Firefox, WebKit and Edge: 10 passed. The related screenshot, roots, upload and configuration tests also passed: 254 passed, 356 expected skips across those five configurations. Build and npm run flint passed.

Checks used Windows and Node.js 24.22.2. The permission-sensitive runs removed backup and restore privileges from the test process and its children; the runner otherwise lets Node bypass directory permissions. The regression skips such accounts. Missing pinned Chromium, Firefox and WebKit binaries were installed before the successful runs. The existing System32 automatic-output fallback was also checked without writing into System32.

Draft PR: https://github.com/microsoft/playwright/pull/44155

Triaged on Windows by the Playwright bot - agent run