Skip to main content
Glama
RadonX

MCP TriliumNext

by RadonX

create_note

Add new notes to your TriliumNext knowledge base with specified titles, content, and organizational structure for information management.

Instructions

Create a new note in TriliumNext

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesThe title of the note (max 200 characters)
contentYesThe content of the note (max 1MB)
typeNoThe type of note to createtext
parentNoteIdNoID of the parent note (defaults to "root" if not provided)

Implementation Reference

  • The primary handler function that executes the create_note tool logic: validates inputs, interacts with TriliumNext API to create a note, formats success/error responses in MCP format.
    export async function createNote(triliumClient, args) {
      try {
        // Validate inputs
        const title = validators.title(args.title);
        const content = validators.content(args.content);
        const type = validators.noteType(args.type);
        // TriliumNext API requires parentNoteId - default to 'root' if not provided
        const parentNoteId = args.parentNoteId ? validators.noteId(args.parentNoteId) : 'root';
    
        logger.debug(`Creating note: title="${title}", type="${type}", parent="${parentNoteId}"`);
    
        // Prepare note data for TriliumNext API
        const noteData = {
          title,
          content,
          type,
          parentNoteId, // Always required by TriliumNext API
        };
    
        // Create the note via TriliumNext API
        const result = await triliumClient.post('create-note', noteData);
        
        if (!result || !result.note || !result.note.noteId) {
          throw new TriliumAPIError('Invalid response from TriliumNext API - missing note ID');
        }
    
        const noteId = result.note.noteId;
        logger.info(`Note created successfully with ID: ${noteId}`);
    
        // Prepare structured response data
        const creationData = {
          operation: 'create_note',
          timestamp: new Date().toISOString(),
          request: {
            title,
            type,
            contentLength: content.length,
            parentNoteId
          },
          result: {
            noteId,
            ...result.note, // Include any additional data from API response
            triliumUrl: `trilium://note/${noteId}` // Add direct link if useful
          }
        };
    
        return {
          content: [
            {
              type: 'text',
              text: `Note created: "${title}" (ID: ${noteId})`
            },
            {
              type: 'application/json',
              text: JSON.stringify(creationData, null, 2)
            }
          ],
        };
      } catch (error) {
        logger.error(`Failed to create note: ${error.message}`);
        
        // Create structured error response
        const errorData = {
          operation: 'create_note',
          timestamp: new Date().toISOString(),
          request: {
            title: args.title,
            type: args.type,
            contentLength: args.content?.length,
            parentNoteId: args.parentNoteId
          },
          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) {
          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: `Note creation failed: ${error.message}`
            },
            {
              type: 'application/json',
              text: JSON.stringify(errorData, null, 2)
            }
          ],
          isError: true,
        };
      }
    }
  • The MCP tool schema definition for 'create_note', including input schema with properties, types, descriptions, enums, and required fields.
    {
      name: 'create_note',
      description: 'Create a new note in TriliumNext',
      inputSchema: {
        type: 'object',
        properties: {
          title: {
            type: 'string',
            description: 'The title of the note (max 200 characters)',
          },
          content: {
            type: 'string',
            description: 'The content of the note (max 1MB)',
          },
          type: {
            type: 'string',
            enum: ['text', 'code', 'file', 'image', 'search', 'book', 'relationMap', 'canvas'],
            default: 'text',
            description: 'The type of note to create',
          },
          parentNoteId: {
            type: 'string',
            description: 'ID of the parent note (defaults to "root" if not provided)',
          },
        },
        required: ['title', 'content'],
      },
    },
  • src/index.js:144-145 (registration)
    Registration of the create_note tool in the CallToolRequestSchema dispatch switch statement, routing calls to the handler.
    case 'create_note':
      return await this.createNote(request.params.arguments);
  • src/index.js:201-203 (registration)
    Wrapper method on the server class that delegates create_note execution to the core handler function.
    async createNote(args) {
      return await createNote(this.triliumClient, args);
    }
  • Validation helper functions used by the create_note handler for input sanitization and validation (title, content, type, noteId).
    export const validators = {
      noteId: (noteId) => {
        if (!noteId || typeof noteId !== 'string') {
          throw new ValidationError('Note ID must be a non-empty string');
        }
        if (noteId.trim().length === 0) {
          throw new ValidationError('Note ID cannot be empty');
        }
        return noteId.trim();
      },
    
      title: (title) => {
        if (!title || typeof title !== 'string') {
          throw new ValidationError('Title must be a non-empty string');
        }
        const trimmed = title.trim();
        if (trimmed.length === 0) {
          throw new ValidationError('Title cannot be empty');
        }
        if (trimmed.length > 200) {
          throw new ValidationError('Title cannot exceed 200 characters');
        }
        return trimmed;
      },
    
      content: (content) => {
        if (content === null || content === undefined) {
          throw new ValidationError('Content cannot be null or undefined');
        }
        if (typeof content !== 'string') {
          throw new ValidationError('Content must be a string');
        }
        if (content.length > 1000000) { // 1MB limit
          throw new ValidationError('Content cannot exceed 1MB');
        }
        return content;
      },
    
      noteType: (type) => {
        const validTypes = ['text', 'code', 'file', 'image', 'search', 'book', 'relationMap', 'canvas'];
        if (type && !validTypes.includes(type)) {
          throw new ValidationError(`Note type must be one of: ${validTypes.join(', ')}`);
        }
        return type || 'text';
      },
    
      searchQuery: (query) => {
        if (!query || typeof query !== 'string') {
          throw new ValidationError('Search query must be a non-empty string');
        }
        const trimmed = query.trim();
        if (trimmed.length === 0) {
          throw new ValidationError('Search query cannot be empty');
        }
        if (trimmed.length > 500) {
          throw new ValidationError('Search query cannot exceed 500 characters');
        }
        return trimmed;
      },
    
      limit: (limit) => {
        if (limit === undefined || limit === null) {
          return 10; // default
        }
        const num = parseInt(limit, 10);
        if (isNaN(num) || num < 1) {
          throw new ValidationError('Limit must be a positive integer');
        }
        if (num > 100) {
          throw new ValidationError('Limit cannot exceed 100');
        }
        return num;
      }
    };
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states this is a creation operation but doesn't mention permissions needed, whether it's idempotent, error handling, or what happens on success/failure. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

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 that states the core purpose without any wasted words. It's appropriately sized and front-loaded, making it easy for an agent to parse quickly.

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?

For a creation tool with no annotations and no output schema, the description is inadequate. It doesn't explain what happens after creation (e.g., returns note ID), error conditions, or behavioral nuances. Given the complexity of a mutation operation, more context is needed for completeness.

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 all four parameters thoroughly. The description adds no additional parameter information beyond what's in the schema, resulting in the baseline score of 3 where the schema does the heavy lifting.

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 verb ('Create') and resource ('a new note in TriliumNext'), making the purpose immediately understandable. However, it doesn't differentiate this from sibling tools like 'update_note' or explain when to create versus update, 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 'update_note' or 'search_notes'. There's no mention of prerequisites, context, or exclusions, leaving the agent with minimal usage direction.

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