diff --git a/.replit b/.replit index cb9288aa..fe2a164e 100644 --- a/.replit +++ b/.replit @@ -68,10 +68,6 @@ mode = "sequential" task = "shell.exec" args = "python examples/mcp_example/math_server.py &" -[[workflows.workflow.tasks]] -task = "shell.exec" -args = "python examples/mcp_example/calc_server.py &" - [[workflows.workflow.tasks]] task = "shell.exec" args = "sleep 2" diff --git a/examples/mcp_example/math_server.py b/examples/mcp_example/math_server.py index 4f3b111b..0e3dab68 100644 --- a/examples/mcp_example/math_server.py +++ b/examples/mcp_example/math_server.py @@ -1,13 +1,13 @@ from fastmcp import FastMCP -from typing import Dict, Any +from litellm import LiteLLM # Initialize MCP server for math operations mcp = FastMCP("Math-Server") @mcp.tool() def add(a: float, b: float) -> float: - """Add two numbers""" + """Add two numbers together""" return a + b @mcp.tool() @@ -17,7 +17,7 @@ def subtract(a: float, b: float) -> float: @mcp.tool() def multiply(a: float, b: float) -> float: - """Multiply two numbers""" + """Multiply two numbers together""" return a * b @mcp.tool() @@ -27,15 +27,7 @@ def divide(a: float, b: float) -> float: return {"error": "Cannot divide by zero"} return a / b -@mcp.tool() -def calculate_percentage(part: float, whole: float) -> float: - """Calculate percentage""" - if whole == 0: - return {"error": "Cannot calculate percentage with zero total"} - return (part / whole) * 100 - if __name__ == "__main__": print("Starting Math Server on port 6274...") - # Initialize LiteLLM with specific model -llm = LiteLLM(model_name="gpt-4o-mini") -mcp.run(transport="sse", host="0.0.0.0", port=6274) + llm = LiteLLM(model_name="gpt-4o-mini") + mcp.run(transport="sse", host="0.0.0.0", port=6274) diff --git a/examples/mcp_example/test_integration.py b/examples/mcp_example/test_integration.py index edce69db..e057c9b0 100644 --- a/examples/mcp_example/test_integration.py +++ b/examples/mcp_example/test_integration.py @@ -1,5 +1,4 @@ from swarms import Agent -from swarms.prompts.finance_agent_sys_prompt import FINANCIAL_AGENT_SYS_PROMPT from swarms.tools.mcp_integration import MCPServerSseParams import logging from datetime import datetime @@ -13,6 +12,13 @@ api_key = os.getenv("SWARMS_API_KEY") or os.getenv("OPENAI_API_KEY") if not api_key: raise ValueError("Please set either SWARMS_API_KEY or OPENAI_API_KEY in your environment") +# Configure MCP server connections +math_server = MCPServerSseParams( + url="http://0.0.0.0:6274", + headers={"Content-Type": "application/json"}, + timeout=10.0 +) + def setup_agent(name: str, description: str, servers: list) -> Agent: """Setup an agent with MCP server connections""" return Agent( @@ -22,24 +28,11 @@ def setup_agent(name: str, description: str, servers: list) -> Agent: max_loops=1, mcp_servers=servers, streaming_on=False, - model_name="gpt-4o-mini" # Added model_name here + model_name="gpt-4o-mini" ) def main(): - # Configure MCP server connections - math_server = MCPServerSseParams( - url="http://0.0.0.0:6274", - headers={"Content-Type": "application/json"}, - timeout=10.0 - ) - - calc_server = MCPServerSseParams( - url="http://0.0.0.0:6275", - headers={"Content-Type": "application/json"}, - timeout=10.0 - ) - - # Initialize specialized agents + # Initialize specialized math agent math_agent = setup_agent( "Math-Agent", "Handles mathematical calculations", @@ -57,18 +50,9 @@ def main(): if user_input.lower() == 'exit': break - if any(op in user_input.lower() for op in ['add', 'subtract', 'multiply', 'divide']): - print(f"\n[{timestamp}] Processing math request...") - response = math_agent.run(user_input) - result = response.get('output') if isinstance(response, dict) else response - try: - nums = [int(x) for x in user_input.split() if x.isdigit()] - if len(nums) == 2: - print(f"\n[{timestamp}] Math calculation result: {nums[0]} + {nums[1]} = {nums[0] + nums[1]}") - else: - print(f"\n[{timestamp}] Math calculation result: {result}") - except: - print(f"\n[{timestamp}] Math calculation result: {result}") + print(f"\n[{timestamp}] Processing math request...") + response = math_agent.run(user_input) + print(f"\n[{timestamp}] Math calculation result: {response}") except KeyboardInterrupt: print("\nExiting gracefully...")