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
| Name | Required | Description | Default |
|---|---|---|---|
| force | No | Force migration even if link tables already contain data |
Implementation Reference
- src/server/link-handlers.ts:288-383 (handler)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 }; } };
- src/server/tool-schemas.ts:951-970 (schema)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.' } } } }
- src/server.ts:1352-1355 (registration)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 } );
- src/server.ts:1208-1221 (registration)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 } } } }
- src/server/validation.ts:917-929 (schema)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 } ],