AI Hints
Home›MCP Tutorial›Richer Prompts
MCP · Lesson 43 of 120

Multi-Message Prompts

A short conversation.

⏱ 2 min read▶ Video at 38:45🎓 Free
Watch this lesson in the MCP courseWatch on YouTube ↗Full MCP course

A prompt can be more than one message. It can set up a short conversation, with user and assistant turns, to show the model exactly how to behave.

Multi-Message Prompts
From the video: Multi-Message Prompts
  • More than one message
  • User and assistant turns
  • Shows the way

A triage prompt

The prompt returns a list of messages. A user message with the customer's text, an assistant message that commits to a task, and a final instruction. Run it. Three messages, with their roles.

multi_message.pypython
import asyncio
from mcp import Client
from mcp.server.mcpserver import MCPServer
from mcp.server.mcpserver.prompts.base import UserMessage, AssistantMessage

mcp = MCPServer("northwind")

@mcp.prompt()
def triage(message: str) -> list:
    """Sort a customer message into a category."""
    return [UserMessage(f"Customer wrote: {message}"),
            AssistantMessage("I'll sort this into orders, returns, or repairs."),
            UserMessage("Reply with just the category.")]

async def main():
    async with Client(mcp) as client:
        for m in (await client.get_prompt("triage", {"message": "My brakes squeak"})).messages:
            print(m.role, "|", m.content.text)
asyncio.run(main())
Output
user | Customer wrote: My brakes squeak
assistant | I'll sort this into orders, returns, or repairs.
user | Reply with just the category.

When to use it

Use several messages to give an example, to set the assistant's role, or to start a step by step task. Keep it short. Every message is sent to the model each time.

keyvalue
Examplesshow the format
Rolesuser and assistant
Tasksstep by step
Keepshort

Summary

Prompts can return several messages, to guide the model with a small conversation. Next, prompts that include resources.

Key takeaways
  • UserMessage
  • AssistantMessage
  • A list
Next up: Prompts with Resources — embed the data