MCP Playwright
Browser automation using Microsoft's Playwright MCP server
- Name: MCP Playwright
- Package:
@playwright/mcp - Provider: Microsoft
Overview
MCP Playwright is a third-party MCP server from Microsoft. It lets agents control a browser to navigate pages, interact with elements, take screenshots, and extract content.
Headless by Default
Playwright MCP runs in headless mode by default. Pass --headed via args if you need a visible browser for debugging.
Usage with ADK TypeScript
import { McpPlaywright } from "@iqai/adk";
const toolset = McpPlaywright();
const tools = await toolset.getTools();import { McpToolset } from "@iqai/adk";
const toolset = new McpToolset({
name: "Playwright MCP Client",
description: "Client for browser automation",
transport: {
mode: "stdio",
command: "npx",
args: ["-y", "@playwright/mcp"],
env: {
PATH: process.env.PATH || "",
},
},
});
const tools = await toolset.getTools();If you want to use this MCP with Claude Desktop, add this to your Claude Desktop configuration file:
MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["-y", "@playwright/mcp"]
}
}
}Environment Variables
No environment variables are required for the Playwright MCP server.
Configuration Options
All MCP servers support these configuration options:
| Option | Type | Description |
|---|---|---|
env | object | Environment variables (see table above) |
debug | boolean | Enable debug logging |
description | string | Custom description |
retryOptions.maxRetries | number | Max retry attempts (default: 2) |
retryOptions.initialDelay | number | Initial retry delay in ms (default: 200) |
samplingHandler | SamplingHandler | Handler for MCP sampling requests |
Available Tools
browser_closeNo parameters
browser_closeNo parameters
Description
Close the page
browser_resizewidth:numberheight:number
browser_resizeDescription
Resize the browser window
browser_console_messageslevel:stringfilename:string
browser_console_messagesDescription
Returns all console messages
browser_handle_dialogaccept:booleanpromptText:string
browser_handle_dialogDescription
Handle a dialog
browser_evaluatefunction:stringelement:stringref:string
browser_evaluateDescription
Evaluate JavaScript expression on page or element
browser_file_uploadpaths:array
browser_file_uploadDescription
Upload one or multiple files
browser_fill_formfields:array
browser_fill_formDescription
Fill multiple form fields
browser_installNo parameters
browser_installNo parameters
Description
Install the browser specified in the config. Call this if you get an error about the browser not being installed.
browser_press_keykey:string
browser_press_keyDescription
Press a key on the keyboard
browser_typeelement:stringref:stringtext:stringsubmit:booleanslowly:boolean
browser_typeDescription
Type text into editable element
browser_navigateurl:string
browser_navigateDescription
Navigate to a URL
browser_navigate_backNo parameters
browser_navigate_backNo parameters
Description
Go back to the previous page in the history
browser_network_requestsincludeStatic:booleanfilename:string
browser_network_requestsDescription
Returns all network requests since loading the page
browser_run_codecode:string
browser_run_codeDescription
Run Playwright code snippet
browser_take_screenshottype:stringfilename:stringelement:stringref:stringfullPage:boolean
browser_take_screenshotDescription
Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.
browser_snapshotfilename:string
browser_snapshotDescription
Capture accessibility snapshot of the current page, this is better than screenshot
browser_clickelement:stringref:stringdoubleClick:booleanbutton:stringmodifiers:array
browser_clickDescription
Perform click on a web page
browser_dragstartElement:stringstartRef:stringendElement:stringendRef:string
browser_dragDescription
Perform drag and drop between two elements
browser_hoverelement:stringref:string
browser_hoverDescription
Hover over element on page
browser_select_optionelement:stringref:stringvalues:array
browser_select_optionDescription
Select an option in a dropdown
browser_tabsaction:stringindex:number
browser_tabsDescription
List, create, close, or select a browser tab.
browser_wait_fortime:numbertext:stringtextGone:string
browser_wait_forDescription
Wait for text to appear or disappear or a specified time to pass
Complete Example
import { McpPlaywright, LlmAgent } from "@iqai/adk";
async function main() {
// Initialize Playwright toolset
const playwrightToolset = McpPlaywright({
debug: true,
});
try {
const tools = await playwrightToolset.getTools();
const agent = new LlmAgent({
name: "browser_agent",
model: "gemini-2.5-flash",
description: "An agent that can browse the web and extract information",
instruction: `You have access to a browser.
Navigate to pages, extract data, and interact with elements as needed.
Take a screenshot after navigating to confirm the page loaded.`,
tools,
});
const response = await agent.ask(
"Go to example.com and tell me what you see on the page",
);
console.log(response);
} finally {
await playwrightToolset.close();
}
}
main();Use Cases
- Web Scraping: Extract structured data from websites
- UI Testing: Automate browser-based testing workflows
- Form Automation: Fill and submit web forms programmatically
- Screenshot Capture: Take screenshots of web pages for analysis
- Navigation Monitoring: Track redirects and page behavior
- Content Extraction: Read and parse page content and metadata
Best Practices
- Cleanup: Always call
toolset.close()when done to free browser resources - Rate Limiting: Add delays between requests to avoid overloading servers
- Error Handling: Handle navigation errors and timeouts gracefully
- Respect robots.txt: Ensure you have permission to scrape target sites
- Headless Mode: Use headless mode in production for better performance
Troubleshooting
| Issue | Solution |
|---|---|
| Browser not launching | Ensure Playwright browsers are installed: npx playwright install |
| Navigation timeout | Increase timeout or check network connectivity |
| Element not found | Verify selectors and wait for page to fully load |
| Connection timeout | Check if npm/npx is installed and in PATH |
| Permission denied | Ensure the process has appropriate system permissions |