Skip to main content
Glama
disnet
by disnet

search_by_links

Find notes in your vault by analyzing link relationships. Search for notes that link to specific content, are linked from other notes, contain external domain links, or have broken internal connections.

Instructions

Search for notes based on their link relationships

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
has_links_toNoFind notes that link to any of these notes
linked_fromNoFind notes that are linked from any of these notes
external_domainsNoFind notes with external links to these domains
broken_linksNoFind notes with broken internal links

Implementation Reference

  • The primary handler function for the 'search_by_links' tool. It validates arguments, resolves the vault context, executes SQL queries based on link criteria (has_links_to, linked_from, external_domains, broken_links), and returns JSON results or error.
    handleSearchByLinks = async (args: {
      has_links_to?: string[];
      linked_from?: string[];
      external_domains?: string[];
      broken_links?: boolean;
      vault_id?: string;
    }) => {
      try {
        // Validate arguments
        validateToolArgs('search_by_links', args);
    
        const { hybridSearchManager } = await this.resolveVaultContext(args.vault_id);
        const db = await hybridSearchManager.getDatabaseConnection();
        let notes: NoteRow[] = [];
    
        // Handle different search criteria
        if (args.has_links_to && args.has_links_to.length > 0) {
          // Find notes that link to any of the specified notes
          const targetIds = args.has_links_to.map(id =>
            this.generateNoteIdFromIdentifier(id)
          );
          const placeholders = targetIds.map(() => '?').join(',');
          notes = await db.all(
            `SELECT DISTINCT n.* FROM notes n
             INNER JOIN note_links nl ON n.id = nl.source_note_id
             WHERE nl.target_note_id IN (${placeholders})`,
            targetIds
          );
        } else if (args.linked_from && args.linked_from.length > 0) {
          // Find notes that are linked from any of the specified notes
          const sourceIds = args.linked_from.map(id =>
            this.generateNoteIdFromIdentifier(id)
          );
          const placeholders = sourceIds.map(() => '?').join(',');
          notes = await db.all(
            `SELECT DISTINCT n.* FROM notes n
             INNER JOIN note_links nl ON n.id = nl.target_note_id
             WHERE nl.source_note_id IN (${placeholders})`,
            sourceIds
          );
        } else if (args.external_domains && args.external_domains.length > 0) {
          // Find notes with external links to specified domains
          const domainConditions = args.external_domains
            .map(() => 'el.url LIKE ?')
            .join(' OR ');
          const domainParams = args.external_domains.map(domain => `%${domain}%`);
          notes = await db.all(
            `SELECT DISTINCT n.* FROM notes n
             INNER JOIN external_links el ON n.id = el.note_id
             WHERE ${domainConditions}`,
            domainParams
          );
        } else if (args.broken_links) {
          // Find notes with broken internal links
          notes = await db.all(
            `SELECT DISTINCT n.* FROM notes n
             INNER JOIN note_links nl ON n.id = nl.source_note_id
             WHERE nl.target_note_id IS NULL`
          );
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  success: true,
                  notes: notes,
                  count: notes.length
                },
                null,
                2
              )
            }
          ]
        };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : 'Unknown error';
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  success: false,
                  error: errorMessage
                },
                null,
                2
              )
            }
          ],
          isError: true
        };
      }
    };
  • Registration of the 'search_by_links' tool handler in the MCP server's CallToolRequestSchema switch statement, mapping tool calls to LinkHandlers.handleSearchByLinks.
    case 'search_by_links':
      return await this.linkHandlers.handleSearchByLinks(
        args as unknown as {
          has_links_to?: string[];
          linked_from?: string[];
          external_domains?: string[];
          broken_links?: boolean;
          vault_id?: string;
        }
      );
  • Input schema definition for the 'search_by_links' tool, returned by ListToolsRequestSchema handler, defining parameters and descriptions.
    {
      name: 'search_by_links',
      description: 'Search for notes based on their link relationships',
      inputSchema: {
        type: 'object',
        properties: {
          has_links_to: {
            type: 'array',
            items: { type: 'string' },
            description: 'Find notes that link to any of these notes'
          },
          linked_from: {
            type: 'array',
            items: { type: 'string' },
            description: 'Find notes that are linked from any of these notes'
          },
          external_domains: {
            type: 'array',
            items: { type: 'string' },
            description: 'Find notes with external links to these domains'
          },
          broken_links: {
            type: 'boolean',
            description: 'Find notes with broken internal links'
          }
        }
      }
    },
  • Validation rules used by validateToolArgs('search_by_links', args) in the handler, including custom validators for identifier formats in arrays.
    search_by_links: [
      {
        field: 'has_links_to',
        required: false,
        type: 'array',
        arrayItemType: 'string',
        allowEmpty: true,
        customValidator: (value: any) => {
          if (!Array.isArray(value)) return null;
          for (const identifier of value) {
            if (!identifier.includes('/')) {
              return `identifier "${identifier}" must be in format "type/filename"`;
            }
            const parts = identifier.split('/');
            if (parts.length !== 2 || !parts[0] || !parts[1]) {
              return `identifier "${identifier}" must be in format "type/filename" with both parts non-empty`;
            }
          }
          return null;
        }
      },
      {
        field: 'linked_from',
        required: false,
        type: 'array',
        arrayItemType: 'string',
        allowEmpty: true,
        customValidator: (value: any) => {
          if (!Array.isArray(value)) return null;
          for (const identifier of value) {
            if (!identifier.includes('/')) {
              return `identifier "${identifier}" must be in format "type/filename"`;
            }
            const parts = identifier.split('/');
            if (parts.length !== 2 || !parts[0] || !parts[1]) {
              return `identifier "${identifier}" must be in format "type/filename" with both parts non-empty`;
            }
          }
          return null;
        }
      },
      {
        field: 'external_domains',
        required: false,
        type: 'array',
        arrayItemType: 'string',
        allowEmpty: true
      },
      {
        field: 'broken_links',
        required: false,
        type: 'boolean'
      },
      {
        field: 'vault_id',
        required: false,
        type: 'string',
        allowEmpty: false
      }
    ],
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but offers minimal information. It doesn't specify whether this is a read-only operation, what permissions might be required, how results are returned (e.g., pagination, format), or any rate limits. The description only states the basic function without behavioral details.

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 directly states the tool's purpose without any wasted words. It's appropriately sized and front-loaded with the essential information.

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 search tool with 4 parameters and no output schema, the description is inadequate. It doesn't explain what the tool returns (e.g., note objects, links, counts), how results are structured, or any limitations. With no annotations and incomplete behavioral context, this leaves significant gaps for an AI agent to understand the tool's full behavior.

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 fully documents all four parameters. The description adds no additional parameter semantics beyond what's in the schema (e.g., no examples, edge cases, or usage patterns). This meets the baseline of 3 when schema coverage is high.

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 ('search') and resource ('notes') with the specific criteria ('based on their link relationships'), which distinguishes it from generic search tools. However, it doesn't explicitly differentiate from sibling tools like 'get_note_links' or 'find_broken_links' that also deal with link relationships.

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 'search_notes', 'search_notes_advanced', or 'find_broken_links'. There's no mention of prerequisites, context, or comparative advantages/disadvantages with sibling tools.

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/disnet/flint-note'

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