mcp_list_databases
List all databases in your Azure CosmosDB account to discover available databases before querying containers. Returns database IDs, timestamps, and ETags.
Instructions
List all databases in the CosmosDB account. Use this to discover available databases before querying containers. Returns database IDs, timestamps, and ETags.
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:12-49 (handler)The main handler function that executes the mcp_list_databases tool logic. It accepts an optional connection_id, retrieves the CosmosDB client, lists all databases via client.databases.readAll().fetchAll(), and returns database info (id, etag, timestamp) along with connection metadata.
export const mcp_list_databases = async (args?: { connection_id?: string }): Promise<ToolResult<any>> => { const connection_id = args?.connection_id; log(`Executing mcp_list_databases with connection_id: ${connection_id || 'default'}`); try { const connInfo = getConnectionInfo(connection_id); log(`[DEBUG] Connection info: ${JSON.stringify(connInfo)}`); const database = getDatabase(connection_id); const client = database.client; const { resources: databases } = await client.databases.readAll().fetchAll(); const databasesInfo = databases.map(db => ({ id: db.id, etag: db._etag, timestamp: new Date(db._ts * 1000) })); // Include connection info for clarity return { success: true, data: { connection: { id: connInfo.connectionId, endpoint: connInfo.endpoint, databaseId: connInfo.databaseId, allowModifications: connInfo.allowModifications }, availableConnections: connInfo.registeredConnections, databases: databasesInfo } }; } catch (error: any) { log(`Error in mcp_list_databases: ${error.message}`); return { success: false, error: error.message }; } }; - src/tools.ts:22-32 (schema)Schema/registration definition for the mcp_list_databases tool. Defines the tool name, description, and input schema (optional connection_id property).
{ name: "mcp_list_databases", description: "List all databases in the CosmosDB account. Use this to discover available databases before querying containers. Returns database IDs, timestamps, and ETags.", inputSchema: { type: "object", properties: { ...connectionIdProperty }, required: [] } }, - src/server.ts:119-121 (registration)Registration entry in the MCP CallTool handler's switch statement. Routes the tool name 'mcp_list_databases' to the handler function imported from './mcp-server.js'.
case 'mcp_list_databases': result = await toolHandlers.mcp_list_databases(input as any); break; - src/db.ts:305-307 (helper)Helper function getDatabase() used by the handler to retrieve the CosmosDB Database reference for the specified connection.
export const getDatabase = (connectionId?: string): Database => { return getConnection(connectionId).database; }; - src/db.ts:320-344 (helper)Helper function getConnectionInfo() used by the handler to retrieve connection metadata for inclusion in the response.
export const getConnectionInfo = (connectionId?: string): { connectionId: string; endpoint: string; databaseId: string; allowModifications: boolean; pid: number; activeConnections: string[]; registeredConnections: string[]; } => { const id = resolveConnectionId(connectionId); const connection = activeConnections.get(id); const config = registeredConnections.get(id); const { endpoint } = config ? parseConnectionString(config.connectionString) : { endpoint: 'NOT CONNECTED' }; return { connectionId: id, endpoint, databaseId: config?.databaseId || 'NOT SET', allowModifications: config?.allowModifications || false, pid: process.pid, activeConnections: Array.from(activeConnections.keys()), registeredConnections: Array.from(registeredConnections.keys()) }; };