Skip to main content

What are Tools?

Tools in MCP allow servers to expose executable functions that can be invoked by clients and used by LLMs to perform actions. They are the primary way to add functionality to your MCP server. FastMCP uses the Standard Schema specification for defining tool parameters, which means you can use your preferred schema validation library (Zod, ArkType, or Valibot).

Basic Usage

Add a tool to your server using the addTool method:

Schema Validation

FastMCP supports multiple schema validation libraries through the Standard Schema specification.

Tools Without Parameters

You can create tools that don’t require any parameters:
Both approaches are fully compatible with all MCP clients, including Cursor.

Return Types

Tools can return different types of content:

Returning a String

The simplest return type - automatically wrapped as text content:

Returning Content Array

For multiple messages or mixed content types:

Returning an Image

Use the imageContent helper to return images:

Returning Audio

Use the audioContent helper to return audio files:

Combining Content Types

Return multiple content types in a single response:

Tool Authorization

Control access to tools based on user authentication:
See the Authentication section for more details on authorization helpers like requireAuth, requireScopes, and requireRole.

Progress Reporting

Report progress during long-running operations:

Streaming Output

Stream partial results while the tool is executing:
Set streamingHint: true in annotations to signal that the tool uses streaming. You can return void if all content was streamed, or return a final result to append.

Tool Annotations

Provide metadata about tool behavior:

Available Annotations

Logging

Log messages to the client during tool execution:
Available log methods:
  • log.debug(message, data?)
  • log.info(message, data?)
  • log.warn(message, data?)
  • log.error(message, data?)

Error Handling

Throw UserError for errors meant to be shown to the user:

Timeouts

Set a timeout for tool execution:

API Reference

Tool Type

Context Type