MCPConnectionError
MCPToolError
ensure_strict_json_schema
strict
standard that the OpenAI API expects.
_ensure_strict_json_schema
resolve_ref
is_dict
is_list
has_more_than_n_keys
MCPToolkit
MCPClient
instances and
aggregates their tools into a unified interface compatible with the CAMEL
framework.
Connection Lifecycle:
There are three ways to manage the connection lifecycle:
- Using the async context manager (recommended):
Toolkit is connected here
tools = toolkit.get_tools()Toolkit is automatically disconnected here
- Using the factory method:
Toolkit is connected here
tools = toolkit.get_tools()Don’t forget to disconnect when done!
await toolkit.disconnect()- Using explicit connect/disconnect:
Toolkit is connected here
tools = toolkit.get_tools()Don’t forget to disconnect when done!
await toolkit.disconnect() Parameters:- clients (Optional[List[MCPClient]], optional): List of :obj:
MCPClient
instances to manage. (default: :obj:None
) - config_path (Optional[str], optional): Path to a JSON configuration file defining MCP servers. The file should contain server configurations in the standard MCP format. (default: :obj:
None
) - config_dict (Optional[Dict[str, Any]], optional): Dictionary containing MCP server configurations in the same format as the config file. This allows for programmatic configuration without file I/O. (default: :obj:
None
) - timeout (Optional[float], optional): Timeout for connection attempts in seconds. This timeout applies to individual client connections. (default: :obj:
None
) - clients (List[MCPClient]): List of :obj:
MCPClient
instances being managed by this toolkit.
init
is_connected
connect_sync
disconnect_sync
enter
exit
create_sync
_load_clients_from_config
_load_clients_from_dict
_create_client_from_config
_ensure_strict_tool_schema
- Ensure parameters exist with at least an empty properties object (OpenAI requirement).
- Try converting parameters to strict using ensure_strict_json_schema.
- If conversion fails, mark function.strict = False and keep best-effort parameters.