Skip to main content
Session manager for MCP connections. This module provides a session manager for MCP connections, which handles authentication, initialization, and tool discovery.

MCPSession

method init

Initialize a new MCP session.Parameters
mcp_use.client.connectors.base.BaseConnector
required
The connector to use for communicating with the MCP implementation.
bool
default:"True"
Whether to automatically connect to the MCP implementation.
Signature

method call_tool

Call an MCP tool.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"
Optional timeout for the tool call.
Returns
mcp.types.CallToolResult
The result of the tool call.
Signature

method connect

Connect to the MCP implementation.Signature

method disconnect

Disconnect from the MCP implementation.Signature

method get_prompt

Get a prompt by name.Parameters
str
required
The name of the prompt to get.
dict[str, typing.Any] | None
default:"None"
Optional arguments for the prompt.
Returns
mcp.types.GetPromptResult
The prompt result with messages.
Signature

method initialize

Initialize the MCP session and discover available tools.Returns
dict[str, Any]
The session information returned by the MCP implementation.
Signature

property is_connected

Check if the connector is connected.Returns
bool
Signature

method list_prompts

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

method list_resources

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

method list_tools

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

method read_resource

Read a resource by URI.Parameters
pydantic.networks.AnyUrl
required
The URI of the resource to read.
Returns
mcp.types.ReadResourceResult
The resource content.
Signature