couchdb_create_document
Create new documents in CouchDB databases by specifying database name and JSON document data, with optional custom document ID.
Instructions
Create a new document in a database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | Name of the database | |
| document | Yes | Document data as JSON object | |
| doc_id | No | Optional document ID (if not provided, CouchDB generates one) |
Implementation Reference
- couchdb_mcp_server.py:347-365 (handler)The actual handler implementation that creates a document in CouchDB. It accepts a database name, document data, and optional document ID. Uses db.save() to create the document, merging the doc_id if provided.async def _create_document(self, database: str, document: dict, doc_id: str | None = None) -> list[TextContent]: """Create a new document.""" try: db = self._get_server()[database] if doc_id: doc_id, rev = db.save({"_id": doc_id, **document}) else: doc_id, rev = db.save(document) result = { "id": doc_id, "rev": rev, "message": "Document created successfully" } return [TextContent(type="text", text=json.dumps(result, 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 document: {str(e)}")]
- couchdb_mcp_server.py:91-112 (schema)Tool schema registration defining the input structure for couchdb_create_document. Requires 'database' and 'document' parameters, with optional 'doc_id'.Tool( name="couchdb_create_document", description="Create a new document in a database", inputSchema={ "type": "object", "properties": { "database": { "type": "string", "description": "Name of the database", }, "document": { "type": "object", "description": "Document data as JSON object", }, "doc_id": { "type": "string", "description": "Optional document ID (if not provided, CouchDB generates one)", }, }, "required": ["database", "document"], }, ),
- couchdb_mcp_server.py:272-277 (registration)Tool call routing that maps the 'couchdb_create_document' tool name to its handler method, extracting arguments from the request.elif name == "couchdb_create_document": return await self._create_document( arguments["database"], arguments["document"], arguments.get("doc_id") )