Skip to content

Client

MCP Client module.

MCPClient(servers)

Bases: ABC

The MCP (Model Context Protocol) Client handler.

Responsible for creating MCP client sessions, managing its lifecycle, and connecting generating the tools, resources, and all server features MCP has to offer.

Attributes:

Name Type Description
servers dict[str, MCPConfiguration]

A dictionary of MCP server configurations.

Creates a new MCP client.

Parameters:

Name Type Description Default
servers dict[str, MCPConfiguration]

A dictionary of MCP server configurations.

required

Example: how to get the tools from the MCP servers.

client = MCPClient(servers)
tools = await client.get_tools()

get_resource(server, resource_uri) async

Returns a resource's entire content.

This function retrieves the resource from the MCP servers configuration dictionary. Be careful with this function, as it will return the entire content of the resource,

NOTE: a new session is created for each resource call.

Parameters:

Name Type Description Default
server str

The name of the MCP server to connect to.

required
resource_uri str

The URI of the resource to retrieve.

required

Returns:

Name Type Description
Any Any

The resource's entire content. The resource can be adapted to a specific framework's resource using resource_adapter.

get_resources(server=None) async

Returns a list of available resources.

This function retrieves the names of the available resources from the MCP servers configuration dictionary. Note that this function only returns the metadata of the resources, not the actual content. For the content, use the get_resource function.

NOTE: a new session is created for each resource call.

Parameters:

Name Type Description Default
server str | None

The name of the MCP server to connect to.

None

Returns:

Type Description
list[MCPResource]

list[MCPResource]: A list of available resources. Only the metadata of the resources is returned.

get_servers()

Returns a list of available MCP servers.

This function retrieves the names of the available MCP servers from the MCP servers configuration dictionary.

Returns:

Type Description
list[str]

list[str]: A list of available MCP servers.

Example: getting the available MCP servers:

servers = {
    "github": MCPConfiguration(...),
    "slack": MCPConfiguration(...),
}
client = MCPClient(servers)
servers = await client.get_servers()
print(servers)
# Output: ["github", "slack"]

get_tools(server=None) async

Returns a list of available tools.

This function retrieves the names of the available tools from the MCP servers configuration dictionary.

NOTE: a new session is created for each tool call.

Parameters:

Name Type Description Default
server str | None

The name of the MCP server to connect to.

None

Returns:

Type Description
list[MCPTool | Any]

list[MCPTool | Any]: A list of available tools. The tool can be adapted to a specific framework's tool using tool_adapter.