save_json_doc_to_db
Store JSON documents in a document database for persistent storage, enabling data management and retrieval within the MCP JSON Document Collection Server.
Instructions
Save a JSON document to a document database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doc | Yes | JSON document to save | |
| databaseName | Yes | document database to save to |
Implementation Reference
- src/index.ts:375-404 (handler)Handler for the 'save_json_doc_to_db' tool: validates args with schema, ensures DB exists, saves the JSON doc to Fireproof DB with timestamp, returns saved ID.case "save_json_doc_to_db": { const parsed = SaveJsonDocToDbArgsSchema.safeParse(args); if (!parsed.success) { throw new Error(`Invalid arguments for save_json_doc_to_db: ${parsed.error}`); } const doc = request.params.arguments?.doc; if (!doc) { throw new Error("Document is required"); } const dbName = parsed.data.databaseName; if (!dbs[dbName]) { const newDb = fireproof(dbName); dbs[dbName] = { db: newDb }; } const db = dbs[dbName].db; const response = await db.put({ ...doc, created: Date.now(), }); return { content: [ { type: "text", text: `Saved document with ID: ${response.id} to database: ${dbName}`, } ] } }
- src/index.ts:73-76 (schema)Zod schema defining input for save_json_doc_to_db: databaseName (string), doc (any object).const SaveJsonDocToDbArgsSchema = z.object({ databaseName: z.string(), doc: z.object({}) });
- src/index.ts:128-145 (registration)Tool registration in listTools handler: defines name, description, and JSON input schema for save_json_doc_to_db.{ name: "save_json_doc_to_db", description: "Save a JSON document to a document database", inputSchema: { type: "object", properties: { doc: { type: "object", description: "JSON document to save", }, databaseName: { type: "string", description: "document database to save to", }, }, required: ["doc", "databaseName"], }, },