Prompts Primitive: Reusable, User/Developer-Controlled Templates

~12 min read

Prompts are predefined templates or multi-turn workflows the server can supply, letting a host reuse sophisticated prompt patterns without hardcoding them — usually selected by a user or developer, not decided spontaneously by the model.

Prompts, in MCP's context, are a distinct kind of capability from both tools and resources: predefined prompt templates or conversation flows that can be injected to guide the AI's behavior. A Prompt capability provides a canned set of instructions, or an example dialogue, that helps steer the model for a specific recurring task — a system role like 'You are a code reviewer,' with the user's code inserted for analysis, is exactly the kind of recurring pattern this primitive is built for. Rather than hardcoding that setup inside the host application every time, the MCP server can supply it on demand.

Prompts can also represent genuinely multi-turn workflows, not just a single system message — this course's example is a prompt that defines how to conduct a step-by-step diagnostic interview with a user. By exposing a workflow like this via MCP, any client connecting to that server can retrieve and use the same sophisticated, pre-designed prompt pattern on demand, rather than every client having to independently design and hardcode its own version.

The control model for Prompts differs meaningfully from both Tools and Resources: Prompts are usually user-controlled or developer-controlled, not model-initiated. A user might pick a prompt or template from a UI — 'Summarize this document' as a selectable option — which the host then fetches from the server. The model doesn't spontaneously decide to use a prompt the way it decides to call a tool; instead, the prompt sets the stage BEFORE the model starts generating, typically fetched at the beginning of an interaction or when the user selects a specific 'mode.'

Concretely, a code-review prompt template on an MCP server might return a list of message objects (in a familiar chat-API format) that set up the code-review scenario — system role, instructions, and a slot for the actual code. When the host invokes this prompt, it receives those pre-structured messages and inserts the real code to be reviewed into the appropriate place, getting a consistent, well-designed prompt setup without having to author it itself.

💻 Code example

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("code-review-server")

@mcp.prompt()
def code_review_prompt(code: str) -> list[dict]:
    """A reusable, pre-designed prompt template — any client can
    fetch this instead of every host independently authoring its
    own version of a good code-review prompt."""
    return [
        {"role": "system", "content": "You are an expert code reviewer. "
            "Review the following code for bugs, style issues, and "
            "potential edge cases."},
        {"role": "user", "content": f"Please review this code:\n\n{code}"},
    ]

# The USER selects this template (not the model deciding spontaneously) —
# e.g. clicking a "Review my code" option in a UI, which the host
# then fetches from the server and inserts the actual code into:
def use_prompt_template(user_selected_code: str) -> list[dict]:
    messages = code_review_prompt(user_selected_code)
    # These pre-structured messages are what actually gets sent to the LLM
    return messages

💬 Deep Dive with AI

Key points

  • Prompts are predefined templates or multi-turn workflows the server supplies, avoiding re-hardcoding recurring prompt patterns in every host
  • Can represent full multi-turn workflows (e.g. a step-by-step diagnostic interview), not just a single system message
  • Usually user-controlled or developer-controlled, unlike tools (model-initiated) — the model doesn't spontaneously decide to use a prompt
  • Prompts set the stage BEFORE generation starts, typically fetched at the beginning of an interaction or when a user picks a specific mode
  • A prompt template returns pre-structured messages (e.g. system + user roles) that the host completes with real content and sends to the LLM