Quickstart
Get started with mcp_use in minutes
Quickstart Guide
This guide will help you get started with mcp_use quickly. We’ll cover installation, basic configuration, and running your first agent.
Installation
You can install mcp_use using pip:
Or install from source:
Installing LangChain Providers
mcp_use works with various LLM providers through LangChain. You’ll need to install the appropriate LangChain provider package for your chosen LLM. For example:
Important: Only models with tool calling capabilities can be used with mcp_use. Make sure your chosen model supports function calling or tool use.
Environment Setup
Set up your environment variables in a .env
file:
Your First Agent
Here’s a simple example to get you started:
Configuration Options
You can also add the servers configuration from a config file:
Example configuration file (browser_mcp.json
):
Working with Adapters Directly
If you want more control over how tools are created, you can work with the adapters directly. The BaseAdapter
class provides a unified interface for converting MCP tools to various framework formats, with LangChainAdapter
being the most commonly used implementation.
The adapter pattern makes it easy to:
- Create tools directly from an MCPClient
- Filter or customize which tools are available
- Integrate with different agent frameworks
Using Multiple Servers
The MCPClient
can be configured with multiple MCP servers, allowing your agent to access tools from different sources. This capability enables complex workflows spanning various domains (e.g., web browsing and API interaction).
Configuration:
Define multiple servers in your configuration file (multi_server_config.json
):
Usage:
When an MCPClient
with multiple servers is passed to an MCPAgent
, the agent gains access to tools from all configured servers. By default, you might need to guide the agent or explicitly specify which server to use for a given task using the server_name
parameter in the agent.run()
method.
Enabling Dynamic Server Selection (Server Manager)
To improve efficiency and potentially reduce agent confusion when many tools are available, you can enable the Server Manager. Set use_server_manager=True
when creating the MCPAgent
.
When enabled, the agent will automatically select the appropriate server based on the tool chosen by the LLM for each step. This avoids connecting to unnecessary servers.
Restricting Tool Access
You can control which tools are available to the agent:
Available MCP Servers
mcp_use supports any MCP server, allowing you to connect to a wide range of server implementations. For a comprehensive list of available servers, check out the awesome-mcp-servers repository.
Each server requires its own configuration. Check the Configuration Guide for details.
HTTP Connection
mcp_use now supports HTTP connections, allowing you to connect to MCP servers running on specific HTTP ports. This feature is particularly useful for integrating with web-based MCP servers.
Here’s a simple example to get you started with HTTP connections:
This example demonstrates how to connect to an MCP server running on a specific HTTP port. Make sure to start your MCP server before running this example.
Streaming Agent Output
You can stream the agent’s output as it is generated using the astream
method:
Each chunk contains incremental results, tool actions, and intermediate steps.
Next Steps
- Learn about Configuration Options
- Explore Example Use Cases
- Check out Advanced Features