mcp_service: lint

This commit is contained in:
vipyne
2025-06-26 14:51:04 -05:00
parent 3b92113680
commit 37929533af
2 changed files with 10 additions and 22 deletions

View File

@@ -16,10 +16,10 @@ from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.runner import PipelineRunner from pipecat.pipeline.runner import PipelineRunner
from pipecat.pipeline.task import PipelineParams, PipelineTask from pipecat.pipeline.task import PipelineParams, PipelineTask
from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext
from pipecat.services.openai.llm import OpenAILLMService
from pipecat.services.cartesia.tts import CartesiaTTSService from pipecat.services.cartesia.tts import CartesiaTTSService
from pipecat.services.deepgram.stt import DeepgramSTTService from pipecat.services.deepgram.stt import DeepgramSTTService
from pipecat.services.mcp_service import MCPClient from pipecat.services.mcp_service import MCPClient
from pipecat.services.openai.llm import OpenAILLMService
from pipecat.transports.base_transport import BaseTransport, TransportParams from pipecat.transports.base_transport import BaseTransport, TransportParams
from pipecat.transports.network.fastapi_websocket import FastAPIWebsocketParams from pipecat.transports.network.fastapi_websocket import FastAPIWebsocketParams
from pipecat.transports.services.daily import DailyParams from pipecat.transports.services.daily import DailyParams
@@ -58,9 +58,7 @@ async def run_example(transport: BaseTransport, _: argparse.Namespace, handle_si
voice_id="71a7ad14-091c-4e8e-a314-022ece01c121", # British Reading Lady voice_id="71a7ad14-091c-4e8e-a314-022ece01c121", # British Reading Lady
) )
llm = OpenAILLMService( llm = OpenAILLMService(api_key=os.getenv("OPENAI_API_KEY"), model="gpt-4o-mini")
api_key=os.getenv("OPENAI_API_KEY"), model="gpt-4o-mini"
)
try: try:
# Github MCP docs: https://github.com/github/github-mcp-server # Github MCP docs: https://github.com/github/github-mcp-server

View File

@@ -17,8 +17,8 @@ from pipecat.utils.base_object import BaseObject
try: try:
from mcp import ClientSession, StdioServerParameters from mcp import ClientSession, StdioServerParameters
from mcp.client.session_group import SseServerParameters, StreamableHttpParameters
from mcp.client.session import ClientSession from mcp.client.session import ClientSession
from mcp.client.session_group import SseServerParameters, StreamableHttpParameters
from mcp.client.sse import sse_client from mcp.client.sse import sse_client
from mcp.client.stdio import stdio_client from mcp.client.stdio import stdio_client
from mcp.client.streamable_http import streamablehttp_client from mcp.client.streamable_http import streamablehttp_client
@@ -81,7 +81,6 @@ class MCPClient(BaseObject):
tools_schema = await self._register_tools(llm) tools_schema = await self._register_tools(llm)
return tools_schema return tools_schema
def _convert_mcp_schema_to_pipecat( def _convert_mcp_schema_to_pipecat(
self, tool_name: str, tool_schema: Dict[str, Any] self, tool_name: str, tool_schema: Dict[str, Any]
) -> FunctionSchema: ) -> FunctionSchema:
@@ -131,9 +130,7 @@ class MCPClient(BaseObject):
logger.debug(f"Executing tool '{function_name}' with call ID: {tool_call_id}") logger.debug(f"Executing tool '{function_name}' with call ID: {tool_call_id}")
logger.trace(f"Tool arguments: {json.dumps(arguments, indent=2)}") logger.trace(f"Tool arguments: {json.dumps(arguments, indent=2)}")
try: try:
async with self._client( async with self._client(**self._server_params.model_dump()) as (read, write):
**self._server_params.model_dump()
) as (read, write):
async with self._session(read, write) as session: async with self._session(read, write) as session:
await session.initialize() await session.initialize()
await self._call_tool(session, function_name, arguments, result_callback) await self._call_tool(session, function_name, arguments, result_callback)
@@ -146,9 +143,7 @@ class MCPClient(BaseObject):
logger.debug(f"SSE server parameters: {self._server_params}") logger.debug(f"SSE server parameters: {self._server_params}")
logger.debug("Starting registration of mcp tools") logger.debug("Starting registration of mcp tools")
async with self._client( async with self._client(**self._server_params.model_dump()) as (read, write):
**self._server_params.model_dump()
) as (read, write):
async with self._session(read, write) as session: async with self._session(read, write) as session:
await session.initialize() await session.initialize()
tools_schema = await self._list_tools(session, mcp_tool_wrapper, llm) tools_schema = await self._list_tools(session, mcp_tool_wrapper, llm)
@@ -213,9 +208,7 @@ class MCPClient(BaseObject):
logger.debug(f"Executing tool '{function_name}' with call ID: {tool_call_id}") logger.debug(f"Executing tool '{function_name}' with call ID: {tool_call_id}")
logger.trace(f"Tool arguments: {json.dumps(arguments, indent=2)}") logger.trace(f"Tool arguments: {json.dumps(arguments, indent=2)}")
try: try:
async with self._client( async with self._client(**self._server_params.model_dump()) as (
**self._server_params.model_dump()
) as (
read_stream, read_stream,
write_stream, write_stream,
_, _,
@@ -231,9 +224,7 @@ class MCPClient(BaseObject):
logger.debug("Starting registration of mcp tools using streamable HTTP") logger.debug("Starting registration of mcp tools using streamable HTTP")
async with self._client( async with self._client(**self._server_params.model_dump()) as (
**self._server_params.model_dump()
) as (
read_stream, read_stream,
write_stream, write_stream,
_, _,
@@ -286,8 +277,7 @@ class MCPClient(BaseObject):
try: try:
# Convert the schema # Convert the schema
function_schema = self._convert_mcp_schema_to_pipecat( function_schema = self._convert_mcp_schema_to_pipecat(
tool_name, tool_name, {"description": tool.description, "input_schema": tool.inputSchema}
{"description": tool.description, "input_schema": tool.inputSchema}
) )
# Register the wrapped function # Register the wrapped function