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/math_server.py

35 lines
752 B

from fastmcp import FastMCP
from typing import Dict, Any
# Initialize MCP server
mcp = FastMCP("Math-Server")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers together"""
try:
return a + b
except Exception as e:
return {"error": str(e)}
@mcp.tool()
def multiply(a: int, b: int) -> int:
"""Multiply two numbers together"""
try:
return a * b
except Exception as e:
return {"error": str(e)}
@mcp.tool()
def subtract(a: int, b: int) -> int:
"""Subtract two numbers"""
try:
return a - b
except Exception as e:
return {"error": str(e)}
if __name__ == "__main__":
print("Starting Math Server on port 6274...")
mcp.run(port=6274, transport="sse")