fix(mcp): resolve async coroutine warning by awaiting batch_mcp_flow correctly

pull/819/head
Pavan Kumar 3 months ago committed by ascender1729
parent 3e159f5617
commit e730e576be

@ -22,5 +22,5 @@ def divide(a: int, b: int) -> float:
if __name__ == "__main__": if __name__ == "__main__":
print("Starting Mock Math Server on port 8000...") print("Starting Mock Math Server on port 8000...")
# The port parameter should be included in the transport_kwargs dictionary # Fix the parameters to match the FastMCP API
mcp.run(transport="sse", transport_kwargs={"port": 8000}) mcp.run(transport="sse", port=8000)

@ -2778,11 +2778,10 @@ class Agent:
def mcp_execution_flow(self, payload: dict) -> str | None: def mcp_execution_flow(self, payload: dict) -> str | None:
"""Forward the tool-call dict to every MCP server in self.mcp_servers""" """Forward the tool-call dict to every MCP server in self.mcp_servers"""
try: try:
# Create a new event loop to run the async function # Use asyncio.run which handles creating and closing the event loop
loop = asyncio.new_event_loop() result = asyncio.run(batch_mcp_flow(self.mcp_servers, [payload]))
asyncio.set_event_loop(loop) if not result:
result = loop.run_until_complete(batch_mcp_flow(self.mcp_servers, [payload])) return "No result returned from MCP server"
loop.close()
return any_to_str(result) return any_to_str(result)
except Exception as err: except Exception as err:
logger.error(f"MCP flow failed: {err}") logger.error(f"MCP flow failed: {err}")

Loading…
Cancel
Save