-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (33 loc) · 904 Bytes
/
Copy pathmain.py
File metadata and controls
40 lines (33 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from mcp.server.fastmcp import FastMCP
import json
mcp = FastMCP(name="Simple Calculator server")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
@mcp.tool()
def subtract(a: int, b: int) -> int:
"""Subtract two numbers."""
return a - b
@mcp.tool()
def multiply(a: int, b: int) -> int:
"""Multiply two numbers."""
return a * b
@mcp.tool()
def divide(a: int, b: int) -> float:
"""Divide two numbers."""
if b == 0:
raise ValueError("Cannot divide by zero.")
return a / b
@mcp.resource("info://server")
def server_info():
"""Return information about the server."""
info = {
"name":mcp.name,
"version":"1.0",
"description":"A simple calculator server using FastMCP.",
"author":"Shees"
}
return json.dumps(info)
if __name__ == "__main__":
mcp.run(transport="streamable-http")