From 3a9e8e18df4c596360da54000f65e1bebc6039c2 Mon Sep 17 00:00:00 2001 From: tanaka takashi Date: Fri, 26 Jun 2026 23:54:17 +0900 Subject: MCP機能追加 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/calc_server.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 scripts/calc_server.py (limited to 'scripts/calc_server.py') diff --git a/scripts/calc_server.py b/scripts/calc_server.py new file mode 100644 index 0000000..65e121d --- /dev/null +++ b/scripts/calc_server.py @@ -0,0 +1,39 @@ +"""Test MCP server providing basic math tools. + +Usage: + python scripts/calc_server.py # stdio transport + python scripts/calc_server.py streamable-http # HTTP transport +""" + +from mcp.server.fastmcp import FastMCP + +mcp = FastMCP("calc") + + +@mcp.tool() +def add(a: float, b: float) -> float: + """Add two numbers.""" + return a + b + + +@mcp.tool() +def multiply(a: float, b: float) -> float: + """Multiply two numbers.""" + return a * b + + +@mcp.tool() +def sqrt(value: float) -> float: + """Return the square root of a non-negative number.""" + if value < 0: + raise ValueError("value must be non-negative") + return value**0.5 + + +if __name__ == "__main__": + import sys + + transport = sys.argv[1] if len(sys.argv) > 1 else "stdio" + port = int(sys.argv[2]) if len(sys.argv) > 2 else 9000 + mcp.settings.port = port + mcp.run(transport=transport) -- cgit v1.2.3