get_backlinks
Retrieve all notes that link to a specified note in your Flint Note vault. Identify backlinks to understand connections between your notes.
Instructions
Get all notes that link to the specified note
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| identifier | Yes | Note identifier (type/filename format) |
Implementation Reference
- src/server/link-handlers.ts:79-131 (handler)Main handler method for the get_backlinks tool. Validates input, resolves database context, verifies note existence, queries backlinks using LinkExtractor, and returns JSON-formatted response.handleGetBacklinks = async (args: { identifier: string; vault_id?: string }) => { try { // Validate arguments validateToolArgs('get_backlinks', args); const { hybridSearchManager } = await this.resolveVaultContext(args.vault_id); const db = await hybridSearchManager.getDatabaseConnection(); const noteId = this.generateNoteIdFromIdentifier(args.identifier); // Check if note exists const note = await db.get('SELECT id FROM notes WHERE id = ?', [noteId]); if (!note) { throw new Error(`Note not found: ${args.identifier}`); } const backlinks = await LinkExtractor.getBacklinks(noteId, db); return { content: [ { type: 'text', text: JSON.stringify( { success: true, note_id: noteId, backlinks: backlinks }, 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:1332-1335 (registration)Tool registration in the MCP CallToolRequestSchema handler switch statement, dispatching to LinkHandlers.handleGetBacklinks.return await this.linkHandlers.handleGetBacklinks( args as unknown as { identifier: string; vault_id?: string } );
- src/server.ts:1157-1169 (schema)Tool schema definition returned by ListToolsRequestSchema, specifying input requirements (identifier required).name: 'get_backlinks', description: 'Get all notes that link to the specified note', inputSchema: { type: 'object', properties: { identifier: { type: 'string', description: 'Note identifier (type/filename format)' } }, required: ['identifier'] } },
- src/core/link-extractor.ts:332-340 (helper)Core helper method that executes the SQL query to fetch all incoming links (backlinks) from the note_links table for the given note ID.static async getBacklinks( noteId: string, db: DatabaseConnection ): Promise<NoteLinkRow[]> { return await db.all<NoteLinkRow>( `SELECT * FROM note_links WHERE target_note_id = ? ORDER BY created DESC`, [noteId] ); }
- src/server/validation.ts:822-845 (schema)Input validation rules for get_backlinks tool arguments, ensuring identifier is in 'type/filename' format.get_backlinks: [ { field: 'identifier', required: true, type: 'string', allowEmpty: false, customValidator: (value: string) => { if (!value.includes('/')) { return 'identifier must be in format "type/filename"'; } const parts = value.split('/'); if (parts.length !== 2 || !parts[0] || !parts[1]) { return 'identifier must be in format "type/filename" with both parts non-empty'; } return null; } }, { field: 'vault_id', required: false, type: 'string', allowEmpty: false } ],