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:
| Property | Purpose |
|---|---|
name | Unique identifier for the tool |
description | Helps LLMs understand when to use this tool |
inputSchema | Zod schema for input validation |
outputSchema | Can be a Zod schema or shorthand like 'number' |
execute() | The logic that runs when the tool is called |
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
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