update_note
Modify the content of a specific note in TriliumNext by providing the note ID and new content, ensuring your knowledge base stays current and accurate.
Instructions
Update the content of an existing note
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | The new content for the note (max 1MB) | |
| noteId | Yes | The ID of the note to update |
Implementation Reference
- src/tools/update-note.js:5-163 (handler)Core implementation of the update_note tool handler. Validates inputs, checks note existence, updates content using Trilium API, logs actions, handles various errors with structured JSON responses, and returns confirmation.export async function updateNote(triliumClient, args) { try { // Validate inputs const noteId = validators.noteId(args.noteId); const content = validators.content(args.content); logger.debug(`Updating note: noteId="${noteId}"`); // First, check if the note exists by getting its metadata try { const note = await triliumClient.get(`notes/${noteId}`); if (!note) { throw new TriliumAPIError('Note not found', 404); } logger.debug(`Note exists: ${note.title || 'Untitled'}`); } catch (error) { if (error instanceof TriliumAPIError && error.status === 404) { throw new TriliumAPIError('Note not found', 404); } throw error; } // Update the note content via TriliumNext API // TriliumNext API expects raw content string, not JSON object await triliumClient.putRaw(`notes/${noteId}/content`, content); logger.info(`Note content updated successfully: ${noteId}`); // Get updated note info for confirmation const updatedNote = await triliumClient.get(`notes/${noteId}`); // Prepare structured response data const updateData = { operation: 'update_note', timestamp: new Date().toISOString(), request: { noteId, contentLength: content.length }, result: { noteId, title: updatedNote.title || 'Untitled', type: updatedNote.type || 'text', dateModified: updatedNote.dateModified, contentLength: content.length, ...updatedNote, // Include any additional data from API response triliumUrl: `trilium://note/${noteId}` } }; return { content: [ { type: 'text', text: `Note updated: "${updatedNote.title || 'Untitled'}" (ID: ${noteId})` }, { type: 'application/json', text: JSON.stringify(updateData, null, 2) } ], }; } catch (error) { logger.error(`Failed to update note: ${error.message}`); // Create structured error response const errorData = { operation: 'update_note', timestamp: new Date().toISOString(), request: { noteId: args.noteId, contentLength: args.content?.length }, error: { type: error.constructor.name, message: error.message, ...(error instanceof TriliumAPIError && { status: error.status }), ...(error instanceof TriliumAPIError && error.details && { details: error.details }) } }; if (error instanceof ValidationError) { return { content: [ { type: 'text', text: `Validation error: ${error.message}` }, { type: 'application/json', text: JSON.stringify(errorData, null, 2) } ], isError: true, }; } if (error instanceof TriliumAPIError) { if (error.status === 404) { return { content: [ { type: 'text', text: `Note not found: ${args.noteId}` }, { type: 'application/json', text: JSON.stringify(errorData, null, 2) } ], isError: true, }; } else if (error.status === 403) { return { content: [ { type: 'text', text: `Access denied: Cannot update note ${args.noteId}` }, { type: 'application/json', text: JSON.stringify(errorData, null, 2) } ], isError: true, }; } return { content: [ { type: 'text', text: `TriliumNext API error: ${error.message}` }, { type: 'application/json', text: JSON.stringify(errorData, null, 2) } ], isError: true, }; } // Unknown error return { content: [ { type: 'text', text: `Failed to update note: ${error.message}` }, { type: 'application/json', text: JSON.stringify(errorData, null, 2) } ], isError: true, }; } }
- src/index.js:120-133 (schema)JSON Schema defining the input parameters for the update_note tool: noteId (string, required) and content (string, required). Used in ListTools response.inputSchema: { type: 'object', properties: { noteId: { type: 'string', description: 'The ID of the note to update', }, content: { type: 'string', description: 'The new content for the note (max 1MB)', }, }, required: ['noteId', 'content'], },
- src/index.js:150-151 (registration)Registration/dispatch in the CallToolRequestSchema switch statement that invokes the tool handler.case 'update_note': return await this.updateNote(request.params.arguments);
- src/index.js:213-215 (registration)Wrapper method in the MCP server class that delegates to the tool's exported handler function, injecting the triliumClient instance.async updateNote(args) { return await updateNote(this.triliumClient, args); }
- src/tools/update-note.js:8-9 (helper)Input validation using shared validators for noteId and content.const noteId = validators.noteId(args.noteId); const content = validators.content(args.content);