Skip to main content
Base connector for MCP implementations. This module provides the base connector interface that all MCP connectors must implement.

BaseConnector

method init

Initialize base connector with common attributes.Parameters
mcp.client.session.SamplingFnT | None
default:"None"
Optional callback to handle sampling requests from servers.
mcp.client.session.ElicitationFnT | None
default:"None"
Optional callback to handle elicitation requests from servers.
mcp.client.session.MessageHandlerFnT | None
default:"None"
Optional callback to handle messages from servers.
mcp.client.session.LoggingFnT | None
default:"None"
Optional callback to handle log messages from servers.
list[mcp_use.client.middleware.middleware.Middleware] | None
default:"None"
Optional list of middleware to apply to requests.
list[mcp.types.Root] | None
default:"None"
Optional initial list of roots to advertise to the server.
mcp.client.session.ListRootsFnT | None
default:"None"
Optional custom callback to handle roots/list requests.
Signature

method call_tool

Call an MCP tool with automatic reconnection handling.Parameters
str
required
The name of the tool to call.
dict[str, Any]
required
The arguments to pass to the tool.
datetime.timedelta | None
default:"None"
timeout seconds when calling tool
Returns
mcp.types.CallToolResult
The result of the tool call.
Signature

property client_info

Get the client info for the connector.Returns
mcp.types.Implementation
Signature

method connect

Establish a connection to the MCP implementation.Signature

method disconnect

Close the connection to the MCP implementation.Signature

method get_prompt

Get a prompt by name.Parameters
str
required
Name identifier
dict[str, typing.Any] | None
default:"None"
Dictionary of key-value pairs
Returns
mcp.types.GetPromptResult
Signature

method get_roots

Get the current list of roots.Returns
list[mcp.types.Root]
A copy of the current roots list.
Signature

method initialize

Initialize the MCP session and return session information.Returns
mcp.types.InitializeResult | None
Signature

property is_connected

Check if the connector is actually connected and the connection is alive.This property checks not only the connected flag but also verifies that the underlying connection manager and streams are still active.Returns
bool
Signature

method list_prompts

List all available prompts from the MCP implementation.Returns
list[mcp.types.Prompt]
Signature

method list_resources

List all available resources from the MCP implementation.Returns
list[mcp.types.Resource]
Signature

property list_roots_callback

Get the list_roots_callback to pass to ClientSession.This always returns a callback to ensure the roots capability is advertised.Returns
mcp.client.session.ListRootsFnT
Signature

method list_tools

List all available tools from the MCP implementation.Returns
list[mcp.types.Tool]
Signature

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.Returns
list[mcp.types.Prompt]
Signature

property public_identifier

Get the identifier for the connector.Returns
str
Signature

method read_resource

Read a resource by URI.Parameters
pydantic.networks.AnyUrl
required
Parameter value
Returns
mcp.types.ReadResourceResult
Signature

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.Returns
list[mcp.types.Resource]
Signature

method set_roots

Set the roots and notify the server if connected.Roots represent directories or files that the client has access to.Example:
Parameters
list[mcp.types.Root]
required
Array of Root objects with uri (must start with “file://”) and optional name.
Signature

property tools

Get the list of available tools... deprecated:: This property is deprecated because it may return stale data when the server sends list change notifications. Use await list_tools() instead to ensure you always get the latest data.Returns
list[mcp.types.Tool]
Signature