From 29ef0f419f7a87ce6f0d48b6e434458ec327c20f Mon Sep 17 00:00:00 2001 From: Paul Kompfner Date: Mon, 3 Nov 2025 22:19:07 -0500 Subject: [PATCH] Add typing formalizing `MCPClient` support for registering tools on an `LLMSwitcher` in addition to an `LLMService`. --- CHANGELOG.md | 20 ++++++++++++++------ src/pipecat/services/mcp_service.py | 7 +++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f5aba6f2..411e381af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,20 @@ reason")`. `LLMSwitcher.register_function()` in that it's a shorthand for registering functions on all LLMs in the switcher, but for direct functions. +- Added support for passing in an `LLMSwicher` to `MCPClient.register_tools()` + (as well as the new `MCPClient.register_tools_schema()`). + +- Added `LLMSwitcher.register_direct_function()`. It works much like + `LLMSwitcher.register_function()` in that it's a shorthand for registering + a function on all LLMs in the switcher, except it takes a direct function (a + `FunctionSchema`-less function). + +- Added the two-step `MCPClient.get_tools_schema()` and + `MCPClient.register_tools_schema()` as two-step alternative to + `MCPClient.register_tools()`, to allow users to use `MCPClient` alongside + the pattern of passing in tools to the LLM service constructor (a pattern + supported by speech-to-speech services such as `GeminiLiveLLMService`). + ### Changed - Bumped the `fastapi` dependency's upperbound to `<0.122.0`. @@ -57,12 +71,6 @@ reason")`. supported languages before Pipecat's service classes are updated, while still providing guidance on verified languages. -- Added the two-step `MCPClient.get_tools_schema()` and - `MCPClient.register_tools_schema()` as two-step alternative to - `MCPClient.register_tools()`, to allow users to use `MCPClient` alongside - the pattern of passing in tools to the LLM service constructor (a pattern - supported by speech-to-speech services such as `GeminiLiveLLMService`). - ### Fixed - Fixed an issue where the `SmallWebRTCRequest` dataclass in runner would scrub diff --git a/src/pipecat/services/mcp_service.py b/src/pipecat/services/mcp_service.py index e38ea17b1..ccfb47adb 100644 --- a/src/pipecat/services/mcp_service.py +++ b/src/pipecat/services/mcp_service.py @@ -13,6 +13,7 @@ from loguru import logger from pipecat.adapters.schemas.function_schema import FunctionSchema from pipecat.adapters.schemas.tools_schema import ToolsSchema +from pipecat.pipeline.llm_switcher import LLMSwitcher from pipecat.services.llm_service import FunctionCallParams, LLMService from pipecat.utils.base_object import BaseObject @@ -74,7 +75,7 @@ class MCPClient(BaseObject): f"{self} invalid argument type: `server_params` must be either StdioServerParameters, SseServerParameters, or StreamableHttpParameters." ) - async def register_tools(self, llm) -> ToolsSchema: + async def register_tools(self, llm: LLMService | LLMSwitcher) -> ToolsSchema: """Register all available MCP tools with an LLM service. Connects to the MCP server, discovers available tools, converts their @@ -106,7 +107,9 @@ class MCPClient(BaseObject): tools_schema = await self._list_tools() return tools_schema - async def register_tools_schema(self, tools_schema: ToolsSchema, llm: LLMService) -> None: + async def register_tools_schema( + self, tools_schema: ToolsSchema, llm: LLMService | LLMSwitcher + ) -> None: """Register the MCP tools (previously obtained from get_tools_schema()) with the LLM service. Args: