Prerequisites: A FrontMCP project initialized (see Installation)
What You’ll Build
A simpleadd tool that adds two numbers together with full type safety and input validation.
Step 1: Create the Tool File
Create a new filesrc/apps/calculator/tools/add.tool.ts:
Step 2: Create the App
Createsrc/apps/calculator/index.ts to group your tools:
Step 3: Register with the Server
Update your main server file to include the app:Step 4: Test Your Tool
1
Start the server
2
Open MCP Inspector
http://localhost:3000 and you’ll see your calculator:add tool listed.3
Call the tool
In the Inspector, call the tool with:You should get back
8.Adding More Tools
Let’s add amultiply tool. Create src/apps/calculator/tools/multiply.tool.ts:
Input Validation
Zod automatically validates inputs. Try callingadd with invalid input:
"not a number" isn’t a valid number.
Common Validation Patterns
Best Practices
Write clear descriptions
Write clear descriptions
Good descriptions help LLMs choose the right tool:
Use .describe() on schema fields
Use .describe() on schema fields
Add context for each input field:
Keep tools focused
Keep tools focused
Each tool should do one thing well. Instead of a
calculate tool that handles add/subtract/multiply/divide, create separate tools for each operation.Handle errors gracefully
Handle errors gracefully
Next Steps
Add Caching
Cache tool results for better performance
Create Prompts
Build prompts and resources alongside tools
Add UI Templates
Render rich HTML widgets for tool outputs
Tool Reference
Full tool decorator documentation