createDocument
Create or update documents in CouchDB databases using specified document IDs and data to store or modify information.
Instructions
Create a new document or update an existing document in a database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dbName | Yes | Database name | |
| docId | Yes | Document ID | |
| data | Yes | Document data |
Implementation Reference
- src/index.ts:337-369 (handler)The handler function that executes the createDocument tool. It validates input parameters, retrieves the CouchDB database instance, inserts or updates the document using the nano client's insert method, determines if it was created or updated based on _rev, and returns a success or error message in the MCP content format.private async handleCreateDocument(args: any) { if (!args.dbName || !args.docId || !args.data) { throw new McpError( ErrorCode.InvalidParams, 'Missing required parameters: dbName, docId, data' ); } try { const db = await getDatabase(args.dbName); const response = await db.insert(args.data, args.docId); const action = args.data._rev ? 'updated' : 'created'; return { content: [ { type: 'text', text: `Document ${action} with ID: ${response.id}, rev: ${response.rev}`, }, ], }; } catch (error: any) { const action = args.data._rev ? 'updating' : 'creating'; return { content: [ { type: 'text', text: `Error ${action} document: ${error.message}`, }, ], isError: true, }; } }
- src/index.ts:93-110 (schema)The input schema definition for the createDocument tool, specifying the required properties: dbName (string), docId (string), and data (object).inputSchema: { type: 'object', properties: { dbName: { type: 'string', description: 'Database name', }, docId: { type: 'string', description: 'Document ID', }, data: { type: 'object', description: 'Document data', }, }, required: ['dbName', 'docId', 'data'], },
- src/index.ts:90-111 (registration)The registration of the createDocument tool in the ListToolsRequest handler, providing name, description, and input schema.{ name: 'createDocument', description: 'Create a new document or update an existing document in a database', inputSchema: { type: 'object', properties: { dbName: { type: 'string', description: 'Database name', }, docId: { type: 'string', description: 'Document ID', }, data: { type: 'object', description: 'Document data', }, }, required: ['dbName', 'docId', 'data'], }, },
- src/index.ts:236-237 (registration)The dispatch case in the CallToolRequest handler that routes calls to the createDocument handler method.case 'createDocument': return this.handleCreateDocument(request.params.arguments);