Skip to main content
Glama
disnet
by disnet

migrate_links

Scan existing notes to populate link tables for a one-time migration in the Flint Note system, enabling AI collaboration through organized markdown files.

Instructions

Scan all existing notes and populate the link tables (one-time migration)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
forceNoForce migration even if link tables already contain data

Implementation Reference

  • Core handler function for the 'migrate_links' MCP tool. Scans all notes in the vault, extracts links using LinkExtractor, stores them in note_links and external_links tables, handles errors per note, and returns migration statistics.
    handleMigrateLinks = async (args: { force?: boolean; vault_id?: string }) => {
      try {
        // Validate arguments
        validateToolArgs('migrate_links', args);
    
        const { hybridSearchManager } = await this.resolveVaultContext(args.vault_id);
        const db = await hybridSearchManager.getDatabaseConnection();
    
        // Check if migration is needed
        if (!args.force) {
          const existingLinks = await db.get<{ count: number }>(
            'SELECT COUNT(*) as count FROM note_links'
          );
          if (existingLinks && existingLinks.count > 0) {
            return {
              content: [
                {
                  type: 'text',
                  text: JSON.stringify(
                    {
                      success: false,
                      message:
                        'Link tables already contain data. Use force=true to migrate anyway.',
                      existing_links: existingLinks.count
                    },
                    null,
                    2
                  )
                }
              ]
            };
          }
        }
    
        // Get all notes from the database
        const notes = await db.all<{ id: string; content: string }>(
          'SELECT id, content FROM notes'
        );
        let processedCount = 0;
        let errorCount = 0;
        const errors: string[] = [];
    
        for (const note of notes) {
          try {
            // Extract links from note content
            const extractionResult = LinkExtractor.extractLinks(note.content);
    
            // Store the extracted links
            await LinkExtractor.storeLinks(note.id, extractionResult, db);
            processedCount++;
          } catch (error) {
            errorCount++;
            const errorMessage = error instanceof Error ? error.message : 'Unknown error';
            errors.push(`${note.id}: ${errorMessage}`);
          }
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  success: true,
                  message: 'Link migration completed',
                  total_notes: notes.length,
                  processed: processedCount,
                  errors: errorCount,
                  error_details: errors.length > 0 ? errors.slice(0, 10) : undefined // Limit error details to first 10
                },
                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
        };
      }
    };
  • JSON Schema definition for the 'migrate_links' tool inputs, defining optional 'force' boolean and 'vault_id' string parameters.
    {
      name: 'migrate_links',
      description:
        'Scan all existing notes and populate the link tables (one-time migration)',
      inputSchema: {
        type: 'object',
        properties: {
          force: {
            type: 'boolean',
            description: 'Force migration even if link tables already contain data',
            default: false
          },
          vault_id: {
            type: 'string',
            description:
              'Optional vault ID to operate on. If not provided, uses the current active vault.'
          }
        }
      }
    }
  • Registration of the 'migrate_links' tool handler in the MCP server's CallToolRequestSchema switch statement, dispatching to LinkHandlers.handleMigrateLinks.
    case 'migrate_links':
      return await this.linkHandlers.handleMigrateLinks(
        args as unknown as { force?: boolean; vault_id?: string }
      );
  • Tool metadata registration for 'migrate_links' in the MCP server's ListToolsRequestSchema response, including name, description, and input schema.
      name: 'migrate_links',
      description:
        'Scan all existing notes and populate the link tables (one-time migration)',
      inputSchema: {
        type: 'object',
        properties: {
          force: {
            type: 'boolean',
            description: 'Force migration even if link tables already contain data',
            default: false
          }
        }
      }
    }
  • Validation rules used by validateToolArgs('migrate_links', args) for input argument checking.
    migrate_links: [
      {
        field: 'force',
        required: false,
        type: 'boolean'
      },
      {
        field: 'vault_id',
        required: false,
        type: 'string',
        allowEmpty: false
      }
    ],

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