Skip to main content
Glama
DynamicEndpoints

Document Extractor MCP Server

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
NameRequiredDescriptionDefault
queryYesSearch query to find documents (searches title and content)
limitNoMaximum number of results to return (default: 50)

Implementation Reference

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

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