Skip to main content
Glama
lumile

Promptopia MCP

by lumile

apply_prompt

Apply specified variables to a template prompt to generate tailored results. Use this tool by providing the prompt ID and variable values for customizable outputs.

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

  • Registration of the 'apply_prompt' tool in listTools(), including name, description, and input schema definition.
    { 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'] } },
  • Tool handler logic in callTool(): extracts parameters, calls PromptsService.applyPrompt(), formats and returns the MCP response.
    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) }] }
  • Main implementation logic: loads prompt by ID, validates provided variables against required ones, replaces variables in single content or multi-message prompts using replaceVariables helper, returns applied 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 } }
  • TypeScript interfaces defining input parameters (ApplyPromptParams) and output result (ApplyPromptResult) for the applyPrompt function.
    export interface ApplyPromptParams { id: string variables: Record<string, string> } export interface ApplyPromptResult { result: string messages?: PromptMessage[] // For multi-message prompts }

Other Tools

Related 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