Skip to main content

Using MCP Servers with Agents

The Model Context Protocol (MCP) provides a standardized way to connect AI agents to external tools and data sources. AutoGen supports MCP servers through the McpWorkbench class.
Only connect to trusted MCP servers. Servers can execute commands in your local environment and access sensitive information.

Quick Start with Playwright MCP

Create a web browsing assistant using the Playwright MCP server:

McpWorkbench Overview

The McpWorkbench class wraps MCP servers and provides:
  • Tools: List and call server-provided tools
  • Resources: Access server resources
  • Prompts: Use server-defined prompts
  • Automatic Integration: Tools automatically available to agents

Connection Types

Stdio Connection

Connect to MCP servers running as child processes:

SSE Connection

Connect to MCP servers over HTTP with Server-Sent Events:

Using Multiple MCP Servers

Connect agents to multiple MCP servers simultaneously:

GitHub MCP Server Example

Connect to the GitHub MCP server:

Tool Overrides

Customize how MCP tools appear to agents:

Listing Available Tools

Query MCP servers for available tools:

Calling Tools Directly

Call MCP tools without agents:

Working with Resources

Access MCP server resources:

MCP with Multi-Agent Teams

Use MCP servers in multi-agent workflows:

Error Handling

Handle MCP connection and execution errors:

Timeout Configuration

Configure timeouts for MCP operations:

Best Practices

MCP servers run as separate processes. Ensure they’re properly closed to avoid resource leaks.

Available MCP Servers

Popular MCP servers you can use:

Official Servers

  • @playwright/mcp - Web browsing and automation
  • @modelcontextprotocol/server-fetch - HTTP requests
  • @modelcontextprotocol/server-filesystem - File system access
  • @modelcontextprotocol/server-sqlite - SQLite database access
  • github-mcp-server - GitHub API integration

Installation Examples

Debugging MCP Connections

Debug MCP server issues:

Advanced: Custom MCP Host

Implement custom MCP capabilities: