getDocument
Retrieve documents from CouchDB databases by specifying database name and document ID to access stored data.
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 core handler function that implements the getDocument tool logic: validates dbName and docId, fetches the database, retrieves the document using the CouchDB client's get method, and formats the response as JSON text or handles errors.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 (registration)Registers the getDocument tool in the ListToolsRequest handler's tool list, providing its name, description, and input schema.{ 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)In the CallToolRequest handler, routes calls to the 'getDocument' tool to its specific handler method.case 'getDocument': return this.handleGetDocument(request.params.arguments);
- src/index.ts:115-128 (schema)Defines the input schema for the getDocument tool, specifying required dbName and docId as strings.inputSchema: { type: 'object', properties: { dbName: { type: 'string', description: 'Database name', }, docId: { type: 'string', description: 'Document ID', }, }, required: ['dbName', 'docId'], },