load_json_doc_from_db
Retrieve a JSON document by specifying its ID and the database name for efficient data access and management in the MCP environment.
Instructions
Load a JSON document by ID from a document database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| databaseName | No | name of document database to load from | |
| id | Yes | ID of document to load |
Implementation Reference
- src/index.ts:434-458 (handler)Handler function for the 'load_json_doc_from_db' tool. It validates input arguments using LoadJsonDocFromDbArgsSchema, ensures the database exists (creating it if necessary), retrieves the document by ID using db.get(), logs it, and returns the document as a JSON string in the tool response format.case "load_json_doc_from_db": { const parsed = LoadJsonDocFromDbArgsSchema.safeParse(args); if (!parsed.success) { throw new Error(`Invalid arguments for load_json_doc_from_db: ${parsed.error}`); } const dbName = parsed.data.databaseName; if (!dbs[dbName]) { const newDb = fireproof(dbName); dbs[dbName] = { db: newDb }; } const db = dbs[dbName].db; const doc = await db.get(parsed.data.id); console.error("doc", doc); return { content: [ { type: "text", text: JSON.stringify(doc), }, ], }; }
- src/index.ts:83-86 (schema)Zod schema defining the input arguments for the 'load_json_doc_from_db' tool: databaseName (string) and id (string). Used for validation in the handler.const LoadJsonDocFromDbArgsSchema = z.object({ databaseName: z.string(), id: z.string(), });
- src/index.ts:153-170 (registration)Registration of the 'load_json_doc_from_db' tool in the listTools response. Includes name, description, and a hardcoded JSON schema for input (noted comment for Zod conversion).{ name: "load_json_doc_from_db", description: "Load a JSON document by ID from a document database", inputSchema: { type: "object", properties: { id: { type: "string", description: "ID of document to load", }, databaseName: { type: "string", description: "name of document database to load from", }, }, // properties: zodToJsonSchema(LoadJsonDocFromDbArgsSchema), required: ["id"], },