Skip to Content

How Do You Use the @mcp.tool Decorator to Create Custom MCP Server Tools?

What Is the Easiest Way to Define an MCP Tool Using the Python SDK?

Learn how to easily define custom tools for your Model Context Protocol (MCP) server using the @mcp.tool decorator in the Python SDK to automate schema generation.

Question

You want to create a tool for your MCP server that reads document contents. Using the Python SDK, what’s the easiest way to define this tool?

A. Write a complex JSON schema manually
B. Send an HTTP request
C. Use the @mcp.tool decorator on a function
D. Create a separate configuration file

Answer

C. Use the @mcp.tool decorator on a function

Explanation

Using the Python SDK (specifically via the FastMCP implementation), the easiest way to define a tool is by simply adding the @mcp.tool() decorator above a standard Python function. This decorator automatically handles all the underlying complexity, such as protocol compliance, generating the necessary JSON schema from the function’s type hints, and parsing the docstring into the tool’s description for the AI to understand.