/**
* MCP Prompts
*
* Prompts are reusable templates that can be invoked by AI assistants.
* They help structure conversations and provide consistent guidance.
*/
export interface PromptDefinition {
name: string;
description: string;
arguments?: Array<{
name: string;
description: string;
required: boolean;
}>;
}
export interface PromptMessage {
role: 'user' | 'assistant' | 'system';
content: {
type: 'text';
text: string;
};
}
/**
* List of all available prompts
*/
export const PROMPTS: PromptDefinition[] = [
{
name: 'code_review',
description: 'Perform a code review with specific focus areas',
arguments: [
{
name: 'code',
description: 'The code to review',
required: true,
},
{
name: 'focus',
description: 'Specific areas to focus on (e.g., security, performance, readability)',
required: false,
},
],
},
{
name: 'explain_concept',
description: 'Get a detailed explanation of a technical concept',
arguments: [
{
name: 'concept',
description: 'The concept to explain',
required: true,
},
{
name: 'level',
description: 'Explanation level: beginner, intermediate, or advanced',
required: false,
},
],
},
{
name: 'debug_helper',
description: 'Get help debugging an issue',
arguments: [
{
name: 'error',
description: 'The error message or description',
required: true,
},
{
name: 'context',
description: 'Additional context about when the error occurs',
required: false,
},
],
},
{
name: 'api_design',
description: 'Get guidance on API design best practices',
arguments: [
{
name: 'api_description',
description: 'Description of the API you want to design',
required: true,
},
{
name: 'type',
description: 'API type: REST, GraphQL, gRPC, or WebSocket',
required: false,
},
],
},
{
name: 'refactor_suggestion',
description: 'Get suggestions for refactoring code',
arguments: [
{
name: 'code',
description: 'The code to refactor',
required: true,
},
{
name: 'goal',
description: 'Refactoring goal (e.g., readability, performance, testability)',
required: false,
},
],
},
];
/**
* Generate a prompt based on the prompt name and arguments
*/
export function generatePrompt(
name: string,
args?: Record<string, string>
): { messages: PromptMessage[] } {
switch (name) {
case 'code_review':
const code = args?.code || '';
const focus = args?.focus || 'general best practices';
return {
messages: [
{
role: 'user',
content: {
type: 'text',
text: `Please review the following code with focus on ${focus}:
${code}
Provide feedback on:
- Code quality and maintainability
- Potential bugs or issues
- Performance considerations
- Security concerns
- Best practices and conventions
- Suggestions for improvement`,
},
},
],
};
case 'explain_concept':
const concept = args?.concept || '';
const level = args?.level || 'intermediate';
return {
messages: [
{
role: 'user',
content: {
type: 'text',
text: `Explain the concept of "${concept}" at a ${level} level.
Please include:
- Clear definition
- Key principles and fundamentals
- Practical examples
- Common use cases
- Related concepts
- Additional resources for learning`,
},
},
],
};
case 'debug_helper':
const error = args?.error || '';
const context = args?.context || 'not provided';
return {
messages: [
{
role: 'user',
content: {
type: 'text',
text: `Help me debug this issue:
Error: ${error}
Context: ${context}
Please provide:
- Likely root causes of this error
- Step-by-step debugging approach
- Potential solutions
- Code examples if applicable
- Prevention strategies for the future`,
},
},
],
};
case 'api_design':
const apiDescription = args?.api_description || '';
const apiType = args?.type || 'REST';
return {
messages: [
{
role: 'user',
content: {
type: 'text',
text: `Design a ${apiType} API for: ${apiDescription}
Please provide:
- Recommended endpoint structure
- Data models/schemas
- Authentication and authorization approach
- Best practices for this API type
- Example requests and responses
- Error handling strategy
- Versioning strategy`,
},
},
],
};
case 'refactor_suggestion':
const refactorCode = args?.code || '';
const goal = args?.goal || 'overall code quality';
return {
messages: [
{
role: 'user',
content: {
type: 'text',
text: `Suggest refactoring improvements for the following code with focus on ${goal}:
${refactorCode}
Please provide:
- Specific refactoring recommendations
- Improved code examples
- Explanation of benefits
- Trade-offs to consider
- Testing strategies for the refactored code`,
},
},
],
};
default:
throw new Error(`Unknown prompt: ${name}`);
}
}