"""
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