clean mcp schema for gemini models, update http mcp example to use gemini

This commit is contained in:
Yousif Astarabadi
2025-06-26 13:14:45 -07:00
parent 19354c6f2d
commit 9d5f5844b8
2 changed files with 11 additions and 2 deletions

View File

@@ -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

View File

@@ -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,