Step 3 of 4
Add a Typed Tool
Expose one deterministic addition tool with a narrow input schema and a description that clients can understand.
Add a tool between the FastMCP instance and the run block:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("mcp-server-demo")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two integers and return the result."""
return a + b
if __name__ == "__main__":
mcp.run()What the decorator contributes
The decorator registers add as a tool. The SDK uses the function name, type annotations, and docstring to construct the tool description and input schema exposed to clients.
This first tool is intentionally deterministic and side-effect free. It lets you verify discovery and invocation without introducing credentials, network calls, or destructive behavior.
- Both parameters have explicit integer types
- The return value has an explicit type
- The docstring describes the result in plain language
- The tool performs no hidden network or file-system work
Recheck the module
uv run python -m py_compile server.pyStep 3
Ready to continue?
Mark this step complete when you have finished the checks above.
Checking saved progress…