Skip to main content
Glama

MCP Calculator Server

app.py786 B
# app.py from mcp.server.fastmcp import FastMCP import math def evaluate_expression(expr: str) -> str: try: safe_dict = {k: getattr(math, k) for k in dir(math) if not k.startswith("__")} safe_dict.update({"__builtins__": {}}) return str(eval(expr, safe_dict)) except Exception as e: return f"Error: {e}" class CalculatorMCP(FastMCP): def __init__(self, **kwargs): super().__init__(**kwargs) self.add_tool(self.calculate) def calculate(self, payload: str) -> str: return evaluate_expression(payload) if __name__ == "__main__": server = CalculatorMCP(host="0.0.0.0", port=8500, streamable_http_path="/") print("MCP server running on 0.0.0.0:8500 (root path)") server.run(transport="streamable-http")

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/linuxacademyir/calculator-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server