Skip to main content
Glama
lumile

Promptopia MCP

by lumile

apply_prompt

Apply variables to template prompts to generate customized content for various use cases.

Instructions

Applies variables to a template prompt and returns the result

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesID of the prompt to apply
variablesYesObject containing variable names and their values

Implementation Reference

  • Core handler function that implements the apply_prompt tool logic: validates input, loads prompt, checks and replaces variables in single-content or multi-message prompts, returns formatted result.
    async applyPrompt(params: ApplyPromptParams): Promise<ApplyPromptResult> {
      if (!params.id || !params.id.trim()) {
        throw new ValidationError('Prompt ID is required')
      }
    
      if (!params.variables || typeof params.variables !== 'object') {
        throw new ValidationError('Variables must be provided as an object')
      }
    
      try {
        const prompt = await this.getPrompt(params.id)
        
        // Check if all required variables are provided
        const missingVariables = prompt.variables.filter(
          variable => !(variable in params.variables)
        )
        
        if (missingVariables.length > 0) {
          throw new ValidationError(
            `Missing required variables: ${missingVariables.join(', ')}`
          )
        }
        
        if (isMultiMessagePrompt(prompt)) {
          // Handle multi-message prompts
          const appliedMessages = prompt.messages.map(message => ({
            ...message,
            content: {
              ...message.content,
              ...(message.content.type === 'text' && message.content.text && {
                text: this.replaceVariables(message.content.text, params.variables)
              })
            }
          }))
    
          return {
            result: JSON.stringify(appliedMessages, null, 2),
            messages: appliedMessages
          }
        } else {
          // Handle single content prompts
          const result = this.replaceVariables(prompt.content, params.variables)
          return { result }
        }
      } catch (error) {
        console.error('Failed to apply prompt:', error)
        throw error
      }
    }
  • MCP tool dispatch handler for 'apply_prompt': extracts args, calls PromptsService.applyPrompt, formats response as MCP content.
    case 'apply_prompt': {
      const { id, variables } = args
      const result = await this.promptsService.applyPrompt({ id, variables })
      return {
        content: [{
          type: 'text',
          text: typeof result.result === 'string'
            ? result.result
            : JSON.stringify(result, null, 2)
        }]
      }
    }
  • Tool registration in listTools(): defines name, description, and inputSchema for 'apply_prompt'.
      name: 'apply_prompt',
      description: 'Applies variables to a template prompt and returns the result',
      inputSchema: {
        type: 'object',
        properties: {
          id: {
            type: 'string',
            description: 'ID of the prompt to apply'
          },
          variables: {
            type: 'object',
            description: 'Object containing variable names and their values'
          }
        },
        required: ['id', 'variables']
      }
    },
  • Type definitions for ApplyPromptParams (input) and ApplyPromptResult (output) used by the tool.
    export interface ApplyPromptParams {
      id: string
      variables: Record<string, string>
    }
    
    export interface ApplyPromptResult {
      result: string
      messages?: PromptMessage[] // For multi-message prompts
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool applies variables and returns a result, but doesn't explain critical behaviors like whether this is a read-only operation, if it modifies data, authentication needs, error handling, or rate limits. For a tool with no annotations, this leaves significant gaps in understanding how it behaves.

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

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's function without any wasted words. It's appropriately sized and front-loaded, making it easy to grasp quickly.

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

Completeness2/5

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

Given the complexity (2 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain what the 'result' looks like (e.g., text output, structured data), potential side effects, or how it relates to sibling tools. For a tool that likely involves prompt execution, more context is needed to guide effective use.

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?

The schema description coverage is 100%, so the schema already documents both parameters ('id' and 'variables') with descriptions. The description adds no additional meaning beyond what the schema provides, such as examples of variable usage or format details. Baseline 3 is appropriate when the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the action ('applies variables to a template prompt') and the outcome ('returns the result'), which is specific and understandable. However, it doesn't explicitly differentiate this tool from its siblings like 'add_prompt' or 'update_prompt', which would require mentioning it's for executing/rendering prompts rather than managing them.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'add_prompt', 'get_prompt', and 'update_prompt', it's unclear if this is for testing prompts, generating outputs, or another purpose. No context, exclusions, or prerequisites are mentioned.

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/lumile/promptopia-mcp'

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