What are Tools?
In MCP, tools are executable functions that servers expose to clients. They allow AI applications to perform actions like:- Fetching data from external APIs
- Performing calculations
- Manipulating data
- Interacting with external systems
- Managing state (CRUD operations)
Tool Anatomy
Every MCP tool consists of:- Name - Unique identifier for the tool
- Description - Explains what the tool does (optional but recommended)
- Input Schema - Defines expected parameters with validation
- Handler Function - Implements the tool’s logic
Defining Tools in TypeScript
Basic Tool Definition
Fromsource/servers/basic/src/server.ts:64-99:
Tool with Description
Fromsource/servers/basic/src/server.ts:102-125:
Defining Tools in Python
Using FastMCP Decorator
Fromsource/servers/calculator-py/server.py:19-30:
Python type hints are automatically converted to JSON schema for validation. The docstring becomes the tool description.
Real-World Tool Examples
API Integration Tool
Fetching data from external APIs:Calculation Tool
Fromsource/servers/calculator-py/server.py:5-17:
CRUD Operations
Fromsource/servers/todo-ts/src/index.ts:15-97:
Input Validation
TypeScript with Zod
Zod provides powerful schema validation:Python Type Validation
Response Format
All tool responses follow a standard format:Success Response
Error Response
Multiple Content Items
Calling Tools from Clients
Best Practices
Validate All Inputs
Validate All Inputs
Always validate inputs, even beyond schema validation:
Use Descriptive Names
Use Descriptive Names
Tool names should clearly indicate their purpose:
Handle Errors Gracefully
Handle Errors Gracefully
Catch errors and return helpful messages:
Add Descriptions and Schema Details
Add Descriptions and Schema Details
Help AI models understand how to use your tools:
Keep Tools Focused
Keep Tools Focused
Each tool should do one thing well:
Testing Tools
Test your tools before deploying:Next Steps
Resources
Learn how to provide data through resources
Prompts
Create reusable prompt templates for AI interactions
Servers
Understand MCP server architecture
Clients
Learn how clients consume tools