MemotivaDefining MCP Tools with the Python SDK

How do you build a simple document reading tool in MCP?

Defining MCP Tools with the Python SDK

Audio flashcard · 0:32

Nortren·

How do you build a simple document reading tool in MCP?

0:32

Imagine the first tool in a document management server: a function that reads a document's contents by ID. You write a normal Python function that takes a document ID as its only parameter, looks the ID up in your in-memory dictionary, and returns the contents. You add the mcp tool decorator to register it. The decorator specifies the tool name and the description. The Pydantic Field class on the parameter provides a clear description of what the document ID argument expects. With those few lines, Claude can now discover the tool, see its schema, and decide to call it whenever a user asks to read a document.
github.com