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
Prompt Structure
Every MCP prompt consists of:- Name - Unique identifier for the prompt
- Parameters - Input schema for customization (optional)
- Handler - Generates the prompt messages
- Messages - Array of message objects with roles and content
Defining Prompts in TypeScript
Basic Prompt
Fromsource/servers/basic/src/server.ts:259-294:
Prompt with Optional Parameters
Fromsource/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
Fromsource/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
Provide Clear Instructions
Provide Clear Instructions
Make assistant messages clear and specific:
Use Parameters for Flexibility
Use Parameters for Flexibility
Allow customization through parameters:
Validate Parameters
Validate Parameters
Always validate and handle missing required parameters:
Structure Multi-Turn Conversations
Structure Multi-Turn Conversations
Use multiple messages to set up complex interactions:
Include Relevant Context
Include Relevant Context
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: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