Skip to main content
Glama
RadonX

MCP TriliumNext

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';
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states it updates content without disclosing behavioral traits like permission requirements, whether the update overwrites or merges content, error handling, or rate limits. This is inadequate for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste, front-loading the key action and resource. It's appropriately sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a mutation tool with two parameters, the description is incomplete. It lacks details on behavior, return values, or error cases, making it insufficient for reliable agent use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters ('noteId' and 'content') adequately. The description adds no additional meaning beyond implying the tool uses these parameters, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Update') and resource ('the content of an existing note'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'create_note' or 'get_note' beyond the basic verb, which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'create_note' or 'get_note'. It lacks context about prerequisites (e.g., needing an existing note ID) or exclusions, leaving usage unclear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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