@mcp.tool() that extend the capabilities of your AI agents.
Basic Example
File:mcp/tools/math.py
Key Requirements
1. Use the @mcp.tool() Decorator
All tools must be decorated with @mcp.tool() to be discovered by Osmosis.
2. Place in mcp/tools/ Directory
Organize your tool modules within the mcp/tools/ directory.
3. Include Type Hints
Type hints are required for all parameters and return values:4. Add Docstrings
Comprehensive docstrings help the AI understand when and how to use your tool:5. Export in __init__.py
Export your tools in mcp/tools/__init__.py:
Server Setup
FastMCP Server Configuration
File:mcp/server/mcp_server.py
Entry Point
File:mcp/main.py
Complete Example
Here’s a more complex tool that demonstrates best practices:Testing Your Tools
Local Testing
Start your MCP server locally:Unit Tests
Create tests for your tools:Best Practices
1. Single Responsibility
Each tool should do one thing well:2. Clear Naming
Use descriptive, action-oriented names:3. Error Handling
Handle errors gracefully:4. Use Type Hints Effectively
Next Steps
Reward Functions
Learn about reward functions
Setup Guide
Complete setup walkthrough
FastMCP Docs
Official FastMCP documentation
Example Repo
See complete examples