update_project_entry
Modify existing project-specific knowledge entries by editing query, solution, or category fields in the Hivemind MCP server.
Instructions
Update an existing project hive entry. Can edit query, solution, or category. Only works for project entries (not global hivemind KB).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | No | Optional: User ID (auto-detected from .user_id in cwd if not provided) | |
| entry_id | Yes | ID of the entry to update (from search results) | |
| query | No | Optional: New query text | |
| solution | No | Optional: New solution text | |
| category | No | Optional: New category name | |
| project_path | No | Optional: Project directory path (required for local storage) |
Implementation Reference
- src/api.ts:572-633 (handler)Core handler function that executes the update_project_entry tool logic. Supports both local file-based storage (.hive.json) and cloud Supabase storage by updating the specified entry's fields (query, solution, or category). Auto-detects user_id from .user_id file.export async function updateProjectEntry( userId: string | null, entryId: number, updates: { query?: string; solution?: string; category?: string; }, projectPath?: string ): Promise<{ success: boolean; message: string }> { // Auto-detect user_id if not provided if (!userId) { userId = await getUserId(projectPath); if (!userId) { throw new Error('No .user_id file found. Run init_hive first.'); } } // Check if local storage if (userId.startsWith('local-') && projectPath) { const hive = await readLocalHive(projectPath); if (!hive) { throw new Error('Local hive not found'); } const entryIndex = hive.entries.findIndex(e => e.id === entryId); if (entryIndex === -1) { throw new Error(`Entry ${entryId} not found in local hive`); } // Apply updates if (updates.query) hive.entries[entryIndex].query = updates.query; if (updates.solution) hive.entries[entryIndex].solution = updates.solution; if (updates.category) hive.entries[entryIndex].category = updates.category; await writeLocalHive(projectPath, hive); return { success: true, message: `Updated entry ${entryId} in local hive` }; } // Cloud storage - use API const response = await fetch(`${API_BASE}/update-project-entry`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: userId, entry_id: entryId, ...updates }), }); if (!response.ok) { throw new Error(`Update entry failed: ${response.statusText}`); } return response.json(); }
- src/index.ts:482-496 (registration)MCP server dispatcher for the tool call. Receives parameters from MCP CallToolRequestSchema, invokes the updateProjectEntry handler, and formats response as MCP content.case "update_project_entry": { const result = await updateProjectEntry( args?.user_id as string, args?.entry_id as number, { query: args?.query as string | undefined, solution: args?.solution as string | undefined, category: args?.category as string | undefined, }, args?.project_path as string | undefined ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }
- src/index.ts:296-330 (schema)Tool schema definition including name, description, and input schema validation. Registered in ListToolsRequestHandler.{ name: "update_project_entry", description: "Update an existing project hive entry. Can edit query, solution, or category. Only works for project entries (not global hivemind KB).", inputSchema: { type: "object", properties: { user_id: { type: "string", description: "Optional: User ID (auto-detected from .user_id in cwd if not provided)", }, entry_id: { type: "number", description: "ID of the entry to update (from search results)", }, query: { type: "string", description: "Optional: New query text", }, solution: { type: "string", description: "Optional: New solution text", }, category: { type: "string", description: "Optional: New category name", }, project_path: { type: "string", description: "Optional: Project directory path (required for local storage)", }, }, required: ["entry_id"], }, },
- Supabase Edge Function handler for cloud storage backend. Updates the 'knowledge_entries' table row for project entries, ensuring ownership and project scope.async function handleUpdateProjectEntry(supabase: any, body: any, corsHeaders: any) { const { user_id, entry_id, query, solution, category } = body; if (!user_id || !entry_id) { return new Response(JSON.stringify({ error: 'user_id and entry_id required' }), { status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }); } // Build update object const updates: any = {}; if (query !== undefined) updates.query = query; if (solution !== undefined) { // Convert solution string to JSONB array format (field name is 'solutions' plural) updates.solutions = [{ solution, success_rate: null, command: null, note: null }]; } if (category !== undefined) updates.category = category; if (Object.keys(updates).length === 0) { return new Response(JSON.stringify({ error: 'No updates provided' }), { status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }); } // Update entry (must be owned by user AND be a project entry) const { data, error } = await supabase .from('knowledge_entries') .update(updates) .eq('id', entry_id) .eq('user_id', user_id) .not('project_id', 'is', null) // Must be a project entry .select() .single(); if (error) { console.error('Update entry error:', error); return new Response(JSON.stringify({ success: false, error: error.message || 'Failed to update entry' }), { status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }); } if (!data) { return new Response(JSON.stringify({ success: false, error: 'Entry not found or not authorized to edit' }), { status: 404, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }); } return new Response(JSON.stringify({ success: true, message: `Updated entry ${entry_id}`, entry: data, _ctx: "Hive accuracy improves with edits. Keep it current for maximum value." }), { headers: { ...corsHeaders, 'Content-Type': 'application/json' } }); }