list_collections
Retrieve all available Qdrant collections for managing and organizing vector database content in the Better Qdrant MCP Server.
Instructions
List all available Qdrant collections
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:220-251 (handler)The primary handler function for the 'list_collections' MCP tool. It invokes the Qdrant service to list collections, formats the result as JSON text response, and handles errors appropriately.private async handleListCollections() { try { const collections = await this.qdrantService.listCollections(); return { content: [ { type: 'text', text: JSON.stringify(collections, null, 2), }, ], }; } catch (error) { console.error('Error in handleListCollections:', error); let errorDetails = ''; if (error instanceof Error) { errorDetails = `${error.name}: ${error.message}\nStack: ${error.stack}`; } else { errorDetails = String(error); } return { content: [ { type: 'text', text: `Error listing collections: ${errorDetails}`, }, ], isError: true, }; } }
- src/index.ts:108-116 (registration)Registration of the 'list_collections' tool in the MCP server, including name, description, and empty input schema (no parameters required).{ name: 'list_collections', description: 'List all available Qdrant collections', inputSchema: { type: 'object', properties: {}, required: [], }, },
- src/services/qdrant.ts:14-52 (helper)The core implementation of listing collections via direct HTTP fetch to Qdrant API /collections endpoint, extracting collection names.async listCollections(): Promise<string[]> { try { console.log('Attempting to connect to Qdrant server using direct fetch...'); // Use direct fetch instead of the client const collectionsUrl = `${this.url}/collections`; console.log(`Fetching from: ${collectionsUrl}`); const response = await fetch(collectionsUrl, { method: 'GET', headers: { 'Content-Type': 'application/json', ...(this.apiKey ? { 'api-key': this.apiKey } : {}) }, // @ts-ignore - node-fetch supports timeout timeout: 5000 // 5 second timeout }); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } const data = await response.json() as { result: { collections: Array<{ name: string }> } }; console.log('Successfully retrieved collections:', data); return data.result.collections.map(c => c.name); } catch (error) { console.error('Error in listCollections:', error); if (error instanceof Error) { console.error(`${error.name}: ${error.message}`); console.error('Stack:', error.stack); } throw error; } }
- src/types.ts:42-42 (schema)TypeScript interface definition for the listCollections method in QdrantService, specifying return type as Promise<string[]>.listCollections(): Promise<string[]>;