Skip to main content

What are MCP Integrations?

MCP (Model Context Protocol) integrations allow you to connect your Stagehand agents to external tools, APIs, and services. This enables agents to perform actions beyond browser automation, such as web search, database operations, and API calls.
MCP integrations make your agents more powerful by combining browser automation with external capabilities. The agent can intelligently decide when to use browser actions versus external tools.

Connection Options

There are two options for connecting to MCP servers:
  1. Pass a URL directly - The simplest approach for quick setup
  2. Create a connection first - Gives you more control over the connection
MCP client support is currently only available in TypeScript.

Passing a URL

The simplest way to add MCP integrations is by providing server URLs directly in the agent configuration:

Creating a Connection First

Alternatively, you can establish MCP connections first and then pass the client objects:

Authenticated MCP Servers

Some MCP servers require authentication via HTTP request headers. You can pass request headers through requestOptions:

Multiple Integrations

You can combine multiple MCP integrations in a single agent:

Best Practices

Choose the Right Connection Approach

When to use:
  • Simple setup requirements
  • Standard API configurations
  • Getting started quickly
Benefits:
  • Minimal code required
  • Automatic connection handling
  • Easy to configure

Environment Variables

Always use environment variables for API keys and sensitive information:

Instructions Best Practices

Provide clear instructions about available tools:

Error Handling

Implement proper error handling for MCP connections:

Troubleshooting

Problem: MCP server connections timing outSolutions:
  • Verify server URLs are correct and accessible
  • Check network connectivity
  • Ensure API keys are valid and have proper permissions
  • Try connecting to servers individually to isolate issues
Problem: Agent not using available MCP toolsSolutions:
  • Make instructions more specific about when to use tools
  • Ensure API keys are properly configured
  • Check that the MCP server supports the expected tools
  • Verify tool descriptions are clear and actionable
Problem: API key or authentication failuresSolutions:
  • Verify all required environment variables are set
  • Check API key validity and permissions
  • Ensure URLs include necessary authentication parameters
  • Test MCP connections independently before using in agents

Examples

Web Search + Browser Automation

Data Extraction + Storage

Multi-tool Workflow

Further Reading

Agent Basics

Learn the fundamentals of Stagehand agents

MCP Server Setup

Set up your own MCP server

Custom Tools

Create custom MCP tools