main.py•1.12 kB
from fastmcp import FastMCP
import random
import json
# Create the MCP Server instance
mcp = FastMCP("Simple Calculator Server")
# Tool: Add two numbers
@mcp.tool
def add(a:int, b:int) -> dict:
"""Add two numbers together
Args:
a: First number
b: Second number
Returns:
The sum of a and b
"""
return {"result": a + b}
@mcp.tool
def random_number(min: int=1, max: int=100) -> dict:
"""Generate a random number between min and max
Args:
min: Minimum value (default: 1)
max: Maximum value (default: 100)
Returns:
A random number between min and max
"""
return {"result":random.randint(min, max)}
@mcp.resource('info://server')
def server_info()->str:
"""Get information about the server."""
info = {
"name": mcp.name,
"version": mcp.version,
"tools": ['add', 'random_number'],
"author": "Suraj Kumar"
}
return json.dumps(info, indent=1)
if __name__ == "__main__":
# mcp.run()
mcp.run(transport="http", host="127.0.0.1", port=5000)