Skip to main content
View the source code for this module on GitHub: https://github.com/mcp-use/mcp-use/blob/main/mcp_use/connectors/base.py
Base connector for MCP implementations. This module provides the base connector interface that all MCP connectors must implement.

BaseConnector

from mcp_use.connectors.base import BaseConnector

method init

Initialize base connector with common attributes.Parameters
sampling_callback
mcp.client.session.SamplingFnT | None
default:"None"
Callback function
elicitation_callback
mcp.client.session.ElicitationFnT | None
default:"None"
Callback function
message_handler
mcp.client.session.MessageHandlerFnT | None
default:"None"
Parameter value
logging_callback
mcp.client.session.LoggingFnT | None
default:"None"
Callback function
middleware
list[mcp_use.middleware.middleware.Middleware] | None
default:"None"
Middleware instance
Signature
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.middleware.middleware.Middleware] | None = None):

method call_tool

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

property client_info

Get the client info for the connector.Returns
returns
mcp.types.Implementation
Signature
def client_info():

method connect

Establish a connection to the MCP implementation.Signature
def connect():

method disconnect

Close the connection to the MCP implementation.Signature
def disconnect():

method get_prompt

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

method initialize

Initialize the MCP session and return session information.Returns
returns
dict[str, Any]
Signature
def initialize():

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
returns
bool
Signature
def is_connected():

method list_prompts

List all available prompts from the MCP implementation.Returns
returns
list[mcp.types.Prompt]
Signature
def list_prompts():

method list_resources

List all available resources from the MCP implementation.Returns
returns
list[mcp.types.Resource]
Signature
def list_resources():

method list_tools

List all available tools from the MCP implementation.Returns
returns
list[mcp.types.Tool]
Signature
def list_tools():

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
returns
list[mcp.types.Prompt]
Signature
def prompts():

property public_identifier

Get the identifier for the connector.Returns
returns
str
Signature
def public_identifier():

method read_resource

Read a resource by URI.Parameters
uri
pydantic.networks.AnyUrl
required
Parameter value
Returns
returns
mcp.types.ReadResourceResult
Signature
def read_resource(uri: pydantic.networks.AnyUrl):

method request

Send a raw request to the MCP implementation.Parameters
method
str
required
String value
params
dict[str, typing.Any] | None
default:"None"
Dictionary of key-value pairs
Returns
returns
Any
Signature
def request(method: str, params: dict[str, typing.Any] | None = None):

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
returns
list[mcp.types.Resource]
Signature
def resources():

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
returns
list[mcp.types.Tool]
Signature
def tools():
I