Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Create Convex queries, mutations, and actions with proper validation, authentication, and error handling. Use when implementing new API endpoints.
.claude/skills/kunanonj-cursor-plugin-convex-function-creator/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 162% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 155% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 85% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 80% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 167% | 0% |
Generate secure, type-safe Convex functions following all best practices.
typescriptimport { query } from "./_generated/server"; import { v } from "convex/values"; export const getTask = query({ args: { taskId: v.id("tasks") }, returns: v.union(v.object({ _id: v.id("tasks"), text: v.string(), completed: v.boolean(), }), v.null()), handler: async (ctx, args) => { return await ctx.db.get(args.taskId); }, });
typescriptimport { mutation } from "./_generated/server"; import { v } from "convex/values"; export const createTask = mutation({ args: { text: v.string(), priority: v.optional(v.union( v.literal("low"), v.literal("medium"), v.literal("high") )), }, returns: v.id("tasks"), handler: async (ctx, args) => { const identity = await ctx.auth.getUserIdentity(); if (!identity) throw new Error("Not authenticated"); return await ctx.db.insert("tasks", { text: args.text, priority: args.priority ?? "medium", completed: false, createdAt: Date.now(), }); }, });
ctx.runMutation"use node" directive when needing Node.js APIsImportant: If your action needs Node.js-specific APIs (crypto, third-party SDKs, etc.), add "use node" at the top of the file. Files with "use node" can ONLY contain actions, not queries or mutations.
typescript"use node"; // Required for Node.js APIs like OpenAI SDK import { action } from "./_generated/server"; import { api } from "./_generated/api"; import { v } from "convex/values"; import OpenAI from "openai"; const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); export const generateTaskSuggestion = action({ args: { prompt: v.string() }, returns: v.string(), handler: async (ctx, args) => { const identity = await ctx.auth.getUserIdentity(); if (!identity) throw new Error("Not authenticated"); // Call OpenAI (requires "use node") const completion = await openai.chat.completions.create({ model: "gpt-4", messages: [{ role: "user", content: args.prompt }], }); const suggestion = completion.choices[0].message.content; // Write to database via mutation await ctx.runMutation(api.tasks.createTask, { text: suggestion, }); return suggestion; }, });
Note: If you only need basic fetch (no Node.js APIs), you can omit "use node". But for third-party SDKs, crypto, or other Node.js features, you must use it.
Always define args with validators:
typescriptargs: { id: v.id("tasks"), text: v.string(), count: v.number(), enabled: v.boolean(), tags: v.array(v.string()), metadata: v.optional(v.object({ key: v.string(), })), }
Always define returns:
typescriptreturns: v.object({ _id: v.id("tasks"), text: v.string(), }) // Or for arrays returns: v.array(v.object({ /* ... */ })) // Or for nullable returns: v.union(v.object({ /* ... */ }), v.null())
Always verify auth in public functions:
typescriptconst identity = await ctx.auth.getUserIdentity(); if (!identity) { throw new Error("Not authenticated"); }
Always verify ownership/permissions:
typescriptconst task = await ctx.db.get(args.taskId); if (!task) { throw new Error("Task not found"); } if (task.userId !== user._id) { throw new Error("Unauthorized"); }
typescriptexport const getMyTasks = query({ args: { status: v.optional(v.union( v.literal("active"), v.literal("completed") )), }, returns: v.array(v.object({ _id: v.id("tasks"), text: v.string(), completed: v.boolean(), })), handler: async (ctx, args) => { const identity = await ctx.auth.getUserIdentity(); if (!identity) throw new Error("Not authenticated"); const user = await ctx.db .query("users") .withIndex("by_token", q => q.eq("tokenIdentifier", identity.tokenIdentifier) ) .unique(); if (!user) throw new Error("User not found"); let query = ctx.db .query("tasks") .withIndex("by_user", q => q.eq("userId", user._id)); const tasks = await query.collect(); if (args.status) { return tasks.filter(t => args.status === "completed" ? t.completed : !t.completed ); } return tasks; }, });
typescriptexport const updateTask = mutation({ args: { taskId: v.id("tasks"), text: v.optional(v.string()), completed: v.optional(v.boolean()), }, returns: v.id("tasks"), handler: async (ctx, args) => { // 1. Authentication const identity = await ctx.auth.getUserIdentity(); if (!identity) throw new Error("Not authenticated"); // 2. Get user const user = await ctx.db .query("users") .withIndex("by_token", q => q.eq("tokenIdentifier", identity.tokenIdentifier) ) .unique(); if (!user) throw new Error("User not found"); // 3. Get resource const task = await ctx.db.get(args.taskId); if (!task) throw new Error("Task not found"); // 4. Authorization if (task.userId !== user._id) { throw new Error("Unauthorized"); } // 5. Update const updates: Partial<typeof task> = {}; if (args.text !== undefined) updates.text = args.text; if (args.completed !== undefined) updates.completed = args.completed; await ctx.db.patch(args.taskId, updates); return args.taskId; }, });
Create separate file for actions that need Node.js:
typescript// convex/taskActions.ts "use node"; // Required for SendGrid SDK import { action } from "./_generated/server"; import { api } from "./_generated/api"; import { v } from "convex/values"; import sendgrid from "@sendgrid/mail"; sendgrid.setApiKey(process.env.SENDGRID_API_KEY); export const sendTaskReminder = action({ args: { taskId: v.id("tasks") }, returns: v.boolean(), handler: async (ctx, args) => { // 1. Auth const identity = await ctx.auth.getUserIdentity(); if (!identity) throw new Error("Not authenticated"); // 2. Get data via query const task = await ctx.runQuery(api.tasks.getTask, { taskId: args.taskId, }); if (!task) throw new Error("Task not found"); // 3. Call external service (using Node.js SDK) await sendgrid.send({ to: identity.email, from: "noreply@example.com", subject: "Task Reminder", text: `Don't forget: ${task.text}`, }); // 4. Update via mutation await ctx.runMutation(api.tasks.markReminderSent, { taskId: args.taskId, }); return true; }, });
Note: Keep queries and mutations in convex/tasks.ts (without "use node"), and actions that need Node.js in convex/taskActions.ts (with "use node").
For backend-only functions (called by scheduler, other functions):
typescriptimport { internalMutation } from "./_generated/server"; export const processExpiredTasks = internalMutation({ args: {}, handler: async (ctx) => { // No auth needed - only callable from backend const now = Date.now(); const expired = await ctx.db .query("tasks") .withIndex("by_due_date", q => q.lt("dueDate", now)) .collect(); for (const task of expired) { await ctx.db.patch(task._id, { status: "expired" }); } }, });
args defined with validatorsreturns defined with validatorctx.auth.getUserIdentity()).filter() on queries)internal.* not api.*"use node" at top of file"use node": Only actions (no queries/mutations)| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 7,085 | 7,522 | +6% | 1 | 1 | 0% | 1,694 | 4,430 | +162% | 0 | 0 | — |
case-22 | pass→pass | 6,784 | 7,648 | +13% | 1 | 1 | 0% | 1,529 | 4,353 | +185% | 0 | 0 | — |
case-02 | fail→pass | 6,178 | 5,023 | -19% | 1 | 1 | 0% | 1,475 | 3,759 | +155% | 0 | 0 | — |
case-03 | fail→pass | 10,315 | 7,747 | -25% | 1 | 1 | 0% | 2,594 | 4,790 | +85% | 0 | 0 | — |
case-04 | fail→pass | 11,085 | 5,918 | -47% | 1 | 1 | 0% | 2,243 | 4,029 | +80% | 0 | 0 | — |
case-05 | fail→pass | 7,528 | 7,221 | -4% | 1 | 1 | 0% | 1,629 | 4,357 | +167% | 0 | 0 | — |
case-06 | pass→pass | 7,771 | 5,360 | -31% | 1 | 1 | 0% | 1,853 | 3,795 | +105% | 0 | 0 | — |
case-07 | pass→pass | 8,904 | 7,691 | -14% | 1 | 1 | 0% | 2,105 | 4,346 | +106% | 0 | 0 | — |
case-08 | pass→pass | 7,674 | 5,488 | -28% | 1 | 1 | 0% | 1,741 | 3,851 | +121% | 0 | 0 | — |
case-09 | pass→pass | 5,256 | 5,720 | +9% | 1 | 1 | 0% | 1,179 | 4,014 | +240% | 0 | 0 | — |
case-10 | fail→pass | 8,110 | 7,889 | -3% | 1 | 1 | 0% | 1,651 | 4,224 | +156% | 0 | 0 | — |
case-11 | pass→pass | 6,746 | 5,646 | -16% | 1 | 1 | 0% | 1,621 | 3,825 | +136% | 0 | 0 | — |
case-12 | fail→pass | 4,908 | 5,125 | +4% | 1 | 1 | 0% | 1,127 | 3,890 | +245% | 0 | 0 | — |
case-13 | fail→pass | 3,917 | 4,365 | +11% | 1 | 1 | 0% | 900 | 3,621 | +302% | 0 | 0 | — |
case-14 | pass→pass | 7,208 | 9,134 | +27% | 1 | 1 | 0% | 1,594 | 4,195 | +163% | 0 | 0 | — |
case-15 | pass→pass | 8,754 | 8,752 | -0% | 1 | 1 | 0% | 2,037 | 4,447 | +118% | 0 | 0 | — |
case-16 | fail→pass | 9,182 | 6,836 | -26% | 1 | 1 | 0% | 2,056 | 4,036 | +96% | 0 | 0 | — |
case-17 | pass→pass | 4,884 | 6,573 | +35% | 1 | 1 | 0% | 1,015 | 4,261 | +320% | 0 | 0 | — |
case-18 | pass→pass | 5,657 | 4,299 | -24% | 1 | 1 | 0% | 1,183 | 3,324 | +181% | 0 | 0 | — |
case-19 | pass→pass | 8,007 | 7,914 | -1% | 1 | 1 | 0% | 1,770 | 4,314 | +144% | 0 | 0 | — |
case-20 | pass→pass | 5,729 | 4,155 | -27% | 1 | 1 | 0% | 1,181 | 3,527 | +199% | 0 | 0 | — |
case-21 | pass→pass | 7,181 | 6,542 | -9% | 1 | 1 | 0% | 1,608 | 4,108 | +155% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +41 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.