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. The connection opens automatically on the first call to tools() and closes at pipeline teardown:
You can also scope the client with async with MCPClient(...) or call start() and close() explicitly.

Installation

To use MCPClient, install the required dependencies:
MCPClient works with MCP SDK versions 1.24.0+ and 2.x. 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.
Dict[str, Dict[str, Any]] | None
default:"None"
Optional dictionary mapping tool names to fixed arguments that are merged into every call of that tool. Use this for arguments the LLM shouldn’t choose — a fixed search mode, an account ID, or a caller-supplied filter. Fixed arguments override any model-supplied values and are hidden from the schema the LLM sees.

Input Parameters

See more information regarding server params here.

Usage Examples

MCP Stdio Transport

MCP SSE Transport

MCP Streamable HTTP Transport

Tools for LLMs with Construction-Time Tool Parameters

Some LLM services (e.g. Gemini Live) require tools to be passed at construction time. The tools() method returns a ToolsSchema with handlers already attached, so you can pass it directly to the LLM constructor.

Multiple MCP Servers

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

Methods

async method
Gets the available MCP tools with handlers attached, ready for LLM auto-registration. Starts the server connection if needed. The connection closes automatically at pipeline teardown. This is the recommended way to use MCP tools — pass the result to LLMContext(tools=...) and the handlers register automatically.
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. Idempotent, and called automatically by tools(). Can also be used via async context manager instead of calling this directly.
async method
Closes the persistent MCP connection. Called automatically at pipeline teardown once the client’s tools have been registered with an LLM service. Call it directly only to release the connection earlier (e.g. on client disconnect). Safe to call multiple times, without having called start(), and from a different task than the one that called start().
async method
Deprecated since 1.8.0. Use tools() instead. Discovers available tools from the active session, converts their schemas to Pipecat format, and registers them with the LLM service. Will be removed in 2.0.0.
async method
Deprecated since 1.8.0. Use tools() instead. Discovers available tools from the active session and converts their schemas to Pipecat format. Will be removed in 2.0.0.
async method
Deprecated since 1.8.0. Use tools() instead. Registers a previously obtained ToolsSchema with an LLM service. Will be removed in 2.0.0.

Additional documentation

See MCP’s docs for MCP related updates.