migrate_links
Scan and migrate all existing notes to populate link tables in Flint Note. This one-time tool ensures accurate note connections, even if link tables contain data, by optionally forcing migration.
Instructions
Scan all existing notes and populate the link tables (one-time migration)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| force | No | Force migration even if link tables already contain data |
Input Schema (JSON Schema)
{
"properties": {
"force": {
"default": false,
"description": "Force migration even if link tables already contain data",
"type": "boolean"
}
},
"type": "object"
}
Implementation Reference
- src/server/link-handlers.ts:288-383 (handler)Main handler function that executes the migrate_links tool: validates args, checks if links exist (unless force), extracts links from all notes using LinkExtractor, stores them in DB tables.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 }; } };
- src/server.ts:1352-1355 (registration)Registration of the migrate_links tool in the MCP server's CallToolRequestSchema handler, dispatching to LinkHandlers.handleMigrateLinkscase 'migrate_links': return await this.linkHandlers.handleMigrateLinks( args as unknown as { force?: boolean; vault_id?: string } );
- src/server.ts:1208-1221 (schema)Tool schema definition for migrate_links provided in ListToolsRequestSchema responsename: '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 } } } }
- src/server/tool-schemas.ts:951-970 (schema)Centralized tool schema definition for migrate_links (potentially used for documentation or generation) with vault_id support{ 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.' } } } }
- src/server/validation.ts:917-929 (helper)Validation rules for migrate_links tool arguments used in validateToolArgs('migrate_links', args)migrate_links: [ { field: 'force', required: false, type: 'boolean' }, { field: 'vault_id', required: false, type: 'string', allowEmpty: false } ],