Skip to main content
Glama
RadonX
by RadonX

update_note

Modify existing note content in your TriliumNext knowledge base by specifying the note ID and providing new text.

Instructions

Update the content of an existing note

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
noteIdYesThe ID of the note to update
contentYesThe new content for the note (max 1MB)

Implementation Reference

  • The core handler function `updateNote(triliumClient, args)` that implements the tool logic: validates inputs using noteId and content validators, verifies note existence, updates note content via Trilium API putRaw, retrieves updated note details, constructs and returns MCP-compliant response content (text summary + JSON details), handles various errors with structured JSON responses.
    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:117-134 (registration)
    Registers the 'update_note' tool in the ListToolsRequestSchema response, including name, description, and inputSchema defining required properties: noteId (string) and content (string, max 1MB).
    { name: 'update_note', description: 'Update the content of an existing note', 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:213-215 (registration)
    Wrapper method `updateNote(args)` in TriliumMCPServer class that delegates the tool execution to the imported `updateNote` function from './tools/update-note.js', passing the triliumClient.
    async updateNote(args) { return await updateNote(this.triliumClient, args); }
  • src/index.js:150-151 (registration)
    Dispatch case in CallToolRequestSchema handler: matches 'update_note' and invokes the class's updateNote method with arguments.
    case 'update_note': return await this.updateNote(request.params.arguments);
  • Import statement for the updateNote handler from './tools/update-note.js'.
    import { updateNote } from './tools/update-note.js';

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/RadonX/mcp-trilium'

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