Skip to main content
Glama
rwxproject
by rwxproject
arithmetic.py2.3 kB
""" Arithmetic Tools Module Provides basic mathematical operations as MCP tools. This module demonstrates how to migrate existing tools to the new modular structure. """ from fastmcp import FastMCP from .base import BaseTool class ArithmeticTools(BaseTool): """ Collection of basic arithmetic operation tools. Provides addition and subtraction operations that were originally in the main.py file. """ def __init__(self): super().__init__(name="arithmetic") def register_with_mcp(self, mcp: FastMCP) -> None: """ Register arithmetic tools with the FastMCP instance. Args: mcp: The FastMCP instance to register with """ # Register the add tool @mcp.tool() def add(a: int, b: int) -> int: """Use this to add two numbers together. Args: a: The first number. b: The second number. Returns: The sum of the two numbers. """ self._log_tool_call("add", a=a, b=b) return a + b # Register the subtract tool @mcp.tool() def subtract(a: int, b: int) -> int: """Use this to subtract two numbers. Args: a: The first number. b: The second number. Returns: The difference of the two numbers. """ self._log_tool_call("subtract", a=a, b=b) return a - b self.logger.info(f"Registered arithmetic tools: add, subtract") def add_numbers(self, a: int, b: int) -> int: """ Direct method for adding numbers (can be used internally). Args: a: First number b: Second number Returns: Sum of the numbers """ return a + b def subtract_numbers(self, a: int, b: int) -> int: """ Direct method for subtracting numbers (can be used internally). Args: a: First number b: Second number Returns: Difference of the numbers """ return a - b

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rwxproject/mcp-server-template'

If you have feedback or need assistance with the MCP directory API, please join our Discord server