parent
d71030859d
commit
2e2ebc40c8
@ -1,77 +1,25 @@
|
|||||||
|
|
||||||
from fastmcp import FastMCP
|
from fastmcp import FastMCP
|
||||||
from typing import Dict, Any, Optional
|
from typing import Dict, Any, Optional
|
||||||
|
|
||||||
# Initialize MCP server
|
# Initialize MCP server
|
||||||
mcp = FastMCP("Math-Server")
|
mcp = FastMCP("Math-Server")
|
||||||
|
|
||||||
# Add tool documentation and type hints
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
def add(a: int, b: int) -> Dict[str, Any]:
|
def add(a: int, b: int) -> int:
|
||||||
"""Add two numbers together
|
"""Add two numbers together"""
|
||||||
|
|
||||||
Args:
|
|
||||||
a (int): First number to add
|
|
||||||
b (int): Second number to add
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Dict[str, Any]: Result dictionary containing sum and metadata
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
result = a + b
|
return a + b
|
||||||
return {
|
|
||||||
"status": "success",
|
|
||||||
"result": result,
|
|
||||||
"message": f"Successfully added {a} and {b}"
|
|
||||||
}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {"error": str(e)}
|
||||||
"status": "error",
|
|
||||||
"error": str(e),
|
|
||||||
"message": "Failed to perform addition"
|
|
||||||
}
|
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
def multiply(a: int, b: int) -> Dict[str, Any]:
|
def multiply(a: int, b: int) -> int:
|
||||||
"""Multiply two numbers together
|
"""Multiply two numbers together"""
|
||||||
|
|
||||||
Args:
|
|
||||||
a (int): First number to multiply
|
|
||||||
b (int): Second number to multiply
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Dict[str, Any]: Result dictionary containing product and metadata
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
result = a * b
|
return a * b
|
||||||
return {
|
|
||||||
"status": "success",
|
|
||||||
"result": result,
|
|
||||||
"message": f"Successfully multiplied {a} and {b}"
|
|
||||||
}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {"error": str(e)}
|
||||||
"status": "error",
|
|
||||||
"error": str(e),
|
|
||||||
"message": "Failed to perform multiplication"
|
|
||||||
}
|
|
||||||
|
|
||||||
@mcp.tool()
|
|
||||||
def get_available_operations() -> Dict[str, Any]:
|
|
||||||
"""Get list of available mathematical operations
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Dict[str, Any]: Dictionary containing available operations and their descriptions
|
|
||||||
"""
|
|
||||||
return {
|
|
||||||
"status": "success",
|
|
||||||
"operations": {
|
|
||||||
"add": "Add two numbers together",
|
|
||||||
"multiply": "Multiply two numbers together"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Starting Math Server...")
|
print("Starting Math Server...")
|
||||||
print("Available operations:", get_available_operations())
|
mcp.run(transport="sse")
|
||||||
mcp.run(host="0.0.0.0", port=6274, transport="sse")
|
|
Loading…
Reference in new issue