Skip to main content

What are Prompts?

In MCP, prompts are reusable templates that generate structured messages for AI interactions. They allow servers to:
  • Provide pre-configured conversation starters
  • Create specialized analysis workflows
  • Inject context and instructions for AI models
  • Standardize common AI interaction patterns
Prompts are dynamic templates that can accept parameters to customize the generated messages.

Prompt Structure

Every MCP prompt consists of:
  1. Name - Unique identifier for the prompt
  2. Parameters - Input schema for customization (optional)
  3. Handler - Generates the prompt messages
  4. Messages - Array of message objects with roles and content

Defining Prompts in TypeScript

Basic Prompt

From source/servers/basic/src/server.ts:259-294:

Prompt with Optional Parameters

From source/servers/basic/src/server.ts:214-257:

Message Roles

Prompts return an array of messages with different roles:

Assistant Role

Sets the context and instructions for the AI:

User Role

Provides the actual query or request:

System Role

Provides high-level instructions (supported by some models):

Using Prompts from Clients

Getting a Prompt

From source/clients/basic-ts/src/index.ts:42-51 and source/clients/basic-py/main.py:23-31:

Listing Available Prompts

Using Prompt Messages with AI Models

Prompt Response Format

Prompts return a structured response:

Real-World Prompt Examples

Code Review Prompt

Structured code analysis with best practices:

Analysis with Dynamic Data

Fetching external data to include in the prompt:

Multi-Step Conversation Starter

Advanced Patterns

Prompts with Resource Data

Combine prompts with resource data:

Contextual Prompts

Include system information or configuration:

Best Practices

Make assistant messages clear and specific:
Allow customization through parameters:
Always validate and handle missing required parameters:
Use multiple messages to set up complex interactions:
Fetch and include data that helps the AI provide better responses:

Prompts vs Tools vs Resources

Use Prompts For

  • Conversation starters
  • Analysis workflows
  • AI instructions
  • Templated queries

Use Tools For

  • Actions
  • Calculations
  • Side effects
  • Computations

Use Resources For

  • Read-only data
  • Context information
  • Files/documents
  • Static content

Testing Prompts

Test your prompts with different parameters:
Test your prompts with various parameter combinations to ensure they generate appropriate messages for all use cases.

Next Steps

Tools

Learn how to implement executable tools

Resources

Discover how to provide data through resources

Servers

Build complete MCP servers with all capabilities

Clients

Create clients that use prompts effectively