diff --git a/.replit b/.replit index 74cdc535..69fe1d48 100644 --- a/.replit +++ b/.replit @@ -65,7 +65,15 @@ mode = "sequential" [[workflows.workflow.tasks]] task = "shell.exec" -args = "python examples/mcp_example/mock_math_server.py & " +args = "python examples/mcp_example/mock_stock_server.py &" + +[[workflows.workflow.tasks]] +task = "shell.exec" +args = "sleep 2" + +[[workflows.workflow.tasks]] +task = "shell.exec" +args = "python examples/mcp_example/mock_math_server.py &" [[workflows.workflow.tasks]] task = "shell.exec" diff --git a/examples/mcp_example/mock_multi_agent.py b/examples/mcp_example/mock_multi_agent.py index 499c50b8..45e5cf62 100644 --- a/examples/mcp_example/mock_multi_agent.py +++ b/examples/mcp_example/mock_multi_agent.py @@ -41,12 +41,22 @@ class MathAgent: class MultiAgentMathSystem: def __init__(self): - base_url = "http://0.0.0.0:8000" - self.calculator = MathAgent("Calculator", base_url) + math_url = "http://0.0.0.0:8000" + stock_url = "http://0.0.0.0:8001" + self.calculator = MathAgent("Calculator", math_url) + self.stock_analyst = MathAgent( + "StockAnalyst", + stock_url, + "Stock market analysis agent specializing in financial calculations and market analysis" + ) async def process_task(self, task: str): - result = await self.calculator.process(task) - return [result] # Keep list format for compatibility + # Process with both agents + results = await asyncio.gather( + self.calculator.process(task), + self.stock_analyst.process(task) + ) + return results def run_interactive(self): print("\nMulti-Agent Math System") diff --git a/examples/mcp_example/mock_stock_server.py b/examples/mcp_example/mock_stock_server.py new file mode 100644 index 00000000..da8f5e32 --- /dev/null +++ b/examples/mcp_example/mock_stock_server.py @@ -0,0 +1,30 @@ + +from fastmcp import FastMCP +import time + +# Initialize MCP server +mcp = FastMCP("Stock-Mock-Server") + +@mcp.tool() +def calculate_simple_moving_average(prices: list[float], period: int) -> float: + """Calculate Simple Moving Average""" + try: + time.sleep(0.1) # Simulate processing time + if len(prices) < period: + return {"error": "Not enough data points"} + return sum(prices[-period:]) / period + except Exception as e: + return {"error": f"Error calculating SMA: {str(e)}"} + +@mcp.tool() +def calculate_percentage_change(old_value: float, new_value: float) -> float: + """Calculate percentage change between two values""" + try: + time.sleep(0.1) # Simulate processing time + return ((new_value - old_value) / old_value) * 100 + except Exception as e: + return {"error": f"Error calculating percentage change: {str(e)}"} + +if __name__ == "__main__": + print("Starting Mock Stock Server on port 8001...") + mcp.run(transport="sse", host="0.0.0.0", port=8001)