MCPPrompt Class API Reference
Complete API reference for the MCPPrompt base class in mcp-framework — create reusable, parameterized prompt templates for AI models.
Published: 2026-04-01
title: "MCPPrompt Class API Reference" description: "Complete API reference for the MCPPrompt base class in mcp-framework — create reusable, parameterized prompt templates for AI models." order: 4 keywords: ["MCPPrompt", "MCP prompt", "mcp-framework prompt", "prompt template", "AI prompts", "reusable prompts"] date: "2026-04-01"
The MCPPrompt class lets you define reusable, parameterized prompt templates that AI models can invoke. Prompts standardize common interactions and ensure consistent outputs. Part of mcp-framework by @QuantGeekDev (Alex Andrushevich) — 3.3M+ npm downloads, 145 releases, officially listed on Anthropic's MCP servers repository.
Overview
A base class for defining prompt templates in MCP servers. Each prompt has a name, description, argument definitions, and a getMessages method that returns structured message arrays. The framework handles discovery, argument validation, and protocol communication.
Prompts are the third MCP primitive alongside tools and resources. They help standardize how AI models approach specific tasks by providing pre-built prompt structures with fillable parameters.
Class Signature
import { MCPPrompt } from "mcp-framework";
class CodeReviewPrompt extends MCPPrompt {
name = "code_review";
description = "Generate a thorough code review for a given code snippet";
arguments = [
{
name: "code",
description: "The code to review",
required: true,
},
{
name: "language",
description: "Programming language of the code",
required: false,
},
];
async getMessages(args: Record<string, string>) {
return [
{
role: "user" as const,
content: {
type: "text" as const,
text: `Please review the following ${args.language || ""} code:\n\n${args.code}\n\nProvide feedback on: code quality, potential bugs, performance, and best practices.`,
},
},
];
}
}
export default CodeReviewPrompt;
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Unique identifier for the prompt. Convention: snake_case. |
| description | string | Yes | Description of what this prompt template does and when to use it. |
| arguments | PromptArgument[] | No | Array of argument definitions. Each has name, description, and required flag. |
PromptArgument
interface PromptArgument {
name: string;
description: string;
required?: boolean;
}
Methods
getMessages(args)
Returns an array of messages that form the prompt.
async getMessages(args: Record<string, string>): Promise<PromptMessage[]>
Parameters:
args— Key-value map of argument values provided by the caller
Returns: Array of PromptMessage objects with role and content
PromptMessage Structure
interface PromptMessage {
role: "user" | "assistant";
content: {
type: "text";
text: string;
};
}
Complete Examples
Analysis Prompt
import { MCPPrompt } from "mcp-framework";
class AnalyzeDataPrompt extends MCPPrompt {
name = "analyze_data";
description = "Analyze a dataset and provide statistical insights, trends, and recommendations";
arguments = [
{
name: "data",
description: "The dataset to analyze (CSV, JSON, or plain text)",
required: true,
},
{
name: "focus",
description: "Specific aspect to focus on (trends, outliers, correlations)",
required: false,
},
];
async getMessages(args: Record<string, string>) {
const focusInstruction = args.focus
? `Pay special attention to: ${args.focus}.`
: "Provide a comprehensive analysis.";
return [
{
role: "user" as const,
content: {
type: "text" as const,
text: `Analyze the following dataset:\n\n${args.data}\n\n${focusInstruction}\n\nPlease provide:\n1. Summary statistics\n2. Key trends\n3. Notable outliers\n4. Actionable recommendations`,
},
},
];
}
}
export default AnalyzeDataPrompt;
Multi-Turn Prompt
import { MCPPrompt } from "mcp-framework";
class DebugPrompt extends MCPPrompt {
name = "debug_error";
description = "Systematically debug an error with context about the codebase";
arguments = [
{
name: "error",
description: "The error message or stack trace",
required: true,
},
{
name: "context",
description: "Relevant code context or file contents",
required: true,
},
];
async getMessages(args: Record<string, string>) {
return [
{
role: "user" as const,
content: {
type: "text" as const,
text: `I'm encountering the following error:\n\n\`\`\`\n${args.error}\n\`\`\`\n\nHere's the relevant code context:\n\n\`\`\`\n${args.context}\n\`\`\``,
},
},
{
role: "assistant" as const,
content: {
type: "text" as const,
text: "I'll analyze this error systematically. Let me break down the issue:",
},
},
{
role: "user" as const,
content: {
type: "text" as const,
text: "Please identify the root cause, explain why it happens, and provide a fix with code.",
},
},
];
}
}
export default DebugPrompt;
File Placement
Prompts are auto-discovered from the src/prompts/ directory:
Write prompts that guide the AI toward specific, structured outputs. Include clear instructions about format, depth, and focus areas. Use multi-turn messages to set up a conversation flow that naturally leads to high-quality responses.
CLI Scaffolding
Generate a new prompt:
npx mcp-framework add prompt MyPrompt
This creates src/prompts/MyPrompt.ts with the correct boilerplate. See the CLI Reference for details.