add more ops
This commit is contained in:
parent
9da3b51201
commit
84d1478b66
|
|
@ -1,14 +1,31 @@
|
||||||
from fastmcp import FastMCP
|
from fastmcp import FastMCP
|
||||||
|
|
||||||
# Create a named server
|
# Create a named server
|
||||||
mcp = FastMCP("Addition Server")
|
mcp = FastMCP("Math Operations Server")
|
||||||
|
|
||||||
# Define an addition tool
|
# Define mathematical operation tools
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
def add(a: int, b: int) -> int:
|
def add(a: int, b: int) -> int:
|
||||||
"""Add two numbers together"""
|
"""Add two numbers together"""
|
||||||
return a + b
|
return a + b
|
||||||
|
|
||||||
|
@mcp.tool()
|
||||||
|
def subtract(a: int, b: int) -> int:
|
||||||
|
"""Subtract b from a"""
|
||||||
|
return a - b
|
||||||
|
|
||||||
|
@mcp.tool()
|
||||||
|
def multiply(a: int, b: int) -> int:
|
||||||
|
"""Multiply two numbers together"""
|
||||||
|
return a * b
|
||||||
|
|
||||||
|
@mcp.tool()
|
||||||
|
def divide(a: int, b: int) -> float:
|
||||||
|
"""Divide a by b"""
|
||||||
|
if b == 0:
|
||||||
|
raise ValueError("Division by zero is not allowed")
|
||||||
|
return a / b
|
||||||
|
|
||||||
# Start the server
|
# Start the server
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
mcp.run()
|
mcp.run()
|
||||||
|
|
@ -42,6 +42,39 @@ def local_get_tools(server_script_path=None):
|
||||||
},
|
},
|
||||||
"required": ["a", "b"]
|
"required": ["a", "b"]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "subtract",
|
||||||
|
"description": "Subtract b from a",
|
||||||
|
"inputSchema": {
|
||||||
|
"properties": {
|
||||||
|
"a": {"type": "integer"},
|
||||||
|
"b": {"type": "integer"}
|
||||||
|
},
|
||||||
|
"required": ["a", "b"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "multiply",
|
||||||
|
"description": "Multiply two numbers together",
|
||||||
|
"inputSchema": {
|
||||||
|
"properties": {
|
||||||
|
"a": {"type": "integer"},
|
||||||
|
"b": {"type": "integer"}
|
||||||
|
},
|
||||||
|
"required": ["a", "b"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "divide",
|
||||||
|
"description": "Divide a by b",
|
||||||
|
"inputSchema": {
|
||||||
|
"properties": {
|
||||||
|
"a": {"type": "integer"},
|
||||||
|
"b": {"type": "integer"}
|
||||||
|
},
|
||||||
|
"required": ["a", "b"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -88,6 +121,23 @@ def local_call_tool(server_script_path=None, tool_name=None, arguments=None):
|
||||||
return arguments["a"] + arguments["b"]
|
return arguments["a"] + arguments["b"]
|
||||||
else:
|
else:
|
||||||
return "Error: Missing required arguments 'a' or 'b'"
|
return "Error: Missing required arguments 'a' or 'b'"
|
||||||
|
elif tool_name == "subtract":
|
||||||
|
if "a" in arguments and "b" in arguments:
|
||||||
|
return arguments["a"] - arguments["b"]
|
||||||
|
else:
|
||||||
|
return "Error: Missing required arguments 'a' or 'b'"
|
||||||
|
elif tool_name == "multiply":
|
||||||
|
if "a" in arguments and "b" in arguments:
|
||||||
|
return arguments["a"] * arguments["b"]
|
||||||
|
else:
|
||||||
|
return "Error: Missing required arguments 'a' or 'b'"
|
||||||
|
elif tool_name == "divide":
|
||||||
|
if "a" in arguments and "b" in arguments:
|
||||||
|
if arguments["b"] == 0:
|
||||||
|
return "Error: Division by zero is not allowed"
|
||||||
|
return arguments["a"] / arguments["b"]
|
||||||
|
else:
|
||||||
|
return "Error: Missing required arguments 'a' or 'b'"
|
||||||
else:
|
else:
|
||||||
return f"Error: Unknown tool '{tool_name}'"
|
return f"Error: Unknown tool '{tool_name}'"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue