-
-
Save DevloperHS/be05cdbaee2a66e9b26ffeb1257c9e91 to your computer and use it in GitHub Desktop.
a simple calculator mcp server to do arithmetic operations and say hello.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # basic import | |
| from mcp.server.fastmcp import FastMCP | |
| import math | |
| # instantiate an MCP server client | |
| mcp = FastMCP("Hello World") | |
| # DEFINE TOOLS | |
| #addition tool | |
| @mcp.tool() | |
| def add(a: int, b: int) -> int: | |
| """Add two numbers""" | |
| return int(a + b) | |
| # subtraction tool | |
| @mcp.tool() | |
| def subtract(a: int, b: int) -> int: | |
| """Subtract two numbers""" | |
| return int(a - b) | |
| # multiplication tool | |
| @mcp.tool() | |
| def multiply(a: int, b: int) -> int: | |
| """Multiply two numbers""" | |
| return int(a * b) | |
| # division tool | |
| @mcp.tool() | |
| def divide(a: int, b: int) -> float: | |
| """Divide two numbers""" | |
| return float(a / b) | |
| # power tool | |
| @mcp.tool() | |
| def power(a: int, b: int) -> int: | |
| """Power of two numbers""" | |
| return int(a ** b) | |
| # square root tool | |
| @mcp.tool() | |
| def sqrt(a: int) -> float: | |
| """Square root of a number""" | |
| return float(a ** 0.5) | |
| # cube root tool | |
| @mcp.tool() | |
| def cbrt(a: int) -> float: | |
| """Cube root of a number""" | |
| return float(a ** (1/3)) | |
| # factorial tool | |
| @mcp.tool() | |
| def factorial(a: int) -> int: | |
| """factorial of a number""" | |
| return int(math.factorial(a)) | |
| # log tool | |
| @mcp.tool() | |
| def log(a: int) -> float: | |
| """log of a number""" | |
| return float(math.log(a)) | |
| # remainder tool | |
| @mcp.tool() | |
| def remainder(a: int, b: int) -> int: | |
| """remainder of two numbers divison""" | |
| return int(a % b) | |
| # sin tool | |
| @mcp.tool() | |
| def sin(a: int) -> float: | |
| """sin of a number""" | |
| return float(math.sin(a)) | |
| # cos tool | |
| @mcp.tool() | |
| def cos(a: int) -> float: | |
| """cos of a number""" | |
| return float(math.cos(a)) | |
| # tan tool | |
| @mcp.tool() | |
| def tan(a: int) -> float: | |
| """tan of a number""" | |
| return float(math.tan(a)) | |
| # DEFINE RESOURCES | |
| # Add a dynamic greeting resource | |
| @mcp.resource("greeting://{name}") | |
| def get_greeting(name: str) -> str: | |
| """Get a personalized greeting""" | |
| return f"Hello, {name}!" | |
| # execute and return the stdio output | |
| if __name__ == "__main__": | |
| mcp.run(transport="stdio") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment