MemotivaDefining MCP Prompts as Reusable Templates

How do you define an MCP prompt with the Python SDK?

Defining MCP Prompts as Reusable Templates

Audio flashcard · 0:30

Nortren·

How do you define an MCP prompt with the Python SDK?

0:30

Prompts use a similar decorator pattern to tools and resources. You write a Python function that builds a prompt for some task, accepting whatever arguments make sense, like a document ID. You apply the mcp prompt decorator to register that function with the server. Inside the function, you construct a list of messages, typically alternating user and assistant roles, that fully describe the task you want the model to perform. The function returns that list of messages. When a client requests the prompt with arguments, the SDK calls your function and returns the resulting messages directly to the client.
github.com