add
Add two numbers together to calculate their sum using this arithmetic tool from the MCP Server Example.
Instructions
Add two numbers.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Implementation Reference
- server.py:20-23 (handler)The 'add' tool handler function. It's registered as an MCP tool via the @mcp.tool() decorator and implements the logic to add two float numbers and return the result.
@mcp.tool() def add(a: float, b: float) -> float: """Add two numbers.""" return a + b - server.py:20-20 (registration)The @mcp.tool() decorator registers the 'add' function as an MCP tool, making it available for Claude to invoke.
@mcp.tool() - server.py:21-23 (schema)The schema is defined via Python type hints: accepts two float parameters (a, b) and returns a float. The docstring provides the tool description.
def add(a: float, b: float) -> float: """Add two numbers.""" return a + b