Skip to main content
Glama
robertoamoreno

CouchDB MCP Server

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
NameRequiredDescriptionDefault
dbNameYesDatabase name
docIdYesDocument ID
dataYesDocument data

Implementation Reference

  • 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, }; } }
  • 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);

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/robertoamoreno/couchdb-mcp-server'

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