Skip to main content
Glama
lumile

Promptopia MCP

by lumile

update_prompt

Modify existing prompts in Promptopia MCP by updating names, descriptions, or message content, including converting single content to multi-message formats.

Instructions

Updates an existing prompt (supports both single content and multi-message formats)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesID of the prompt to update
nameNoNew name for the prompt
descriptionNoNew description for the prompt
messagesNoNew messages (converts single content to multi-message format)

Implementation Reference

  • Registration of the 'update_prompt' tool including name, description, and input schema definition.
    {
      name: 'update_prompt',
      description: 'Updates an existing prompt (supports both single content and multi-message formats)',
      inputSchema: {
        type: 'object',
        properties: {
          id: {
            type: 'string',
            description: 'ID of the prompt to update'
          },
          name: {
            type: 'string',
            description: 'New name for the prompt'
          },
          description: {
            type: 'string',
            description: 'New description for the prompt'
          },
          messages: {
            type: 'array',
            description: 'New messages (converts single content to multi-message format)',
            items: {
              type: 'object',
              properties: {
                role: {
                  type: 'string',
                  enum: ['user', 'assistant'],
                  description: 'Role of the message sender'
                },
                content: {
                  type: 'object',
                  properties: {
                    type: {
                      type: 'string',
                      enum: ['text', 'image'],
                      description: 'Type of content'
                    },
                    text: {
                      type: 'string',
                      description: 'Text content (required for text type)'
                    },
                    image: {
                      type: 'string',
                      description: 'Image data (required for image type)'
                    }
                  },
                  required: ['type']
                }
              },
              required: ['role', 'content']
            }
          }
        },
        required: ['id']
      }
    },
  • MCP tool handler implementation for 'update_prompt': extracts parameters, calls PromptsService.updatePrompt, and formats response.
    case 'update_prompt': {
      const { id, name, description, messages } = args
      const result = await this.promptsService.updatePrompt({ id, name, description, messages })
      return {
        content: [{
          type: 'text',
          text: JSON.stringify(result, null, 2)
        }]
      }
    }
  • Core logic for updating a prompt: validates input, loads existing prompt, applies updates or converts format, persists to filesystem.
    async updatePrompt(params: UpdatePromptParams): Promise<UpdatePromptResult> {
      if (!params.id || !params.id.trim()) {
        throw new ValidationError('Prompt ID is required')
      }
    
      // At least one field to update must be provided
      if (!params.name && !params.description && !params.messages) {
        throw new ValidationError('At least one field to update must be provided')
      }
    
      try {
        // First get the existing prompt
        const existingPrompt = await this.getPrompt(params.id)
        
        let updatedPrompt: Prompt
    
        if (isMultiMessagePrompt(existingPrompt)) {
          // Update existing multi-message prompt
          updatedPrompt = {
            ...existingPrompt,
            ...(params.name && { name: params.name.trim() }),
            ...(params.description !== undefined && { description: params.description.trim() || '' }),
            ...(params.messages && {
              messages: params.messages,
              variables: this.extractVariablesFromMessages(params.messages)
            }),
            updatedAt: new Date().toISOString()
          }
        } else {
          // Convert single content prompt to multi-message if messages are provided
          if (params.messages) {
            updatedPrompt = {
              id: existingPrompt.id,
              name: params.name?.trim() || existingPrompt.name,
              description: params.description !== undefined ? (params.description.trim() || '') : existingPrompt.description,
              variables: this.extractVariablesFromMessages(params.messages),
              createdAt: existingPrompt.createdAt,
              updatedAt: new Date().toISOString(),
              version: '2.0',
              messages: params.messages
            }
          } else {
            // Keep as single content format
            updatedPrompt = {
              ...existingPrompt,
              ...(params.name && { name: params.name.trim() }),
              ...(params.description !== undefined && { description: params.description.trim() || '' }),
              updatedAt: new Date().toISOString()
            }
          }
        }
        
        // Save the updated prompt
        const filePath = path.join(this.promptsDir, `${params.id}.json`)
        await this.fileSystemService.writeJSONFile(filePath, updatedPrompt)
        
        return {
          success: true,
          message: `Prompt ${params.id} updated successfully`,
          prompt: updatedPrompt
        }
      } catch (error) {
        if (error instanceof Error && error.message.includes('not found')) {
          throw new NotFoundError(`Prompt not found: ${params.id}`)
        }
        console.error('Failed to update prompt:', error)
        throw error
      }
    }
  • TypeScript interface defining input parameters for updatePrompt.
    export interface UpdatePromptParams {
      id: string
      name?: string
      description?: string
      messages?: PromptMessage[]
    }
  • TypeScript interface defining return type for updatePrompt.
    export interface UpdatePromptResult {
      success: boolean
      message: string
      prompt: Prompt
    }

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