Prompts
Prompts are user-driven templates that provide shortcuts and working examples for AI interactions. They help users get started quickly without figuring out the right way to phrase requests.
How Prompts Work
Prompts can be consumed in two ways, depending on how the client is built:
| Mode | Who Triggers | How It Works |
|---|
| User-Invoked | User explicitly selects | Slash commands (/analyze), dropdown menus, keyboard shortcuts |
| Agent-Selected | AI agent picks automatically | Agent browses available prompts and selects the best one for the task |
Client Implementation Matters: Whether prompts are user-invoked or agent-selected depends entirely on how the client application is developed. Some clients expose prompts as slash commands, others let the AI agent discover and use them automatically.
When to Use Prompts
- Provide examples of how to use your MCP server effectively
- Create shortcuts for common workflows users perform repeatedly
- Include dynamic context that would be tedious to type manually
- Onboard new users with working examples they can invoke immediately
Basic Prompt
import { Prompt } from "@leanmcp/core";
export class PromptService {
@Prompt({ description: "Customer support assistant" })
supportAssistant() {
return {
messages: [{
role: "user",
content: {
type: "text",
text: "You are a helpful customer support agent. Be polite and helpful."
}
}]
};
}
}
Prompt with Arguments
import { Prompt, SchemaConstraint } from "@leanmcp/core";
class CodeReviewInput {
@SchemaConstraint({ description: "Code to review" })
code!: string;
@SchemaConstraint({ description: "Programming language" })
language!: string;
}
export class CodeService {
@Prompt({ description: "Generate code review prompt" })
codeReview(input: CodeReviewInput) {
return {
messages: [{
role: "user",
content: {
type: "text",
text: `Review this ${input.language} code for bugs, style, and best practices:\n\n${input.code}`
}
}]
};
}
}
Multi-message Prompt
Set up a conversation with context:
@Prompt({ description: "Code review conversation" })
codeReviewer() {
return {
messages: [
{
role: "user",
content: { type: "text", text: "You are a senior code reviewer." }
},
{
role: "assistant",
content: { type: "text", text: "I'll review the code for bugs, style, and best practices." }
}
]
};
}
Specialized Prompts
@Prompt({ description: "SQL query generator" })
sqlHelper(input: { schema: string }) {
return {
messages: [{
role: "user",
content: {
type: "text",
text: `You are a SQL expert. Generate queries for this schema:\n\n${input.schema}`
}
}]
};
}
@Prompt({ description: "API documentation writer" })
apiDocWriter() {
return {
messages: [{
role: "user",
content: {
type: "text",
text: "You write clear, concise API documentation with examples."
}
}]
};
}
The Three MCP Primitives
Understanding when to use each:
| Primitive | Control | Purpose | Example |
|---|
| Tools | Model-driven | Actions the AI performs | Send email, create task, query API |
| Resources | Application-driven | Context data for AI | Files, preferences, schedules |
| Prompts | User-driven | Templates users invoke | /analyze, /review, /support |
Next Steps