getDocument
Retrieve specific documents from a CouchDB database by providing the database name and document ID using this MCP server tool.
Instructions
Get a document from a database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dbName | Yes | Database name | |
| docId | Yes | Document ID |
Implementation Reference
- src/index.ts:371-401 (handler)The handler function that validates input parameters, retrieves the database instance using getDatabase, fetches the document using the CouchDB client's get method, and returns the document as JSON or an error message.private async handleGetDocument(args: any) { if (!args.dbName || !args.docId) { throw new McpError( ErrorCode.InvalidParams, 'Missing required parameters: dbName, docId' ); } try { const db = await getDatabase(args.dbName); const doc = await db.get(args.docId); return { content: [ { type: 'text', text: JSON.stringify(doc, null, 2), }, ], }; } catch (error: any) { return { content: [ { type: 'text', text: `Error retrieving document: ${error.message}`, }, ], isError: true, }; } }
- src/index.ts:112-129 (schema)Defines the tool's metadata including name, description, and input schema specifying required dbName and docId parameters.{ 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'], }, }
- src/index.ts:238-239 (registration)Registers the tool handler in the switch statement for CallToolRequestSchema, dispatching getDocument calls to handleGetDocument.case 'getDocument': return this.handleGetDocument(request.params.arguments);