Skip to main content
Glama

cosmosdb_container_create

Create a new container in Azure Cosmos DB to store and organize data with a specified partition key for scalable performance.

Instructions

Create a new Cosmos DB container

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
container_nameYesName of the Cosmos DB container
database_nameNoName of the Cosmos DB database (optional, defaults to 'defaultdb')
partition_keyYesPartition key definition for the container (e.g., {'paths': ['/partitionKey'], 'kind': 'Hash'})

Implementation Reference

  • Executes the cosmosdb_container_create tool by calling database.create_container with the provided container_name and partition_key.
    if name == "cosmosdb_container_create": # Renamed from table to container container = database.create_container( id=arguments["container_name"], partition_key=arguments["partition_key"] ) response = {"container_id": container.id, "created": True}
  • Defines the input schema, description, and name for the cosmosdb_container_create tool.
    Tool( name="cosmosdb_container_create", # Renamed from table to container description="Create a new Cosmos DB container", # Updated description inputSchema={ "type": "object", "properties": { "container_name": { # Renamed from table_name "type": "string", "description": "Name of the Cosmos DB container", # Updated description }, "database_name": { "type": "string", "description": "Name of the Cosmos DB database (optional, defaults to 'defaultdb')", }, "partition_key": { "type": "object", "description": "Partition key definition for the container (e.g., {'paths': ['/partitionKey'], 'kind': 'Hash'})", }, }, "required": [ "container_name", "partition_key", ], # Partition key is usually required for Cosmos DB }, ),
  • Registers the cosmosdb tools (including cosmosdb_container_create) by dispatching to handle_cosmosdb_operations in the call_tool handler.
    elif name.startswith("cosmosdb_"): # Updated prefix to cosmosdb_ return await handle_cosmosdb_operations( azure_rm, name, arguments ) # Use cosmosdb handler
  • Registers all Azure tools, including cosmosdb_container_create, via server.list_tools().
    @server.list_tools() async def list_tools() -> list[Tool]: """List available Azure tools""" logger.debug("Handling list_tools request") return get_azure_tools() # Use get_azure_tools
  • Helper function to create and cache the CosmosClient used in cosmosdb tool handlers.
    def get_cosmos_client( self, endpoint: str | None = None, key: str | None = None, url: str | None = None, ) -> CosmosClient: """Get an Azure Cosmos DB client.""" try: logger.info(f"Creating CosmosClient for endpoint: {endpoint}") url = url or os.getenv("AZURE_COSMOSDB_URL") endpoint = endpoint or os.getenv("AZURE_COSMOSDB_ENDPOINT") key = key or os.getenv("AZURE_COSMOSDB_KEY") url = str(url) if not endpoint or not key: raise ValueError( "Azure Cosmos DB Endpoint or Key is not specified and not set in the environment." ) return CosmosClient(endpoint=endpoint, credential=key, url=url) except Exception as e: logger.error(f"Failed to create CosmosClient: {e}") raise RuntimeError(f"Failed to create CosmosClient: {e}")

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/mashriram/azure_mcp_server'

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