Skip to main content
Glama
robertoamoreno

CouchDB MCP Server

createDocument

Add or update documents in a CouchDB database by specifying the database name, document ID, and data. Simplifies database interactions for AI assistants using TypeScript-based MCP servers.

Instructions

Create a new document or update an existing document in a database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYesDocument data
dbNameYesDatabase name
docIdYesDocument ID

Implementation Reference

  • The handler function that validates input parameters, retrieves the database instance, inserts the document using nano's insert method (handles create/update), and returns success or error message.
    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 defining the parameters for the createDocument tool: dbName, docId, and data object.
    { 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 switch case in the CallToolRequestSchema handler that routes createDocument calls to the handler method.
    case 'createDocument': return this.handleCreateDocument(request.params.arguments);

Other Tools

Related Tools

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