Skip to main content

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:
ModeWho TriggersHow It Works
User-InvokedUser explicitly selectsSlash commands (/analyze), dropdown menus, keyboard shortcuts
Agent-SelectedAI agent picks automaticallyAgent 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:
PrimitiveControlPurposeExample
ToolsModel-drivenActions the AI performsSend email, create task, query API
ResourcesApplication-drivenContext data for AIFiles, preferences, schedules
PromptsUser-drivenTemplates users invoke/analyze, /review, /support

Next Steps