Configure MCPClient for connecting to MCP servers
{ "mcpServers": { "server_name": { "command":"command_to_run", "args": ["arg1","arg2"], "env": { "ENV_VAR":"value" } } }}mcpServers object has aserver_name and then specific options depending on howmcp-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"}).{ "mcpServers": { "my_server": { "command":"npx", "args": ["@my-mcp/server"], "env": { "PORT":"3000" } } }}{ "mcpServers": { "airbnb": { "command":"npx", "args": ["-y","@openbnb/mcp-server-airbnb","--ignore-robots-txt"] }, "playwright": { "command":"npx", "args": ["@playwright/mcp@latest"], "env": {"DISPLAY":":1" } }, "filesystem": { "command":"npx", "args": [ "-y", "@modelcontextprotocol/server-filesystem", "/home/pietro/projects/mcp-use/" ] } }}from mcp_useimport MCPClientconfig= { "mcpServers": { "playwright": { "command":"npx", "args": ["@playwright/mcp@latest"], "env": {"DISPLAY":":1"} } }}client= MCPClient(config)from mcp_useimport MCPClientclient= MCPClient.from_config_file("config.json")from mcp_useimport MCPClientfrom mcp_use.types.sandboximport SandboxOptionssandbox_options: SandboxOptions= { "api_key":"your_e2b_api_key", "sandbox_template_id":"code-interpreter-v1"}client= MCPClient.from_dict( config, sandbox=True, sandbox_options=sandbox_options)Was this page helpful?