Skip to main content

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)
Tools are the primary way servers provide active capabilities to AI applications.

Tool Anatomy

Every MCP tool consists of:
  1. Name - Unique identifier for the tool
  2. Description - Explains what the tool does (optional but recommended)
  3. Input Schema - Defines expected parameters with validation
  4. Handler Function - Implements the tool’s logic

Defining Tools in TypeScript

Basic Tool Definition

From source/servers/basic/src/server.ts:64-99:

Tool with Description

From source/servers/basic/src/server.ts:102-125:

Defining Tools in Python

Using FastMCP Decorator

From source/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

From source/servers/calculator-py/server.py:5-17:

CRUD Operations

From source/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

Always validate inputs, even beyond schema validation:
Tool names should clearly indicate their purpose:
Catch errors and return helpful messages:
Help AI models understand how to use your tools:
Each tool should do one thing well:
Tools execute with the same permissions as your server process. Be careful with tools that modify files, execute commands, or access sensitive data.

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