Skip to main content
Glama
DynamicEndpoints

Document Extractor MCP Server

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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()}`

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DynamicEndpoints/documentation-mcp-using-pocketbase'

If you have feedback or need assistance with the MCP directory API, please join our Discord server