from fastmcp import FastMCP
import csv
from typing import Optional
from typing import Annotated
from datetime import datetime
from pathlib import Path
from enum import Enum
from starlette.responses import JSONResponse
# Create the MCP server
mcp = FastMCP("Calculator MCP Server")
# ------------------------------------------------------ #
# ------------- CREATE DOCSTRINGS FOR TOOLS ------------ #
# ------------------------------------------------------ #
# Tool to add a task
@mcp.tool
def add(
a: int,
b: int
) -> int:
"""Add two numbers and return the result.
Args:
a (int): The first number to add.
b (int): The second number to add.
Returns:
int: The sum of a and b.
Example:
>>> add(5, 3)
8
"""
return a + b
# Tool to subtract two numbers
@mcp.tool
def subtract(
a: int,
b: int
) -> int:
"""Subtract two numbers and return the result.
Args:
a (int): The first number.
b (int): The second number.
Returns:
int: The difference of a and b.
Example:
>>> subtract(5, 3)
2
"""
return a - b
# Tool to multiply two numbers
@mcp.tool
def multiply(
a: int,
b: int
) -> int:
"""Multiply two numbers and return the result.
Args:
a (int): The first number.
b (int): The second number.
Returns:
int: The product of a and b.
Example:
>>> multiply(5, 3)
15
"""
return a * b
# Tool to divide two numbers
@mcp.tool
def divide(
a: int,
b: int
) -> Optional[float]:
"""Divide two numbers and return the result.
Args:
a (int): The dividend.
b (int): The divisor.
Returns:
Optional[float]: The quotient of a and b, or None if b is 0.
Example:
>>> divide(6, 3)
2.0
>>> divide(5, 0)
None
"""
if b == 0:
return None
return a / b
if __name__ == "__main__":
mcp.run()