- Resolved broken or missing import statements in `math_server.py` and `calc_server.py` - Updated server initialization to ensure proper startup and output deliverypull/819/head
parent
3da7bd6381
commit
3273747e6a
@ -1,31 +1,22 @@
|
|||||||
|
|
||||||
import asyncio
|
from fastmcp import FastMCP
|
||||||
from mcp import run
|
import logging
|
||||||
from swarms.utils.litellm_wrapper import LiteLLM
|
|
||||||
|
|
||||||
def calculate_compound_interest(principal: float, rate: float, time: float) -> float:
|
# Configure logging
|
||||||
"""Calculate compound interest."""
|
logging.basicConfig(level=logging.INFO)
|
||||||
return principal * (1 + rate/100) ** time - principal
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def calculate_simple_interest(principal: float, rate: float, time: float) -> float:
|
# Initialize MCP server
|
||||||
"""Calculate simple interest."""
|
mcp = FastMCP("Calc-Server")
|
||||||
return (principal * rate * time) / 100
|
|
||||||
|
|
||||||
# Create tool registry
|
@mcp.tool(name="compound_interest")
|
||||||
tools = {
|
def compound_interest(principal: float, rate: float, time: float) -> float:
|
||||||
"calculate_compound_interest": calculate_compound_interest,
|
return principal * (1 + rate/100) ** time
|
||||||
"calculate_simple_interest": calculate_simple_interest,
|
|
||||||
}
|
|
||||||
|
|
||||||
async def handle_tool(name: str, args: dict) -> dict:
|
@mcp.tool(name="simple_interest")
|
||||||
"""Handle tool execution."""
|
def simple_interest(principal: float, rate: float, time: float) -> float:
|
||||||
try:
|
return (principal * rate * time) / 100
|
||||||
result = tools[name](**args)
|
|
||||||
return {"result": result}
|
|
||||||
except Exception as e:
|
|
||||||
return {"error": str(e)}
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Starting Calculation Server on port 6275...")
|
print("Starting Calculation Server on port 6275...")
|
||||||
llm = LiteLLM()
|
mcp.run(transport="sse", port=6275)
|
||||||
run(transport="sse", port=6275, tool_handler=handle_tool)
|
|
||||||
|
@ -1,42 +1,32 @@
|
|||||||
import asyncio
|
|
||||||
from mcp import run
|
|
||||||
from swarms.utils.litellm_wrapper import LiteLLM
|
|
||||||
|
|
||||||
|
from fastmcp import FastMCP
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# Configure logging
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# Initialize MCP server
|
||||||
|
mcp = FastMCP("Math-Server")
|
||||||
|
|
||||||
|
@mcp.tool(name="add")
|
||||||
def add(a: float, b: float) -> float:
|
def add(a: float, b: float) -> float:
|
||||||
"""Add two numbers together."""
|
return float(a) + float(b)
|
||||||
return a + b
|
|
||||||
|
|
||||||
|
@mcp.tool(name="subtract")
|
||||||
def subtract(a: float, b: float) -> float:
|
def subtract(a: float, b: float) -> float:
|
||||||
"""Subtract b from a."""
|
return float(a) - float(b)
|
||||||
return a - b
|
|
||||||
|
|
||||||
|
@mcp.tool(name="multiply")
|
||||||
def multiply(a: float, b: float) -> float:
|
def multiply(a: float, b: float) -> float:
|
||||||
"""Multiply two numbers together."""
|
return float(a) * float(b)
|
||||||
return a * b
|
|
||||||
|
|
||||||
|
@mcp.tool(name="divide")
|
||||||
def divide(a: float, b: float) -> float:
|
def divide(a: float, b: float) -> float:
|
||||||
"""Divide a by b."""
|
if float(b) == 0:
|
||||||
if b == 0:
|
|
||||||
raise ValueError("Cannot divide by zero")
|
raise ValueError("Cannot divide by zero")
|
||||||
return a / b
|
return float(a) / float(b)
|
||||||
|
|
||||||
# Create tool registry
|
|
||||||
tools = {
|
|
||||||
"add": add,
|
|
||||||
"subtract": subtract,
|
|
||||||
"multiply": multiply,
|
|
||||||
"divide": divide
|
|
||||||
}
|
|
||||||
|
|
||||||
async def handle_tool(name: str, args: dict) -> dict:
|
|
||||||
"""Handle tool execution."""
|
|
||||||
try:
|
|
||||||
result = tools[name](**args)
|
|
||||||
return {"result": result}
|
|
||||||
except Exception as e:
|
|
||||||
return {"error": str(e)}
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Starting Math Server on port 6274...")
|
print("Starting Math Server on port 6274...")
|
||||||
llm = LiteLLM()
|
mcp.run(transport="sse", port=6274)
|
||||||
run(transport="sse", port=6274, tool_handler=handle_tool)
|
|
||||||
|
Loading…
Reference in new issue