ensure_collection
Verifies document collection existence in PocketBase and creates it automatically when missing to maintain organized storage for extracted content.
Instructions
Check if the documents collection exists and create it if needed
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.js:128-144 (handler)The 'ensureCollectionExists' function checks for a document collection existence in PocketBase and creates it if it is missing.
async function ensureCollectionExists() { await authenticateWhenNeeded(); try { const collection = await pb.collections.getOne(DOCUMENTS_COLLECTION); debugLog('✅ Collection exists', { name: DOCUMENTS_COLLECTION, id: collection.id }); return { exists: true, collection, created: false }; } catch (error) { if (error.status === 404) { debugLog('📝 Creating collection', { name: DOCUMENTS_COLLECTION }); const newCollection = await pb.collections.create(getDocumentsCollectionSchema()); debugLog('✅ Collection created successfully', { name: DOCUMENTS_COLLECTION, id: newCollection.id }); return { exists: true, collection: newCollection, created: true }; } else { throw error; } } } - server.js:635-655 (registration)The 'ensure_collection' MCP tool is registered using server.tool, calling ensureCollectionExists internally.
server.tool( 'ensure_collection', 'Check if the documents collection exists and create it if needed', {}, async () => { try { await authenticateWhenNeeded(); const result = await ensureCollectionExists(); return { content: [{ type: 'text', text: result.created ? `✅ Documents collection "${DOCUMENTS_COLLECTION}" created successfully!\n\n` + `**Collection Details:**\n` + `- ID: ${result.collection.id}\n` + `- Name: ${result.collection.name}\n` + `- Type: ${result.collection.type}\n` + `- Schema Fields: ${result.collection.schema?.length || 0}\n` + `- Created: ${new Date(result.collection.created).toLocaleString()}`