Skip to main content
Glama
andyfe76

CouchDB MCP Server

by andyfe76

couchdb_update_document

Update an existing document in a CouchDB database by specifying the database name, document ID, and revised document data including the _rev field.

Instructions

Update an existing document in a database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesName of the database
doc_idYesDocument ID
documentYesUpdated document data (must include _rev)

Implementation Reference

  • The _update_document method implements the actual logic for updating a CouchDB document. It retrieves the database, ensures the document has _id, saves it using db.save(), and handles various error cases (KeyError for missing database, ResourceConflict for revision conflicts, and general exceptions). Returns the updated document id and revision.
    async def _update_document(self, database: str, doc_id: str, document: dict) -> list[TextContent]: """Update an existing document.""" try: db = self._get_server()[database] # Ensure document has _id if "_id" not in document: document["_id"] = doc_id # Save the document saved_id, rev = db.save(document) result = { "id": saved_id, "rev": rev, "message": "Document updated successfully" } return [TextContent(type="text", text=json.dumps(result, indent=2))] except KeyError: return [TextContent(type="text", text=f"Database '{database}' not found")] except couchdb.http.ResourceConflict: return [TextContent(type="text", text="Document update conflict - document was modified, please get the latest revision")] except Exception as e: return [TextContent(type="text", text=f"Error updating document: {str(e)}")]
  • Tool schema definition for couchdb_update_document, registered in the list_tools() handler. Defines the input schema with database (string), doc_id (string), and document (object) as required fields. The document parameter note specifies it must include _rev for optimistic concurrency control.
    Tool( name="couchdb_update_document", description="Update an existing document in a database", inputSchema={ "type": "object", "properties": { "database": { "type": "string", "description": "Name of the database", }, "doc_id": { "type": "string", "description": "Document ID", }, "document": { "type": "object", "description": "Updated document data (must include _rev)", }, }, "required": ["database", "doc_id", "document"], }, ),
  • Tool routing registration in the call_tool() handler that routes the 'couchdb_update_document' tool name to its handler method _update_document(), extracting the database, doc_id, and document arguments.
    elif name == "couchdb_update_document": return await self._update_document( arguments["database"], arguments["doc_id"], arguments["document"] )

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/andyfe76/couchdb_mcp'

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