TransportType
ServerConfig
validate_config
transport_type
MCPClient
- config (Union[ServerConfig, Dict[str, Any]]): Server configuration as either a :obj:
ServerConfig
object or a dictionary that will be converted to a :obj:ServerConfig
. The configuration determines the transport type and connection parameters. - client_info (Optional[types.Implementation], optional): Client implementation information to send to the server during initialization. (default: :obj:
None
) - timeout (Optional[float], optional): Timeout for waiting for messages from the server in seconds. (default: :obj:
10.0
) - config (ServerConfig): The server configuration object.
- client_info (Optional[types.Implementation]): Client implementation information.
- read_timeout_seconds (timedelta): Timeout for reading from the server.
init
transport_type
_simplify_connection_error
session
is_connected
list_mcp_tools_sync
generate_function_from_mcp_tool
- mcp_tool (types.Tool): The MCP tool definition received from the MCP server.
_build_tool_schema
get_tools
FunctionTool
objects
representing the available tools from the MCP server. Returns
an empty list if the client is not connected.
Note:
This method requires an active connection to the MCP server.
If the client is not connected, an empty list will be returned.
get_text_tools
call_tool_sync
- tool_name (str): The name of the tool to call.
- arguments (Dict[str, Any]): A dictionary of arguments to pass to the tool.
create_mcp_client
MCPClient
instance from various
configuration formats. This is the recommended way to create MCP clients
as it handles configuration validation and type conversion automatically.
Parameters:
- config (Union[Dict[str, Any], ServerConfig]): Server configuration as either a dictionary or a :obj:
ServerConfig
object. If a dictionary is provided, it will be automatically converted to - a: obj:
ServerConfig
. **kwargs: Additional keyword arguments passed to the :obj:MCPClient
constructor, such as :obj:client_info
, :obj:timeout
.
MCPClient
instance ready for use as
an async context manager.
create_mcp_client_from_config_file
- config_path (Union[str, Path]): Path to configuration file (JSON).
- server_name (str): Name of the server in the config. **kwargs: Additional arguments passed to MCPClient constructor.
\{ "mcpServers": \{ "filesystem": \{ "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-filesystem", "/path" ] \}, "remote-server": \{ "url": "https://api.example.com/mcp", "headers": \{"Authorization": "Bearer token"\} \} \} \}
Usage:
.. code-block:: python
async with create_mcp_client_from_config_file(
“config.json”, “filesystem”
) as client:
tools = client.get_tools()