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;
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It describes the transformation behavior and template support, but lacks details on output format, potential limitations (e.g., length constraints), error handling, or performance characteristics. It provides some context about workspace alignment but doesn't fully compensate for the missing annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections: purpose statement, usage bullet points, template list, and important note. It's appropriately sized for a 5-parameter tool, though the template list could be more concise. Every sentence adds value, but minor trimming is possible.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 5-parameter tool with no annotations and no output schema, the description provides good purpose and usage context but lacks details about the transformation output, error cases, or behavioral constraints. It's adequate for basic understanding but leaves gaps about what the tool actually produces.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are well-documented in the schema. The description adds minimal value beyond the schema: it mentions template types and workspace context importance, but doesn't explain parameter interactions or provide additional semantic context. Baseline 3 is appropriate given the comprehensive schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Transform a raw idea into a well-structured, actionable prompt optimized for AI assistants.' It uses specific verbs ('transform', 'optimize') and distinguishes from sibling tools like 'analyze_prompt' and 'refine_prompt' by focusing on creation from scratch rather than analysis or refinement.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit usage scenarios: 'Create a new prompt from scratch', 'Structure a vague idea into a clear request', and 'Generate role-specific prompts'. It also implicitly distinguishes from siblings by not mentioning analysis or refinement, and includes an 'IMPORTANT' note about when to provide workspace context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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