From 9d5f5844b87c6a428429dd1637dc4297b85980d2 Mon Sep 17 00:00:00 2001 From: Yousif Astarabadi <6870090+yousifa@users.noreply.github.com> Date: Thu, 26 Jun 2025 13:14:45 -0700 Subject: [PATCH] clean mcp schema for gemini models, update http mcp example to use gemini --- examples/foundational/39c-mcp-run-http.py | 5 ++++- src/pipecat/services/mcp_service.py | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/foundational/39c-mcp-run-http.py b/examples/foundational/39c-mcp-run-http.py index 1c51894b1..df17869bb 100644 --- a/examples/foundational/39c-mcp-run-http.py +++ b/examples/foundational/39c-mcp-run-http.py @@ -16,6 +16,7 @@ from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.runner import PipelineRunner from pipecat.pipeline.task import PipelineParams, PipelineTask from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext +from pipecat.services.google.llm import GoogleLLMService from pipecat.services.cartesia.tts import CartesiaTTSService from pipecat.services.deepgram.stt import DeepgramSTTService from pipecat.services.mcp_service import MCPClient @@ -58,7 +59,9 @@ async def run_example(transport: BaseTransport, _: argparse.Namespace, handle_si voice_id="71a7ad14-091c-4e8e-a314-022ece01c121", # British Reading Lady ) - llm = OpenAILLMService(api_key=os.getenv("OPENAI_API_KEY"), model="gpt-4o-mini") + llm = GoogleLLMService( + api_key=os.getenv("GOOGLE_API_KEY"), model="gemini-2.0-flash" + ) try: # Github MCP docs: https://github.com/github/github-mcp-server diff --git a/src/pipecat/services/mcp_service.py b/src/pipecat/services/mcp_service.py index 48202e8f9..13d58ed0c 100644 --- a/src/pipecat/services/mcp_service.py +++ b/src/pipecat/services/mcp_service.py @@ -82,13 +82,14 @@ class MCPClient(BaseObject): return tools_schema def _convert_mcp_schema_to_pipecat( - self, tool_name: str, tool_schema: Dict[str, Any] + self, tool_name: str, tool_schema: Dict[str, Any], llm=None ) -> FunctionSchema: """Convert an mcp tool schema to Pipecat's FunctionSchema format. Args: tool_name: The name of the tool tool_schema: The mcp tool schema + llm: The LLM service instance (used to determine if we need Gemini compatibility) Returns: A FunctionSchema instance """ @@ -97,6 +98,11 @@ class MCPClient(BaseObject): properties = tool_schema["input_schema"].get("properties", {}) required = tool_schema["input_schema"].get("required", []) + + # Only clean properties for Google/Gemini LLM services + if llm and self._is_google_llm(llm): + logger.debug(f"Detected Google LLM service, cleaning schema for Gemini compatibility") + properties = self._clean_schema_for_gemini(properties) schema = FunctionSchema( name=tool_name,