Skip to main content
Glama
robertoamoreno

CouchDB MCP Server

createDatabase

Create a new CouchDB database using a simple interface. Specify the database name to initiate the process, enabling organized data storage and management.

Instructions

Create a new CouchDB database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dbNameYesDatabase name

Implementation Reference

  • The main handler function for the 'createDatabase' tool. It validates the input database name and calls the getDatabase helper, which creates the database if it does not exist. Returns success or error message.
    private async handleCreateDatabase(args: any) { if (!args.dbName || typeof args.dbName !== 'string') { throw new McpError(ErrorCode.InvalidParams, 'Invalid database name'); } try { await getDatabase(args.dbName); return { content: [ { type: 'text', text: `Database ${args.dbName} created successfully`, }, ], }; } catch (error: any) { return { content: [ { type: 'text', text: `Error creating database: ${error.message}`, }, ], isError: true, }; } }
  • Input schema definition for the 'createDatabase' tool, specifying the required 'dbName' parameter.
    { name: 'createDatabase', description: 'Create a new CouchDB database', inputSchema: { type: 'object', properties: { dbName: { type: 'string', description: 'Database name', }, }, required: ['dbName'], }, },
  • src/index.ts:230-231 (registration)
    Registration of the 'createDatabase' tool handler in the CallToolRequestSchema switch statement.
    case 'createDatabase': return this.handleCreateDatabase(request.params.arguments);
  • Helper function that gets a database or creates it if it doesn't exist (404 error), used by the createDatabase handler.
    export async function getDatabase(dbName: string): Promise<DocumentScope<any>> { try { await couch.db.get(dbName); } catch (error: any) { if (error.statusCode === 404) { await couch.db.create(dbName); } else { throw error; } } return couch.use(dbName); }
  • src/index.ts:52-255 (registration)
    The tool is registered in the list of available tools returned by ListToolsRequestSchema, unconditionally in baseTools.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => { const baseTools = [ { name: 'createDatabase', description: 'Create a new CouchDB database', inputSchema: { type: 'object', properties: { dbName: { type: 'string', description: 'Database name', }, }, required: ['dbName'], }, }, { name: 'listDatabases', description: 'List all CouchDB databases', inputSchema: { type: 'object', properties: {}, }, }, { name: 'deleteDatabase', description: 'Delete a CouchDB database', inputSchema: { type: 'object', properties: { dbName: { type: 'string', description: 'Database name to delete', }, }, required: ['dbName'], }, }, { 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'], }, }, { name: 'getDocument', description: 'Get a document from a database', inputSchema: { type: 'object', properties: { dbName: { type: 'string', description: 'Database name', }, docId: { type: 'string', description: 'Document ID', }, }, required: ['dbName', 'docId'], }, } ]; const mangoTools = isV3Plus ? [ { name: 'createMangoIndex', description: 'Create a new Mango index (CouchDB 3.x+)', inputSchema: { type: 'object', properties: { dbName: { type: 'string', description: 'Database name', }, indexName: { type: 'string', description: 'Name of the index', }, fields: { type: 'array', items: { type: 'string' }, description: 'Fields to index', }, }, required: ['dbName', 'indexName', 'fields'], }, }, { name: 'deleteMangoIndex', description: 'Delete a Mango index (CouchDB 3.x+)', inputSchema: { type: 'object', properties: { dbName: { type: 'string', description: 'Database name', }, designDoc: { type: 'string', description: 'Design document name', }, indexName: { type: 'string', description: 'Name of the index', }, }, required: ['dbName', 'designDoc', 'indexName'], }, }, { name: 'listMangoIndexes', description: 'List all Mango indexes in a database (CouchDB 3.x+)', inputSchema: { type: 'object', properties: { dbName: { type: 'string', description: 'Database name', }, }, required: ['dbName'], }, }, { name: 'findDocuments', description: 'Query documents using Mango query (CouchDB 3.x+)', inputSchema: { type: 'object', properties: { dbName: { type: 'string', description: 'Database name', }, query: { type: 'object', description: 'Mango query object', }, }, required: ['dbName', 'query'], }, } ] : []; return { tools: [...baseTools, ...mangoTools] }; }); // Handle tool calls this.server.setRequestHandler(CallToolRequestSchema, async (request) => { // Version check for Mango query tools if (!isV3Plus && ['createMangoIndex', 'deleteMangoIndex', 'listMangoIndexes', 'findDocuments'].includes(request.params.name)) { throw new McpError( ErrorCode.MethodNotFound, `Tool ${request.params.name} requires CouchDB 3.x or higher` ); } switch (request.params.name) { case 'createDatabase': return this.handleCreateDatabase(request.params.arguments); case 'listDatabases': return this.handleListDatabases(); case 'deleteDatabase': return this.handleDeleteDatabase(request.params.arguments); case 'createDocument': return this.handleCreateDocument(request.params.arguments); case 'getDocument': return this.handleGetDocument(request.params.arguments); case 'createMangoIndex': return this.handleCreateMangoIndex(request.params.arguments); case 'deleteMangoIndex': return this.handleDeleteMangoIndex(request.params.arguments); case 'listMangoIndexes': return this.handleListMangoIndexes(request.params.arguments); case 'findDocuments': return this.handleFindDocuments(request.params.arguments); default: throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}` ); } }); }

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