arcticaurora commited on
Commit
35a00c3
·
verified ·
1 Parent(s): 5546ec0

Create tools/calculator.py

Browse files
Files changed (1) hide show
  1. tools/calculator.py +28 -0
tools/calculator.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mcp.server.fastmcp import FastMCP
2
+
3
+ mcp = FastMCP("Calculator")
4
+
5
+ @mcp.tool()
6
+ def add(a: float, b: float) -> float:
7
+ """Add two numbers"""
8
+ return a + b
9
+
10
+ @mcp.tool()
11
+ def subtract(a: float, b: float) -> float:
12
+ """Subtract b from a"""
13
+ return a - b
14
+
15
+ @mcp.tool()
16
+ def multiply(a: float, b: float) -> float:
17
+ """Multiply two numbers"""
18
+ return a * b
19
+
20
+ @mcp.tool()
21
+ def divide(a: float, b: float) -> float:
22
+ """Divide a by b"""
23
+ if b == 0:
24
+ raise ValueError("Cannot divide by zero")
25
+ return a / b
26
+
27
+ if __name__ == "__main__":
28
+ mcp.run()