Skip to Content

How Do You Define an MCP Tool in Python Using the @mcp.tool Decorator?

What’s the Easiest Way to Create an MCP Server Tool with the Python SDK?

Learn the simplest way to add a document-reading tool to an MCP server in Python: use the @mcp.tool decorator so the SDK can generate the tool definition from your function.

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

In the MCP Python SDK (e.g., FastMCP), decorating a normal Python function with @mcp.tool() is the simplest way to expose it as a tool, because the SDK can derive the tool’s interface from your function signature and type hints instead of you hand-writing a JSON schema.