move fastapi to main

This commit is contained in:
2026-01-20 14:54:05 +08:00
parent ab3c1d4d8d
commit 5919480312

View File

@@ -50,20 +50,18 @@ class Calculator(LangToolBase):
return [self.calculator] return [self.calculator]
# Global calculator instance if __name__ == "__main__":
calculator = Calculator(CalculatorConfig()) # Global calculator instance
calculator = Calculator(CalculatorConfig())
# FastMCP server setup # FastMCP server setup
from fastmcp import FastMCP from fastmcp import FastMCP
mcp = FastMCP("Calculator Server") mcp = FastMCP("Calculator Server")
@mcp.tool() @mcp.tool()
async def calculate(python_expression: str) -> dict: async def calculate(python_expression: str) -> dict:
"""For mathematical calculation, always use this tool to calculate the result of a python expression. You can use 'math' or 'random' directly, without 'import'.""" """For mathematical calculation, always use this tool to calculate the result of a python expression. You can use 'math' or 'random' directly, without 'import'."""
return await calculator.calculator_async(python_expression) return await calculator.calculator_async(python_expression)
if __name__ == "__main__":
mcp.run(transport="streamable-http", host="0.0.0.0", port=9000) mcp.run(transport="streamable-http", host="0.0.0.0", port=9000)