Lesson 5 - Step 1 of 6

What are MCP Tools?

Understand model-controlled functions, inputSchema, and when to use tools.

What You'll Build

In this lesson, you'll build tools.py — a reusable tool registry module, plus calculator_example.py to demonstrate it. By the end, your server will:

  • Define tools with proper JSON Schema inputSchema
  • Handle tools/list to advertise available tools
  • Handle tools/call to execute tools with arguments
  • Return properly formatted results (text content, error handling)
  • Validate arguments and handle errors gracefully

Each step builds on the previous one, and you'll test your server with curl commands.

Tools: Model-Controlled Functions

Tools are one of the three core primitives in MCP. They represent functions that an AI model can choose to execute. Unlike resources (which are application-controlled), tools are model-controlled — the AI decides when and how to use them.

Model-Controlled vs Application-Controlled

Model-controlled means the AI model decides when to invoke the functionality based on context and user requests. The model reads tool descriptions and chooses appropriate tools to accomplish tasks.

What Can Tools Do?

Tools can perform any action your server can execute:

  • Query databases or APIs
  • Perform calculations
  • Read/write files
  • Execute system commands
  • Send notifications or emails
  • Interact with external services

Tool Anatomy

Every MCP tool has three key components:

Component Purpose
name Unique identifier for the tool
description Human-readable explanation of what the tool does
inputSchema JSON Schema defining the expected arguments

Example Tool Definition

Here's what a simple tool looks like in MCP:

json
{
    "name": "get_weather",
    "description": "Get the current weather for a specified city",
    "inputSchema": {
        "type": "object",
        "properties": {
            "city": {
                "type": "string",
                "description": "The city name to get weather for"
            },
            "units": {
                "type": "string",
                "enum": ["celsius", "fahrenheit"],
                "description": "Temperature units"
            }
        },
        "required": ["city"]
    }
}

The inputSchema

The inputSchema uses JSON Schema to define what arguments the tool accepts. This serves multiple purposes:

  • Helps the AI model understand what parameters to provide
  • Enables validation of arguments before execution
  • Documents the tool's interface for developers
  • Allows clients to generate UI forms for tool inputs
Write Good Descriptions

The AI model uses descriptions to decide which tool to use and how. Be specific and clear about what each tool does and what each parameter means.

When to Use Tools

Use tools when you need the AI to:

  • Take actions — anything that changes state or has side effects
  • Compute results — calculations, transformations, processing
  • Fetch dynamic data — current time, live API calls, database queries
  • Interact with systems — file operations, API calls, commands

Tools vs Resources

Understanding when to use each primitive:

Use Tools When... Use Resources When...
Action has side effects Data is read-only
AI should decide when to call App controls when to load
Needs computed/dynamic result Static or slowly-changing data
Requires parameters Identified by URI
Coming Up

In the next steps, we'll dive deep into tool definitions, learn how to implement tools/list and tools/call, and build a complete calculator tool set.