search_documents
Find documents by searching titles and content using full-text queries to retrieve relevant information from stored documentation.
Instructions
Search documents by title or content using full-text search
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query to find documents (searches title and content) | |
| limit | No | Maximum number of results to return (default: 50) |
Implementation Reference
- src/index.js:898-951 (handler)The tool `search_documents` is registered using `server.tool` and uses `searchDocuments` to fetch the data.
const searchDocumentsTool = server.tool( 'search_documents', 'Search documents by title or content using full-text search', { query: z.string().min(1, 'Query cannot be empty').describe('Search query to find documents (searches title and content)'), limit: z.number().min(1).max(100).optional().default(50).describe('Maximum number of results to return (default: 50)') }, async ({ query, limit = 50 }) => { try { // Only authenticate when tool is actually invoked await authenticateWhenNeeded(); const result = await searchDocuments(query, limit); if (result.items.length === 0) { return { content: [ { type: 'text', text: `🔍 No documents found matching "${query}"` } ] }; } const searchResults = result.items.map(doc => `**${doc.title}** (ID: ${doc.id})\n` + `Source: ${doc.metadata?.source || 'Unknown'}\n` + `Domain: ${doc.metadata?.domain || 'Unknown'}\n` + `Created: ${new Date(doc.created).toLocaleString()}\n` + `${doc.metadata?.url ? `URL: ${doc.metadata.url}\n` : ''}` + `Preview: ${doc.content.substring(0, 150)}...\n` ).join('\n---\n'); return { content: [ { type: 'text', text: `🔍 Found ${result.items.length} documents matching "${query}":\n\n${searchResults}` } ] }; } catch (error) { return { content: [ { type: 'text', text: `❌ Error: ${error.message}` } ], isError: true }; } } ); - src/index.js:600-620 (handler)The `searchDocuments` function is the core logic that performs the actual full-text search against the PocketBase collection.
// Search documents in PocketBase (with lazy initialization) async function searchDocuments(query, limit = 50) { try { await authenticateWhenNeeded(); if (!DOCUMENTS_COLLECTION) { initializeConfig(); } const records = await pb.collection(DOCUMENTS_COLLECTION).getList(1, limit, { filter: `title ~ "${query}" || content ~ "${query}"`, sort: '-created' }); debugLog('Documents searched in PocketBase', { query, count: records.items.length }); return records; } catch (error) { debugLog('Error searching documents', { error: error.message }); throw new Error(`Failed to search documents: ${error.message}`); } }