You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
swarms/examples/mcp_example/mock_math_server.py

39 lines
855 B

from fastmcp import FastMCP
from loguru import logger
mcp = FastMCP(
host="0.0.0.0",
port=8000,
transport="sse",
require_session_id=False
)
@mcp.tool()
def add(a: int, b: int) -> str:
"""Add two numbers."""
result = a + b
return f"The sum of {a} and {b} is {result}"
@mcp.tool()
def multiply(a: int, b: int) -> str:
"""Multiply two numbers."""
result = a * b
return f"The product of {a} and {b} is {result}"
@mcp.tool()
def divide(a: int, b: int) -> str:
"""Divide two numbers."""
if b == 0:
return "Cannot divide by zero"
result = a / b
return f"{a} divided by {b} is {result}"
if __name__ == "__main__":
try:
logger.info("Starting math server on http://0.0.0.0:8000")
mcp.run()
except Exception as e:
logger.error(f"Server error: {e}")
raise