Client Configuration
This guide covers MCPClient configuration options for connecting to MCP servers. For agent configuration, see the Agent Configuration guide.
MCP Server Configuration
mcp_use supports any MCP server through a flexible configuration system. (For a list of awesome servers you can visit https://github.com/punkpeye/awesome-mcp-servers or https://github.com/appcypher/awesome-mcp-servers which have an amazing collection of them) The configuration is defined in a JSON file with the following structure:mcpServers
object has a server_name
and then specific options depending on how mcp-use
should connect to and/or manage the server.
server_name
: (Required) A unique string identifier for this MCP server configuration. This name is used to select the server, for example, inagent.run(..., server_name="your_server_name")
.
mcp-use
will start and manage as local child processes, communicating via their standard input/output streams.
command
: (Required) The executable command to start the server (e.g.,"npx"
,"python"
).args
: (Optional) An array of string arguments to pass to thecommand
(e.g.,["-y", "@playwright/mcp@latest"]
).env
: (Optional) An object defining environment variables to set for the server’s process (e.g.,{"DISPLAY": ":1"}
).
mcp-use
acts as an HTTP client to communicate with them.
url
: (Required) The full URL where the MCP server is listening (e.g.,"http://localhost:7777/mcp"
,"https://api.example.com/mcp"
).headers
: (Optional) An object containing custom HTTP headers to be sent with every request to this server (e.g., for authentication:{"Authorization": "Bearer your_api_token"}
).
Example Configuration
Here’s a basic example of how to configure an MCP server:Multiple Server Configuration
You can configure multiple MCP servers in a single configuration file, allowing you to use different servers for different tasks or combine their capabilities (e.g.):Client Creation Methods
There are several ways to create an MCPClient:From Dictionary
Create configuration programmatically:From Configuration File
Load configuration from a JSON file:With Sandbox Options
Enable sandboxed execution:Best Practices
- API Keys: Always use environment variables for sensitive information
- Configuration Files: Keep configuration files in version control (without sensitive data)
- Server Naming: Use descriptive names for your MCP servers
- Environment Variables: Set appropriate environment variables for each server
- Testing: Test server connections independently before using with agents
- Monitoring: Enable logging to monitor server connection health
Error Handling
Common client configuration errors and solutions:- Server Not Found: Check if the server command is installed and accessible
- Connection Timeout: Verify server is running and network connectivity
- Permission Denied: Ensure proper file permissions and environment setup
- Invalid Configuration: Validate JSON syntax and required fields