Skip to main content
Glama

Convex MCP server

Official
by get-convex
addDocument.ts1.32 kB
import { GenericDocument } from "convex/server"; import { mutationGeneric } from "../server"; import { ConvexError, v } from "convex/values"; const MAX_IMPORT_COUNT = 4096; // TRANSACTION_MAX_NUM_USER_WRITES / 2 export default mutationGeneric({ args: { componentId: v.optional(v.union(v.string(), v.null())), table: v.string(), documents: v.array(v.any()), }, handler: async ( { db }, args, ): Promise<{ success: false; error: string } | { success: true }> => { const { table } = args; const documents = args.documents as GenericDocument[]; if (documents.length > MAX_IMPORT_COUNT) { return { success: false, error: `Can’t import more than ${MAX_IMPORT_COUNT} documents at once.`, }; } const insertedIds = []; try { for (const document of documents) { const id = await db.insert(table, document); insertedIds.push(id); } } catch (e: any) { // Revert the documents previously inserted since we return // a result and thus make the transaction commit. for (const id of insertedIds) { await db.delete(id); } // Rewrapping this error because it could be a schema validation error. throw new ConvexError(e.message); } return { success: true }; }, });

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/get-convex/convex-backend'

If you have feedback or need assistance with the MCP directory API, please join our Discord server