Prompt Messages & Embedded Resources

+15 Mana ✨

Introduction

When a client retrieves a prompt via prompts/get, the server returns a structured response containing a messages array. These messages define a conversation that the client sends to the LLM. Prompt messages can include multiple turns, embedded resources, and different content types, making them a powerful mechanism for guiding LLM behavior.

Key Concepts

A prompt response contains a messages array where each message has:

  • role: Either user or assistant, defining who is "speaking" in the template
  • content: The message content, which can be text, image, audio, or an embedded resource

Here is a simple single-message prompt response:

json
{
  "description": "Summarize a document",
  "messages": [
    {
      "role": "user",
      "content": {
        "type": "text",
        "text": "Please summarize the following document in 3 bullet points:\n\nThe Model Context Protocol (MCP) is an open standard..."
      }
    }
  ]
}

This is the simplest form — a single user message with text content.

Real World Context

Consider a prompt for classifying customer support tickets. The template might include a user message with the ticket text and an assistant message showing the expected format. When the LLM receives this pre-structured conversation, it understands both the task and the expected output format, leading to more consistent results.

Deep Dive

Multi-turn messages let prompts include both user and assistant messages to create few-shot examples. The LLM sees a conversation pattern and follows it:

json
{
  "description": "Classify support tickets with examples",
  "messages": [
    {
      "role": "user",
      "content": {
        "type": "text",
        "text": "Classify this support ticket: 'My payment was charged twice'"
      }
    },
    {
      "role": "assistant",
      "content": {
        "type": "text",
        "text": "Category: Billing\nPriority: High\nSentiment: Frustrated"
      }
    },
    {
      "role": "user",
      "content": {
        "type": "text",
        "text": "Classify this support ticket: 'How do I export my data?'"
      }
    }
  ]
}

The first user-assistant pair serves as a few-shot example. The final user message contains the actual ticket to classify. This pattern dramatically improves consistency in LLM responses.

Embedded resources allow prompts to include data from MCP resources directly in messages. Instead of plain text, a message's content can reference a resource URI:

json
{
  "description": "Review a code file",
  "messages": [
    {
      "role": "user",
      "content": {
        "type": "resource",
        "resource": {
          "uri": "file:///src/main.py",
          "mimeType": "text/x-python",
          "text": "def calculate(x, y):\n    return x + y"
        }
      }
    }
  ]
}

The embedded resource includes the URI for provenance tracking and the actual content for the LLM to process. This bridges prompts and resources — the prompt template can pull in data from the server's resource system.

Content types in prompt messages include:

  • text: Plain text or structured text content, the most common type
  • image: Base64-encoded image data with a MIME type, useful for visual analysis prompts
  • audio: Base64-encoded audio data with a MIME type, useful for voice and speech analysis prompts
  • resource: An embedded MCP resource with URI, MIME type, and content

Here is an image content example:

json
{
  "role": "user",
  "content": {
    "type": "image",
    "data": "iVBORw0KGgoAAAANSUhEUgAA...",
    "mimeType": "image/png"
  }
}

Image content enables prompts for visual tasks like screenshot analysis, diagram review, or image description.

Common Pitfalls

  • Using only single-turn prompts: Multi-turn messages with few-shot examples significantly improve output quality. Use them whenever consistency is important.
  • Embedding large resources inline: Very large files should be referenced via resource URIs rather than embedded directly, to avoid bloating the prompt.
  • Forgetting the role field: Every message needs a role. Mixing up user and assistant roles in few-shot examples confuses the LLM.

Best Practices

  • Use multi-turn messages with few-shot examples for classification, formatting, and structured output tasks.
  • Embed resources when the prompt needs specific data from the server's resource system.
  • Keep embedded content concise — if a resource is large, consider summarizing it or including only the relevant section.
  • Use image content for visual analysis workflows like UI review or diagram validation.

Summary

Prompt responses contain a messages array with role-based entries that guide LLM behavior. Multi-turn messages enable few-shot learning by providing example conversations. Embedded resources bridge the prompts and resources primitives, letting templates include server-managed data. Content types include text, image, audio, and resource references, supporting a wide range of use cases.

Code Examples

json
{
  "description": "Classify support tickets with examples",
  "messages": [
    {
      "role": "user",
      "content": { "type": "text", "text": "Classify: 'My payment was charged twice'" }
    },
    {
      "role": "assistant",
      "content": { "type": "text", "text": "Category: Billing\nPriority: High" }
    },
    {
      "role": "user",
      "content": { "type": "text", "text": "Classify: 'How do I export my data?'" }
    }
  ]
}
✓ Completed