Skip to main content
The createConnection function is the main entry point for creating a Playwright MCP server instance programmatically.

Function Signature

Parameters

config
Config
Optional configuration object to customize the MCP server behavior. See Configuration Schema for all available options.If not provided, defaults will be used (persistent profile, chromium browser, all core capabilities enabled).
contextGetter
() => Promise<BrowserContext>
Optional function that returns a Playwright BrowserContext. This allows you to provide your own browser context instead of letting the server create one.Useful for:
  • Using an existing authenticated browser session
  • Sharing a browser context across multiple connections
  • Custom context initialization logic

Return Value

Returns a Promise<Server> that resolves to an MCP Server instance from @modelcontextprotocol/sdk. The server instance can be connected to various transports:
  • SSE (Server-Sent Events) for HTTP-based communication
  • stdio for command-line based communication
  • Custom transports

Basic Example

HTTP Server Integration

Integrate with an HTTP server using SSE transport:

Custom Browser Context

Provide your own browser context for advanced control:

Configuration Examples

Headless with Specific Capabilities

Connect to Remote Browser

Connect via CDP Endpoint