Skip to main content
Glama
tan-yong-sheng

TriliumNext Notes' MCP Server

search_notes

Search notes in TriliumNext with keyword queries or advanced filters for content, dates, templates, note types, MIME types, and hierarchy navigation using boolean logic.

Instructions

Unified search with comprehensive filtering capabilities including keyword search, date ranges, field-specific searches, attribute searches, note properties, template-based searches, note type filtering, MIME type filtering, and hierarchy navigation through unified searchCriteria structure. For simple keyword searches, use the 'text' parameter. For complex boolean logic like 'docker OR kubernetes', use searchCriteria with proper OR logic. For template search: use relation type with 'template.title' property and built-in template values like 'Calendar', 'Board', 'Text Snippet', 'Grid View', 'List View', 'Table', 'Geo Map'. For note type search: use noteProperty type with 'type' property and values from the 9 supported ETAPI types: 'text', 'code', 'render', 'search', 'relationMap', 'book', 'noteMap', 'mermaid', 'webView'. For MIME type search: use noteProperty type with 'mime' property and MIME values like 'text/javascript', 'text/x-python', 'text/vnd.mermaid', 'application/json'. Use hierarchy properties like 'parents.noteId', 'children.noteId', or 'ancestors.noteId' for navigation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textNoSIMPLE keyword search ONLY - single terms or exact phrases. Examples: 'kubernetes' (finds notes containing 'kubernetes'), 'machine learning' (finds notes containing both 'machine' AND 'learning' together), '"docker kubernetes"' (finds notes containing the exact phrase 'docker kubernetes'). ⚠️ WARNING: This parameter does NOT support boolean operators like OR, AND, NOT. If you use 'docker OR kubernetes', it will search for the literal text 'docker OR kubernetes' and return no results. For any boolean logic (OR, AND, NOT), you MUST use searchCriteria parameter instead.
searchCriteriaNoUnified search criteria array that supports all search types with complete boolean logic. Enables cross-type OR operations (e.g., 'relation OR dateCreated' searches). Supports labels, relations, note properties (including hierarchy navigation: parents.title, children.title, ancestors.title), note type filtering, MIME type filtering, and keyword searches. For keyword searches: use noteProperty type with 'title' or 'content' properties. Operators include existence checks (exists, not_exists), comparisons (=, !=, >=, <=, >, <), and text matching (contains, starts_with, ends_with, regex). Use OR logic between items for 'either/or' searches across ANY criteria types. Examples: Find mermaid diagrams by setting type property to 'mermaid'. Find JavaScript code by combining type 'code' with mime 'text/javascript'. Find mermaid notes by using OR logic between type criteria. Logic parameter connects current item to next item.
limitNoMaximum number of results to return

Implementation Reference

  • Entry point handler for search_notes tool: permission check, parameter mapping, core logic delegation, and MCP response formatting.
    export async function handleSearchNotesRequest(
      args: any,
      axiosInstance: any,
      permissionChecker: PermissionChecker
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      if (!permissionChecker.hasPermission("READ")) {
        throw new McpError(ErrorCode.InvalidRequest, "Permission denied: Not authorized to search notes.");
      }
    
      try {
        const searchOperation: SearchOperation = {
          text: args.text,
          searchCriteria: args.searchCriteria,
          limit: args.limit
        };
    
        const result = await handleSearchNotes(searchOperation, axiosInstance);
        const resultsText = JSON.stringify(result.results, null, 2);
    
        return {
          content: [{
            type: "text",
            text: `${result.debugInfo || ''}${resultsText}`
          }]
        };
      } catch (error) {
        if (error instanceof McpError) {
          throw error;
        }
        throw new McpError(ErrorCode.InvalidParams, error instanceof Error ? error.message : String(error));
      }
    }
  • Core implementation executing the TriliumNext search API call with dynamic query building, smart fastSearch optimization, result trimming, and debug information.
    export async function handleSearchNotes(
      args: SearchOperation,
      axiosInstance: any
    ): Promise<SearchResponse> {
      // Build query from structured parameters
      const query = buildSearchQuery(args);
      
      if (!query.trim()) {
        throw new Error("At least one search parameter must be provided");
      }
    
      const params = new URLSearchParams();
      params.append("search", query);
      
      // Smart fastSearch logic: use fastSearch=true ONLY when ONLY text parameter is provided (no other parameters)
      const hasOnlyText = args.text &&
        (!args.searchCriteria || !Array.isArray(args.searchCriteria) || args.searchCriteria.length === 0) &&
        !args.limit; // fastSearch doesn't support limit clauses
      
      params.append("fastSearch", hasOnlyText ? "true" : "false");
      params.append("includeArchivedNotes", "true"); // Always include archived notes
    
      const response = await axiosInstance.get(`/notes?${params.toString()}`);
      
      // Prepare verbose debug info if enabled
      const verboseInfo = createSearchDebugInfo(query, args);
      
      let searchResults = response.data.results || [];
    
      const trimmedResults = trimNoteResults(searchResults);
      
      return {
        results: trimmedResults,
        debugInfo: verboseInfo
      };
    }
  • src/index.ts:109-110 (registration)
    Tool registration in the MCP CallToolRequestHandler switch statement dispatching to the handler function.
    case "search_notes":
      return await handleSearchNotesRequest(request.params.arguments, this.axiosInstance, this);
  • MCP tool schema definition for 'search_notes' including detailed inputSchema with properties for text search, advanced searchCriteria array, and result limit.
        {
          name: "search_notes",
          description: "Unified search with comprehensive filtering capabilities including keyword search, date ranges, field-specific searches, attribute searches, note properties, template-based searches, note type filtering, MIME type filtering, and hierarchy navigation through unified searchCriteria structure. For simple keyword searches, use the 'text' parameter. For complex boolean logic like 'docker OR kubernetes', use searchCriteria with proper OR logic. For template search: use relation type with 'template.title' property and built-in template values like 'Calendar', 'Board', 'Text Snippet', 'Grid View', 'List View', 'Table', 'Geo Map'. For note type search: use noteProperty type with 'type' property and values from the 9 supported ETAPI types: 'text', 'code', 'render', 'search', 'relationMap', 'book', 'noteMap', 'mermaid', 'webView'. For MIME type search: use noteProperty type with 'mime' property and MIME values like 'text/javascript', 'text/x-python', 'text/vnd.mermaid', 'application/json'. Use hierarchy properties like 'parents.noteId', 'children.noteId', or 'ancestors.noteId' for navigation.",
          inputSchema: {
            type: "object",
            properties: searchProperties,
          },
        }
      ];
    }
    
    /**
     * Create shared search properties for reuse across search tools
     */
    function createSearchProperties() {
      return {
        text: {
          type: "string",
          description: "SIMPLE keyword search ONLY - single terms or exact phrases. Examples: 'kubernetes' (finds notes containing 'kubernetes'), 'machine learning' (finds notes containing both 'machine' AND 'learning' together), '\"docker kubernetes\"' (finds notes containing the exact phrase 'docker kubernetes'). ⚠️ WARNING: This parameter does NOT support boolean operators like OR, AND, NOT. If you use 'docker OR kubernetes', it will search for the literal text 'docker OR kubernetes' and return no results. For any boolean logic (OR, AND, NOT), you MUST use searchCriteria parameter instead.",
        },
        searchCriteria: {
          type: "array",
          description: "Unified search criteria array that supports all search types with complete boolean logic. Enables cross-type OR operations (e.g., 'relation OR dateCreated' searches). Supports labels, relations, note properties (including hierarchy navigation: parents.title, children.title, ancestors.title), note type filtering, MIME type filtering, and keyword searches. For keyword searches: use noteProperty type with 'title' or 'content' properties. Operators include existence checks (exists, not_exists), comparisons (=, !=, >=, <=, >, <), and text matching (contains, starts_with, ends_with, regex). Use OR logic between items for 'either/or' searches across ANY criteria types. Examples: Find mermaid diagrams by setting type property to 'mermaid'. Find JavaScript code by combining type 'code' with mime 'text/javascript'. Find mermaid notes by using OR logic between type criteria. Logic parameter connects current item to next item.",
          items: {
            type: "object",
            properties: {
              property: {
                type: "string",
                description: "Property name. For labels: tag name (e.g., 'book', 'author'). For relations: relation name with optional property path (e.g., 'author', 'author.title', 'template.title'). Built-in templates: use 'template.title' with values 'Calendar', 'Board', 'Text Snippet', 'Grid View', 'List View', 'Table', 'Geo Map'. For note properties: system property name (e.g., 'isArchived', 'type', 'mime', 'title', 'content', 'dateCreated') OR hierarchy properties (e.g., 'parents.title', 'children.title', 'ancestors.title', 'parents.parents.title')."
              },
              type: {
                type: "string",
                enum: ["label", "relation", "noteProperty"],
                description: "Type of search criteria: 'label' for #tags, 'relation' for ~relations, 'noteProperty' for note.* system properties and hierarchy navigation"
              },
              op: {
                type: "string",
                enum: ["exists", "not_exists", "=", "!=", ">=", "<=", ">", "<", "contains", "starts_with", "ends_with", "regex"],
                description: "Search operator for property matching and comparison. Use 'exists' to find notes with a property, 'not_exists' to find notes without the property at all, '=' for exact matches, '!=' to find notes that have the property but excluding specific values, '>=' and '<=' for ranges, and text operators like 'contains' for partial matches.",
                default: "exists"
              },
              value: {
                type: "string",
                description: "Value to compare against (optional for exists operator). For built-in template relations: use 'Calendar' (calendar notes), 'Board' (task boards), 'Text Snippet' (text snippets), 'Grid View' (grid layouts), 'List View' (list layouts), 'Table' (table views), 'Geo Map' (geography maps). For note type property: use ETAPI-aligned note types: 'text' (rich text), 'code' (code with syntax highlighting), 'render' (rendered content), 'search' (saved searches), 'relationMap' (relation maps), 'book' (folders/containers), 'noteMap' (note relationship maps), 'mermaid' (Mermaid diagrams), 'webView' (web content embedding). For note MIME property: use MIME types like 'text/javascript', 'text/x-python', 'text/x-java', 'text/css', 'text/html', 'text/x-typescript', 'text/x-sql', 'text/x-yaml', 'text/x-markdown', 'text/vnd.mermaid', 'application/json'. For noteProperty dates (dateCreated, dateModified): MUST use ISO date format - 'YYYY-MM-DDTHH:mm:ss.sssZ'. For hierarchy navigation: parent/ancestor note title or 'root' for top-level."
              },
              logic: {
                type: "string",
                enum: ["AND", "OR"],
                description: "Logic operator connecting this item to the NEXT item in the array. Think sequentially: each item's logic determines how it combines with the following item. For 'A OR B AND C' expressions, use OR on first item, AND on second item. For simple 'A OR B' use OR on first item only. Default AND creates standard conjunctions. System ignores logic on the final array item.",
                default: "AND"
              }
            },
            required: ["property", "type", "logic"]
          }
        },
        limit: {
          type: "number",
          description: "Maximum number of results to return",
        },
      };
    }
Behavior4/5

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

Since no annotations are provided, the description carries full burden. It effectively describes the tool's behavioral traits: it's a read-only search operation (implied by 'search'), supports comprehensive filtering, handles boolean logic, and includes hierarchy navigation. However, it doesn't mention rate limits, authentication requirements, or pagination behavior, which would be helpful for a search tool.

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

Conciseness2/5

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

The description is overly verbose and poorly structured. It's a single dense paragraph mixing high-level purpose with detailed parameter usage examples. Important guidance is buried in the middle rather than front-loaded. While informative, it could be much more concise and better organized for quick comprehension.

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

Completeness4/5

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

For a search tool with no annotations and no output schema, the description does a good job explaining what the tool does and how to use it. It covers the main functionality, parameter usage, and provides concrete examples. However, it lacks information about result format, pagination, error handling, or performance characteristics that would be useful for a comprehensive search tool.

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?

With 100% schema description coverage, the baseline is 3. The description adds some value by explaining when to use 'text' vs 'searchCriteria' parameters and providing examples of template values, note types, and MIME types. However, it doesn't significantly enhance parameter understanding beyond what's already well-documented in the schema.

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

Purpose5/5

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

The description clearly states the tool's purpose as 'Unified search with comprehensive filtering capabilities' and lists specific search types (keyword, date ranges, field-specific, etc.). It distinguishes from siblings by focusing on search functionality rather than CRUD operations like create_note, delete_note, or update_note.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use different parameters: 'For simple keyword searches, use the 'text' parameter. For complex boolean logic... use searchCriteria.' It also gives specific examples for template searches, note type searches, and MIME type searches, clearly indicating appropriate usage scenarios.

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/tan-yong-sheng/triliumnext-mcp'

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