Skip to main content

Overview

MCP is an open standard for enabling AI agents to interact with external data and tools. MCPClient provides a way to access and call tools via MCP. For example, instead of writing bespoke function call implementations for an external API, you may use an MCP server that provides a bridge to the API. Be aware there may be security implications. See MCP documenation for more details. The client maintains a persistent connection to the MCP server and must be used as an async context manager or explicitly started and closed:

Installation

To use MCPClient, install the required dependencies:
You may also need to set environment variables as required by the specific MCP server to which you are connecting.

Configuration

Constructor Parameters

You can connect to your MCP server via Stdio, SSE, or Streamable HTTP transport. See here for more documentation on MCP transports.
StdioServerParameters | SseServerParameters | StreamableHttpParameters
required
Connection parameters for the MCP server. Must be one of:
  • StdioServerParameters (from mcp): Connects to a local MCP server process via stdio.
  • SseServerParameters (from mcp.client.session_group): Connects to a remote MCP server via Server-Sent Events.
  • StreamableHttpParameters (from mcp.client.session_group): Connects to a remote MCP server via Streamable HTTP.
List[str] | None
default:"None"
Optional list of tool names to register. If None, all tools from the MCP server are registered. Use this to limit which tools are exposed to the LLM.
Dict[str, Callable] | None
default:"None"
Optional dictionary mapping tool names to filter functions that post-process tool outputs. Each filter function receives the raw tool output and returns the processed output.

Input Parameters

See more information regarding server params here.

Usage Examples

MCP Stdio Transport

MCP SSE Transport

MCP Streamable HTTP Transport

Two-Step Registration

Some LLM services (e.g. Gemini Live) require tools to be passed at construction time. Use get_tools_schema() to obtain the schema first, then register_tools_schema() to register handlers after the LLM is created.

Multiple MCP Servers

You can combine tools from multiple MCP servers by merging their ToolsSchema objects.

Methods

async method
Opens a persistent connection to the MCP server and initializes the session. The session is reused for all subsequent tool calls until close() is called. Can also be used via async context manager instead of calling this directly.
async method
Closes the persistent MCP connection. Safe to call multiple times or without having called start().
async method
Discovers available tools from the active session, converts their schemas to Pipecat format, and registers them with the LLM service. This is equivalent to calling get_tools_schema() followed by register_tools_schema(). Requires the client to be started via start() or async context manager.
async method
Discovers available tools from the active session and converts their schemas to Pipecat format — without registering them with an LLM. Use this when you need the tools schema before the LLM is created. Requires the client to be started via start() or async context manager.
async method
Registers a previously obtained ToolsSchema with an LLM service. Use this after get_tools_schema() once the LLM is available.

Additional documentation

See MCP’s docs for MCP related updates.