Skip to main content
Build a simple calculator tool to learn the fundamentals of FrontMCP tool development. By the end of this guide, you’ll understand how to create, validate, and test MCP tools.
Prerequisites: A FrontMCP project initialized (see Installation)

What You’ll Build

A simple add tool that adds two numbers together with full type safety and input validation.

Step 1: Create the Tool File

Create a new file src/apps/calculator/tools/add.tool.ts:
Let’s break this down:

Step 2: Create the App

Create src/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

Connect to 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 a multiply tool. Create src/apps/calculator/tools/multiply.tool.ts:
Then add it to your app:

Input Validation

Zod automatically validates inputs. Try calling add with invalid input:
You’ll get a validation error because "not a number" isn’t a valid number.

Common Validation Patterns


Best Practices

Good descriptions help LLMs choose the right tool:
Add context for each input field:
Each tool should do one thing well. Instead of a calculate tool that handles add/subtract/multiply/divide, create separate tools for each operation.

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