couchdb_create_index
Create indexes in CouchDB to improve Mango query performance and ensure reliable results by specifying database and fields to index.
Instructions
Create an index to improve Mango query performance. While optional, indexes dramatically speed up queries and ensure reliable results.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | Name of the database | |
| fields | Yes | Fields to index (e.g., ['type', 'name']) | |
| index_name | No | Optional name for the index |
Implementation Reference
- couchdb_mcp_server.py:516-546 (handler)The _create_index method is the actual handler implementation that creates an index in CouchDB using the _index endpoint. It accepts database name, list of fields, and optional index name, then posts the index specification to CouchDB and returns the result.async def _create_index(self, database: str, fields: list, index_name: str | None = None) -> list[TextContent]: """Create an index for Mango queries.""" try: db = self._get_server()[database] # Build index specification index_spec = { "index": { "fields": fields }, "type": "json" } if index_name: index_spec["name"] = index_name # Create the index result = db.resource.post_json('_index', body=index_spec) response = { "result": result[1].get("result"), "id": result[1].get("id"), "name": result[1].get("name"), "message": f"Index created successfully on fields: {fields}" } return [TextContent(type="text", text=json.dumps(response, indent=2))] except KeyError: return [TextContent(type="text", text=f"Database '{database}' not found")] except Exception as e: return [TextContent(type="text", text=f"Error creating index: {str(e)}")]
- couchdb_mcp_server.py:223-245 (schema)Tool registration schema definition for couchdb_create_index. Defines the input schema with required 'database' and 'fields' parameters, and optional 'index_name' parameter. The description emphasizes that indexes improve query performance.Tool( name="couchdb_create_index", description="Create an index to improve Mango query performance. While optional, indexes dramatically speed up queries and ensure reliable results.", inputSchema={ "type": "object", "properties": { "database": { "type": "string", "description": "Name of the database", }, "fields": { "type": "array", "items": {"type": "string"}, "description": "Fields to index (e.g., ['type', 'name'])", }, "index_name": { "type": "string", "description": "Optional name for the index", }, }, "required": ["database", "fields"], }, ),
- couchdb_mcp_server.py:308-313 (registration)Registration point in the call_tool method that maps the tool name 'couchdb_create_index' to its handler function _create_index, extracting the database, fields, and optional index_name arguments.elif name == "couchdb_create_index": return await self._create_index( arguments["database"], arguments["fields"], arguments.get("index_name") )