mcp_service: lint
This commit is contained in:
@@ -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
|
||||||
@@ -132,4 +130,4 @@ async def run_example(transport: BaseTransport, _: argparse.Namespace, handle_si
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from pipecat.examples.run import main
|
from pipecat.examples.run import main
|
||||||
|
|
||||||
main(run_example, transport_params=transport_params)
|
main(run_example, transport_params=transport_params)
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -306,4 +296,4 @@ class MCPClient(BaseObject):
|
|||||||
logger.debug(f"Completed registration of {len(tool_schemas)} tools")
|
logger.debug(f"Completed registration of {len(tool_schemas)} tools")
|
||||||
tools_schema = ToolsSchema(standard_tools=tool_schemas)
|
tools_schema = ToolsSchema(standard_tools=tool_schemas)
|
||||||
|
|
||||||
return tools_schema
|
return tools_schema
|
||||||
|
|||||||
Reference in New Issue
Block a user