createDatabase
Create a new CouchDB database by specifying a database name. This tool enables AI assistants to set up databases for storing and managing documents.
Instructions
Create a new CouchDB database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dbName | Yes | Database name |
Implementation Reference
- src/index.ts:257-283 (handler)The handler function for the 'createDatabase' tool. Validates the input dbName and calls the getDatabase helper to create the database if it does not exist, returning a formatted success or error response.
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, }; } } - src/index.ts:57-66 (schema)Input schema definition for the 'createDatabase' tool, requiring a 'dbName' string parameter.
inputSchema: { type: 'object', properties: { dbName: { type: 'string', description: 'Database name', }, }, required: ['dbName'], }, - src/index.ts:54-67 (registration)Registration of the 'createDatabase' tool in the ListToolsRequestSchema handler, providing name, description, and schema.
{ 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)Dispatch registration in the CallToolRequestSchema switch statement, routing 'createDatabase' calls to the handler.
case 'createDatabase': return this.handleCreateDatabase(request.params.arguments); - src/connection.ts:24-35 (helper)Helper function that gets an existing CouchDB database or creates it if not found (404), then returns the DocumentScope. This performs the core logic for database creation.
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); }