Implementation:0xK3vin MegaMemory MCP Tools Merge
| Knowledge Sources | |
|---|---|
| Domains | Knowledge_Graph, Merge_Conflict_Resolution, MCP |
| Last Updated | 2026-10-27 12:00 GMT |
Overview
Concrete tool handlers for listing and AI-assisted resolution of knowledge graph merge conflicts provided by the MegaMemory MCP server.
Description
The MCP Tools Merge handlers (src/tools.ts) implement the two MCP tools that operate on merge conflicts: listConflicts and resolveConflict. These are distinct from the manual megamemory resolve --keep CLI: the MCP resolveConflict path is AI-assisted — the agent verifies the resolved content against the current codebase rather than blindly picking a side, then writes a single resolved concept back over the original ID.
Key handlers:
- listConflicts — reads all nodes with needs_merge = 1, groups them by merge_group, and returns each version with its edges and file refs
- resolveConflict — within a single transaction: deletes all conflict copies except a chosen base, renames the base to the original clean ID, applies the agent-verified summary/why/file_refs, regenerates the embedding, and clears merge flags on the node and its edges
Usage
Import these handlers when you need to:
- View conflicts after a merge: call listConflicts to enumerate unresolved merge_group UUIDs and their ::left/::right versions
- Resolve a conflict (AI-assisted): call resolveConflict with a verified summary and a reason; the agent is expected to inspect the codebase to confirm the resolved content
Code Reference
Source Location
- Repository: 0xK3vin_MegaMemory
- File: src/tools.ts
- Key functions:
- listConflicts: L303-352
- resolveConflict: L354-410
Signature
export function listConflicts(db: KnowledgeDB): ListConflictsOutput;
// ListConflictsOutput = { conflicts: ConflictGroup[] }
// ConflictGroup = { merge_group: string; merge_timestamp: string | null; versions: ConflictVersion[] }
export async function resolveConflict(
db: KnowledgeDB,
input: ResolveConflictInput
): Promise<{ message: string }>;
// ResolveConflictInput = {
// merge_group: string;
// resolved: { summary: string; why?: string; file_refs?: string[] };
// reason: string;
// }
Import
import { listConflicts, resolveConflict } from "./tools.js";
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| db | KnowledgeDB | Yes | Merged output DB containing conflict nodes |
| merge_group | string | Yes (resolveConflict) | UUID from listConflicts identifying the conflict group |
| resolved.summary | string | Yes (resolveConflict) | Agent-verified summary to write |
| resolved.why | string | No | Rationale |
| resolved.file_refs | string[] | No | File paths |
| reason | string | Yes (resolveConflict) | Why this resolution is correct (logged) |
Outputs
| Name | Type | Description |
|---|---|---|
| listConflicts() returns | ListConflictsOutput | { conflicts: [] } when fully resolved |
| resolveConflict() returns | { message } | Resolved "id". Reason: ... |
| Side effects | DB writes (transactional) | Deletes losing copies, renames base, applies content, regenerates embedding, clears merge flags |
Usage Examples
List Unresolved Conflicts
import { listConflicts } from "./tools.js";
const { conflicts } = listConflicts(db);
if (conflicts.length === 0) {
console.log("No unresolved conflicts.");
return;
}
for (const group of conflicts) {
console.log(`Conflict group: ${group.merge_group}`);
for (const v of group.versions) {
console.log(` ${v.source_branch}: ${v.summary}`);
}
}
AI-Assisted Resolution
import { resolveConflict } from "./tools.js";
// The agent inspected the codebase and confirmed the correct summary
await resolveConflict(db, {
merge_group: "a1b2c3d4-...",
resolved: {
summary: "Two-pass graph merge with conflict tracking and edge remapping",
why: "SQLite DBs are unmergeable by git; structured merge prevents data loss",
file_refs: ["src/merge.ts"],
},
reason: "Verified against src/merge.ts: the two-pass algorithm remaps edges by origin side",
});
// => { message: 'Resolved "merge-engine". Reason: Verified against ...' }
Related Pages
Implements Principle
- Principle:0xK3vin_MegaMemory_Knowledge_Graph_Merge
- Principle:0xK3vin_MegaMemory_Merge_Conflict_Resolution