View the source code for this module on GitHub: https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/client/connectors/base.py
BaseConnector
from mcp_use.client.connectors.base import BaseConnector
method init
Initialize base connector with common attributes.ParametersSignaturemcp.client.session.SamplingFnT | Nonedefault:"None"Optional callback to handle sampling requests from servers.mcp.client.session.ElicitationFnT | Nonedefault:"None"Optional callback to handle elicitation requests from servers.mcp.client.session.MessageHandlerFnT | Nonedefault:"None"Optional callback to handle messages from servers.mcp.client.session.LoggingFnT | Nonedefault:"None"Optional callback to handle log messages from servers.list[mcp_use.client.middleware.middleware.Middleware] | Nonedefault:"None"Optional list of middleware to apply to requests.list[mcp.types.Root] | Nonedefault:"None"Optional initial list of roots to advertise to the server.mcp.client.session.ListRootsFnT | Nonedefault:"None"Optional custom callback to handle roots/list requests.
def __init__(sampling_callback: mcp.client.session.SamplingFnT | None = None, elicitation_callback: mcp.client.session.ElicitationFnT | None = None, message_handler: mcp.client.session.MessageHandlerFnT | None = None, logging_callback: mcp.client.session.LoggingFnT | None = None, middleware: list[mcp_use.client.middleware.middleware.Middleware] | None = None, roots: list[mcp.types.Root] | None = None, list_roots_callback: mcp.client.session.ListRootsFnT | None = None):
method call_tool
Call an MCP tool with automatic reconnection handling.ParametersReturnsstrrequiredThe name of the tool to call.dict[str, Any]requiredThe arguments to pass to the tool.datetime.timedelta | Nonedefault:"None"timeout seconds when calling tool
Signaturemcp.types.CallToolResultThe result of the tool call.
def call_tool(
name: str,
arguments: dict[str,
Any],
read_timeout_seconds: datetime.timedelta | None = None
):
property prompts
Get the list of available prompts... deprecated::
This property is deprecated because it may return stale data when the server
sends list change notifications. Use `await list_prompts()’ instead to ensure
you always get the latest data.ReturnsSignaturelist[mcp.types.Prompt]
def prompts():
property resources
Get the list of available resources... deprecated::
This property is deprecated because it may return stale data when the server
sends list change notifications. Use await list_resources() instead to ensure
you always get the latest data.ReturnsSignaturelist[mcp.types.Resource]
def resources():
method set_roots
Set the roots and notify the server if connected.Roots represent directories or files that the client has access to.Example:await connector.set_roots([
Root(uri="file:///home/user/project", name="My Project"),
Root(uri="file:///home/user/data"),
])
Signaturelist[mcp.types.Root]requiredArray of Root objects withuri(must start with “file://”) and optionalname.
def set_roots(roots: list[mcp.types.Root]):