Skip to main content
This example demonstrates how to use the Playwright MCP server to give agents web browsing capabilities.

What You’ll Learn

  • How to set up and use MCP servers
  • How to create a web browsing assistant
  • How to handle streaming responses with tools
  • Security considerations for MCP servers

Prerequisites

1

Install AutoGen and MCP

2

Install Playwright MCP Server

3

Set your OpenAI API key

Code Example

Run the Example

Expected Output

How It Works

  1. MCP Server: Playwright MCP server provides web automation tools
  2. McpWorkbench: Manages the connection to the MCP server
  3. Tool Discovery: Agent automatically discovers available tools from the server
  4. Execution: Agent uses tools like navigate, screenshot, click to browse the web
  5. Context Manager: async with ensures proper cleanup of resources

Available MCP Tools

The Playwright MCP server provides several tools:
  • navigate(url): Navigate to a URL
  • screenshot(): Take a screenshot of the current page
  • click(selector): Click an element
  • fill(selector, value): Fill a form field
  • evaluate(script): Execute JavaScript
  • get_text(selector): Extract text from elements

Using Multiple MCP Servers

You can connect to multiple MCP servers simultaneously:

Security Warning

Only connect to trusted MCP servers as they may:
  • Execute commands in your local environment
  • Access your filesystem
  • Expose sensitive information
  • Make network requests
Always review the MCP server’s source code before use in production.

Common Use Cases

Research

Gather information from multiple websites automatically.

Testing

Automate web application testing and validation.

Data Extraction

Scrape structured data from web pages.

Monitoring

Track changes on websites over time.

Troubleshooting

Browser Not Found

If you get a “browser not found” error:

Connection Timeout

Increase the timeout in server parameters:

Next Steps

Code Execution

Execute code safely within agent workflows

Research Assistant

Build a complete research assistant application