sync_knowledge
Sync Outline wiki documents to a vector store to enable AI-powered search and retrieval for answering questions.
Instructions
Sync documents to vector store for AI-powered search. Run this before using ask_wiki.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collectionId | No |
Implementation Reference
- src/lib/handlers/smart.ts:16-83 (handler)The core handler function for the 'sync_knowledge' tool. It fetches documents from Outline (optionally filtered by collection), retrieves full content, and syncs them to the vector store (brain) for RAG./** * Sync all documents to vector store for RAG * * Note: documents.list may return truncated or missing text, * so we fetch each document's full content via documents.info */ async sync_knowledge(args: { collectionId?: string }) { if (!brain.isEnabled()) { return { error: ERROR_MESSAGES.SMART_FEATURES_DISABLED }; } // Step 1: Fetch document list from Outline const payload: Record<string, unknown> = { limit: 100 }; if (args.collectionId) { payload.collectionId = args.collectionId; } const { data: docList } = await apiCall(() => apiClient.post<OutlineDocument[]>('/documents.list', payload) ); if (!docList || docList.length === 0) { return { message: ERROR_MESSAGES.NO_DOCUMENTS_FOUND, synced: 0 }; } // Step 2: Fetch full content for each document (list API may truncate text) const wikiDocs: WikiDocument[] = []; let fetchErrors = 0; for (const doc of docList) { try { const { data: fullDoc } = await apiCall(() => apiClient.post<OutlineDocument>('/documents.info', { id: doc.id }) ); if (fullDoc && fullDoc.text) { wikiDocs.push({ id: fullDoc.id, title: fullDoc.title, text: fullDoc.text, url: `${baseUrl}${fullDoc.url}`, collectionId: fullDoc.collectionId, }); } } catch { fetchErrors++; } } if (wikiDocs.length === 0) { return { message: ERROR_MESSAGES.NO_DOCUMENTS_WITH_CONTENT, synced: 0, errors: fetchErrors, }; } // Step 3: Sync to brain (vectorize) const result = await brain.syncDocuments(wikiDocs); return { message: `Successfully synced ${result.documents} documents (${result.chunks} chunks).`, documents: result.documents, chunks: result.chunks, skipped: docList.length - wikiDocs.length, errors: fetchErrors, }; },
- src/lib/schemas.ts:142-144 (schema)Zod schema defining the input for sync_knowledge: optional collectionId (UUID).export const syncKnowledgeSchema = z.object({ collectionId: collectionId.optional(), });
- src/lib/tools.ts:200-204 (registration)MCP tool definition/registration for 'sync_knowledge', mapping to the Zod schema and providing description.createTool( 'sync_knowledge', 'Sync documents to vector store for AI-powered search. Run this before using ask_wiki.', 'sync_knowledge' ),
- src/lib/handlers/index.ts:26-26 (registration)Spreads the smart handlers (including sync_knowledge) into the main ToolHandlers object during handler creation....createSmartHandlers(ctx),
- src/lib/schemas.ts:244-244 (schema)Entry in toolSchemas map that associates 'sync_knowledge' tool name with its Zod schema.sync_knowledge: syncKnowledgeSchema,