Configuring and Inspecting the MCP Client

~12 min read

Every mcp-use agent embeds an MCP client responsible for connections, handshakes, and streaming — configurable from a file or a Python dictionary, and directly inspectable for debugging.

The previous subtopics focused on the agent's behavior; this one zooms into the specific component doing the protocol-level communication underneath it: the MCP client itself.

Within mcp-use, every agent embeds an MCP client. The client is the component responsible for all communication between the agent and any MCP server — it manages the transport layer and ensures that capabilities (tools, resources, prompts, etc.) remain synchronized throughout an interaction. At a high level, the MCP client handles: connecting to MCP servers, performing the initial capability handshake, streaming tool calls and tool responses, retrieving resources, receiving notifications, and routing elicitation requests back to the user or host application. In short, the client keeps the agent and server aligned, ensuring both sides speak the same protocol.

mcp-use provides two simple ways to create an MCP client, depending on how you prefer to manage server settings. The first is loading configuration from a file — ideal when working with multiple environments or when you prefer keeping server settings version-controlled (a config file that can live alongside your codebase, tracked in git). The second is creating the client from a Python dictionary directly — this mirrors the same structure as configuration files but allows programmatic customization inside Python, useful when server settings need to be computed or assembled dynamically at runtime rather than fixed ahead of time.

Although the agent manages the client internally, mcp-use still allows you to inspect the client directly when needed — for example, to debug capability discovery or understand which tools are actually available at a given moment. This inspection ability matters specifically because the Server Manager (previous subtopic) makes the active toolset dynamic — being able to directly query the client for what's currently connected and discovered is often the fastest way to debug why an agent did (or didn't) find a tool you expected it to have access to. Combined with connecting to one or more servers simultaneously (the multi-server setups the Server Manager is built to handle), this client-level configuration and inspection layer is what gives you direct visibility and control underneath the agent's higher-level behavior.

💻 Code example

from mcp_use import MCPClient

# Option 1: load configuration from a version-controlled file
client_from_file = MCPClient.from_config_file("mcp_servers_config.json")

# Option 2: create from a Python dictionary -- useful when server
# settings need to be assembled dynamically at runtime
server_config = {
    "mcpServers": {
        "weather": {"command": "python", "args": ["weather_server.py"]},
        "travel": {"url": "https://travel-mcp.example.com/sse"},
    }
}
client_from_dict = MCPClient.from_dict(server_config)

async def inspect_client(client: MCPClient) -> None:
    """Directly inspecting the client -- useful for debugging
    capability discovery, especially alongside a dynamic Server Manager."""
    await client.connect_all()
    for server_name, session in client.sessions.items():
        tools = await session.list_tools()
        print(f"{server_name}: {[t.name for t in tools]}")

import asyncio
asyncio.run(inspect_client(client_from_dict))

💬 Deep Dive with AI

Key points

  • The MCP client handles connecting to servers, the capability handshake, streaming tool calls/responses, resources, notifications, and elicitation routing
  • Two ways to configure a client: loading from a version-controlled config file, or creating from a Python dictionary for dynamic setups
  • Although the agent manages the client internally, mcp-use lets you inspect it directly for debugging capability discovery
  • Inspection is especially useful alongside the Server Manager's dynamic toolset, to see exactly what's currently connected and discovered
  • This client layer is what actually keeps the agent and server aligned, speaking the same protocol underneath the agent's higher-level behavior