简体中文
calculator
from ultrarag_mcp.server import UltraRAG_MCP_Server app = UltraRAG_MCP_Server("calculator") if __name__ == "__main__": app.run(transport="stdio")
@app.tool
from ultrarag_mcp.server import UltraRAG_MCP_Server app = UltraRAG_MCP_Server("calculator") @app.tool(output="a,b->result") def add(a: float, b: float) -> Dict[str, float]: """Return the sum of a and b""" return {"result": a + b} @app.tool(output="result") def minus(a: float, b: float) -> Dict[str, float]: """Return a - b""" return {"result": a - b} @app.tool(output="a,b->None") def log(a: float, b: float) -> None: """Logging a, b""" app.logger.info(f"a: {a}, b:{b}") if __name__ == "__main__": app.run(transport="stdio")
servers/calculator/parameter.yaml
a: 1 b: 2
from ultrarag_mcp.server import UltraRAG_MCP_Server app = UltraRAG_MCP_Server("calculator") class Calculator: def __init__(self, mcp_inst: UltraRAG_MCP_Server) mcp_inst.tool(self.add, output="b->result") mcp_inst.tool(self.minus, output="result") mcp_inst.tool(self.log, output="none") self.a = 10 # 模拟全局变量 def add(self, b: float) -> Dict[str, float]: return {"result": self.a + b} def minus(self, b: float) -> Dict[str, float]: return {"result": self.a - b} def log(self, b: float): app.logger.info(f"a: {a}, b:{b}") if __name__ == "__main__": Calculator(app) app.run(transport="stdio")
此页面对您有帮助吗?