Skip to main content
Glama

generate_prompt

Transform raw ideas into structured prompts for AI assistants using templates like coding, writing, and research. Optimizes prompts with project context for better results.

Instructions

Transform a raw idea into a well-structured, actionable prompt optimized for AI assistants.

Use this tool when you need to: • Create a new prompt from scratch • Structure a vague idea into a clear request • Generate role-specific prompts (coding, writing, research, etc.)

Supports templates: coding (for programming tasks), writing (for content creation), research (for investigation), analysis (for data/business analysis), factcheck (for verification), general (versatile).

IMPORTANT: When available, pass workspace context (file structure, package.json, tech stack) to generate prompts that align with the user's project.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ideaYesThe raw idea or concept to transform into a prompt. Can be brief or detailed.
templateNoTemplate type to use. Default: auto-detected from idea or "general".
contextNoAdditional context like domain, constraints, or preferences.
targetModelNoTarget AI model for optimization. Default: "general".
workspaceContextNoProject context to ensure the prompt aligns with the codebase. Include: file/folder structure, package.json dependencies, tech stack (React, Node, etc.), relevant code snippets, and the original user request. This helps generate prompts that comply with project conventions.

Implementation Reference

  • Core handler function that implements the generate_prompt tool logic. Attempts to use the PromptArchitect API first, falls back to local template generation, and computes metadata.
    export async function generatePrompt(input: GeneratePromptInput): Promise<{ prompt: string; template: string; metadata: { estimatedTokens: number; wordCount: number; hasStructure: boolean; }; }> { const { idea, template = 'general', context, targetModel, workspaceContext } = input; logger.info('Generating prompt', { template, targetModel, ideaLength: idea.length, hasWorkspaceContext: !!workspaceContext }); let generatedPrompt: string = ''; // Use PromptArchitect API if (isApiClientAvailable()) { try { const response = await apiGeneratePrompt({ idea, template, context, targetModel, workspaceContext, }); generatedPrompt = response.prompt; logger.info('Generated via PromptArchitect API'); } catch (error) { logger.warn('API request failed, using fallback', { error: error instanceof Error ? error.message : 'Unknown error' }); } } // Fallback template generation if (!generatedPrompt) { generatedPrompt = createFallbackPrompt(idea, template, context); logger.warn('Using fallback prompt generation'); } // Calculate metadata const wordCount = generatedPrompt.split(/\s+/).length; const estimatedTokens = Math.ceil(wordCount * 1.3); // Rough estimate const hasStructure = /^#+\s|^\d+\.|^-\s|^\*\s/m.test(generatedPrompt); return { prompt: generatedPrompt, template, metadata: { estimatedTokens, wordCount, hasStructure, }, }; }
  • Zod schema defining the input parameters for the generate_prompt tool, used for validation.
    export const generatePromptSchema = z.object({ idea: z.string().min(1).describe('The user\'s raw prompt idea or concept'), template: z.enum(['coding', 'writing', 'research', 'analysis', 'factcheck', 'general']) .optional() .default('general') .describe('Template type to use for generation'), context: z.string().optional().describe('Additional context or constraints'), targetModel: z.enum(['gpt-4', 'claude', 'gemini', 'general']) .optional() .default('general') .describe('Target AI model to optimize for'), workspaceContext: z.string().optional().describe('Project context including file structure, tech stack, dependencies, and any relevant code snippets to ensure the generated prompt aligns with the project scope'), });
  • src/server.ts:207-218 (registration)
    MCP server handler for incoming generate_prompt tool calls: parses arguments with schema and invokes the generatePrompt handler.
    case 'generate_prompt': { const input = generatePromptSchema.parse(args); const result = await generatePrompt(input); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
  • src/server.ts:73-113 (registration)
    Tool metadata registration in ListTools response, defining name 'generate_prompt', description, and input schema for MCP discovery.
    { name: 'generate_prompt', description: `Transform a raw idea into a well-structured, actionable prompt optimized for AI assistants. Use this tool when you need to: • Create a new prompt from scratch • Structure a vague idea into a clear request • Generate role-specific prompts (coding, writing, research, etc.) Supports templates: coding (for programming tasks), writing (for content creation), research (for investigation), analysis (for data/business analysis), factcheck (for verification), general (versatile). IMPORTANT: When available, pass workspace context (file structure, package.json, tech stack) to generate prompts that align with the user's project.`, inputSchema: { type: 'object', properties: { idea: { type: 'string', description: 'The raw idea or concept to transform into a prompt. Can be brief or detailed.', }, template: { type: 'string', enum: ['coding', 'writing', 'research', 'analysis', 'factcheck', 'general'], description: 'Template type to use. Default: auto-detected from idea or "general".', }, context: { type: 'string', description: 'Additional context like domain, constraints, or preferences.', }, targetModel: { type: 'string', enum: ['gpt-4', 'claude', 'gemini', 'general'], description: 'Target AI model for optimization. Default: "general".', }, workspaceContext: { type: 'string', description: 'Project context to ensure the prompt aligns with the codebase. Include: file/folder structure, package.json dependencies, tech stack (React, Node, etc.), relevant code snippets, and the original user request. This helps generate prompts that comply with project conventions.', }, }, required: ['idea'], }, },
  • Helper function that makes HTTP request to PromptArchitect backend API for primary prompt generation logic (used by handler).
    export async function apiGeneratePrompt(params: { idea: string; template?: string; context?: string; targetModel?: string; workspaceContext?: string; }): Promise<GenerateResponse> { logger.info('Generating prompt via API', { template: params.template, ideaLength: params.idea.length, hasWorkspaceContext: !!params.workspaceContext }); const response = await apiRequest<GenerateResponse>('/generate', { idea: params.idea, template: params.template || 'general', context: params.context, targetModel: params.targetModel || 'gemini', workspaceContext: params.workspaceContext, }); return response; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MerabyLabs/promptarchitect-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server