mcp_list_containers
List all containers in a connected CosmosDB database to discover available containers, their partition key paths, and indexing policies for query planning.
Instructions
List all containers in the connected CosmosDB database. Use this to discover available containers and their partition key configurations before querying data. Returns container IDs, partition key paths, and indexing policies.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connection_id | No | ID of the connection to use. Use mcp_list_connections to see available connections. If not specified, uses the default connection. |
Implementation Reference
- src/tools/containerAnalysis.ts:54-78 (handler)Handler function that lists all containers in the CosmosDB database. Accepts an optional connection_id, fetches all containers via database.containers.readAll(), maps results to ContainerInfo objects with id, partitionKey, indexingPolicy, etag, and timestamp fields.
export const mcp_list_containers = async (args?: { connection_id?: string }): Promise<ToolResult<ContainerInfo[]>> => { const connection_id = args?.connection_id; log(`Executing mcp_list_containers with connection_id: ${connection_id || 'default'}`); try { const database = getDatabase(connection_id); const { resources: containers } = await database.containers.readAll().fetchAll(); const containersInfo: ContainerInfo[] = containers.map((container: any) => ({ id: container.id, partitionKey: container.partitionKey ? { paths: container.partitionKey.paths || [], kind: container.partitionKey.kind } : undefined, indexingPolicy: container.indexingPolicy, etag: container._etag, timestamp: container._ts ? new Date(container._ts * 1000) : undefined })); return { success: true, data: containersInfo }; } catch (error: any) { log(`Error in mcp_list_containers: ${error.message}`); return { success: false, error: error.message }; } }; - src/tools/types.ts:14-24 (schema)Type definition for ContainerInfo returned by the mcp_list_containers handler.
export interface ContainerInfo { id: string; partitionKey?: { paths: string[]; kind?: string; }; throughput?: number; indexingPolicy?: any; etag?: string; timestamp?: Date; } - src/tools.ts:34-45 (schema)Input schema definition for the mcp_list_containers tool. Has an optional connection_id property and no required fields.
// 2. Container Operations { name: "mcp_list_containers", description: "List all containers in the connected CosmosDB database. Use this to discover available containers and their partition key configurations before querying data. Returns container IDs, partition key paths, and indexing policies.", inputSchema: { type: "object", properties: { ...connectionIdProperty }, required: [] } }, - src/server.ts:122-124 (registration)Registration in the MCP server: routes the 'mcp_list_containers' tool name to the handler function via the CallToolRequestSchema switch statement.
case 'mcp_list_containers': result = await toolHandlers.mcp_list_containers(input as any); break; - src/tools/index.ts:4-9 (helper)Re-exports the mcp_list_containers handler from containerAnalysis.ts for centralized import in mcp-server.ts.
export { mcp_list_databases, mcp_list_containers, mcp_get_container_definition, mcp_get_container_stats } from './containerAnalysis.js';