# server.py
from mcp.server.fastmcp import FastMCP
import sys
import logging
logger = logging.getLogger('Calculator')
# Fix UTF-8 encoding for Windows console
if sys.platform == 'win32':
sys.stderr.reconfigure(encoding='utf-8')
sys.stdout.reconfigure(encoding='utf-8')
import math
import random
# Create an MCP server
mcp = FastMCP("Calculator")
# Add an addition tool
@mcp.tool()
def calculator(python_expression: str) -> dict:
"""For mathamatical calculation, always use this tool to calculate the result of a python expression. `math` and `random` are available."""
result = eval(python_expression)
logger.info(f"Calculating formula: {python_expression}, result: {result}")
return {"success": True, "result": result}
# Start the server
if __name__ == "__main__":
mcp.run(transport="stdio")
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/kukuqi666/mcp-calculator'
If you have feedback or need assistance with the MCP directory API, please join our Discord server