update_prompt
Modify existing prompts by updating their name, description, or messages, converting single content to multi-message format when needed. Ensures prompt content remains accurate and adaptable.
Instructions
Updates an existing prompt (supports both single content and multi-message formats)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | No | New description for the prompt | |
| id | Yes | ID of the prompt to update | |
| messages | No | New messages (converts single content to multi-message format) | |
| name | No | New name for the prompt |
Implementation Reference
- src/services/prompts.service.ts:200-268 (handler)Core implementation of the update_prompt tool logic: validates parameters, retrieves existing prompt, merges updates, handles conversion between single-content and multi-message formats, extracts variables, and persists changes to the 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 } }
- src/handlers/tools.handler.ts:217-226 (handler)MCP tool handler for 'update_prompt': extracts arguments, calls PromptsService.updatePrompt, and returns JSON-formatted result as MCP content.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) }] } }
- src/handlers/tools.handler.ts:37-92 (registration)Registers the 'update_prompt' tool in listTools() with detailed inputSchema matching UpdatePromptParams.{ 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'] } },
- src/types/index.ts:62-67 (schema)TypeScript interface defining input parameters for updatePrompt.export interface UpdatePromptParams { id: string name?: string description?: string messages?: PromptMessage[] }
- src/types/index.ts:84-88 (schema)TypeScript interface defining output result for updatePrompt.export interface UpdatePromptResult { success: boolean message: string prompt: Prompt }