How to set custom HTTP headers (X-Tenant-ID) in playwright-mcp for multi-tenant testing?
How do I set custom HTTP headers such as X-Tenant-ID in playwright-mcp for multi-tenant testing? I need the MCP agent's browser session to send a tenant header on every request, but playwright-mcp appears to have no built-in way to set headers. Is there a configuration or workaround, and is this supported yet?
Originally asked on GitHub: https://github.com/microsoft/playwright-mcp/issues/925
3 answers
Closed as implemented via microsoft/playwright#39377; the thread does not state which Playwright MCP release contains the fix. Until then, a maintainer said you can already get tenant-specific headers today by running separate MCP servers with different configurations, using either STDIO or HTTP transports. So the practical workaround is: run one MCP server per tenant context, configure each server with the appropriate custom header (e.g.
X-Tenant-ID: tenant-123), and switch MCP servers in your client when you need a different tenant. The maintainer also noted the preferred implementation isbrowserContext.setExtraHTTPHeaders, using routing only where absolutely necessary, and that the new tool should be opt-in so it does not increase the default number of exposed tools.General advice: if your headers contain auth tokens, load them from environment variables instead of hardcoding them in MCP config files.
Did this work for you?What a GitHub user tried on GitHub (Outcome unclear)
The reporter submitted PR microsoft/playwright-mcp#801 to implement custom header support; the PR is referenced as closed later in the thread, but the final resolution is not described there.
Source: https://github.com/microsoft/playwright-mcp/issues/925 (opens external site)
Did this work for you?What @pavelfeldman tried on GitHub (Worked)
A maintainer stated you can run different MCP servers with different configs (STDIO or HTTP transports) to get different headers today.
Source: https://github.com/microsoft/playwright-mcp/issues/925#issuecomment-3474943718 (opens external site)
Did this work for you?
Related questions
- Playwright MCP browser_take_screenshot shows no saved file or unreadable image in Cursor or VS Code
- Windows: playwright-mcp via Claude Desktop fails: Chromium distribution 'chrome' is not found
- playwright-mcp fails to start in Cursor after 0.0.19/0.0.20 (Client closed / Connection closed)
- Can I generate codegen-style Playwright test code from a prompt-driven playwright-mcp flow?
- Does Playwright MCP have a quiet mode to reduce page snapshot tokens?