memoryai-mcp 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +92 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34,7 +34,7 @@ function err(e) {
|
|
|
34
34
|
return { content: [{ type: "text", text: `Error: ${msg}` }], isError: true };
|
|
35
35
|
}
|
|
36
36
|
// --- MCP Server ---
|
|
37
|
-
const server = new McpServer({ name: "memoryai", version: "0.
|
|
37
|
+
const server = new McpServer({ name: "memoryai", version: "0.5.0" }, { capabilities: { tools: {} } });
|
|
38
38
|
// 1. memory_store
|
|
39
39
|
server.tool("memory_store", "Store information in persistent memory. Use when you learn something important — project context, user preferences, architectural decisions, patterns, or bugs.", {
|
|
40
40
|
content: z.string().describe("What to remember"),
|
|
@@ -700,6 +700,97 @@ server.tool("memory_clusters", "View memory topic clusters — groups of related
|
|
|
700
700
|
return err(e);
|
|
701
701
|
}
|
|
702
702
|
});
|
|
703
|
+
// 24. session_handoff_start
|
|
704
|
+
server.tool("session_handoff_start", "Start a session handoff — save old session conversation to MemoryAI server for new session to read. Use when context window is filling up and you need to switch sessions without losing context.", {
|
|
705
|
+
conversation: z.array(z.object({
|
|
706
|
+
role: z.string().describe("Message role: user, assistant, system"),
|
|
707
|
+
content: z.string().describe("Message content"),
|
|
708
|
+
timestamp: z.string().optional().describe("ISO timestamp"),
|
|
709
|
+
})).describe("Last N conversation turns from this session"),
|
|
710
|
+
metadata: z.record(z.string(), z.unknown()).optional().describe("Session metadata (platform, model, session_id)"),
|
|
711
|
+
}, async (args) => {
|
|
712
|
+
try {
|
|
713
|
+
const r = (await api("POST", "/v1/session/handoff/start", {
|
|
714
|
+
conversation: args.conversation,
|
|
715
|
+
metadata: args.metadata,
|
|
716
|
+
}));
|
|
717
|
+
return ok(`Handoff started (id=${r.handoff_id}): ${r.turns_stored} turns stored. New session can call session_handoff_restore to get this context.`);
|
|
718
|
+
}
|
|
719
|
+
catch (e) {
|
|
720
|
+
return err(e);
|
|
721
|
+
}
|
|
722
|
+
});
|
|
723
|
+
// 25. session_handoff_restore
|
|
724
|
+
server.tool("session_handoff_restore", "Restore old session conversation + related MemoryAI memories for a new session. Call this at the start of a new session to pick up where the old session left off — zero context loss.", {
|
|
725
|
+
handoff_id: z.string().optional().describe("Specific handoff ID, or omit for latest"),
|
|
726
|
+
include_memories: z.boolean().optional().describe("Also include related MemoryAI memories (default: true)"),
|
|
727
|
+
memory_limit: z.number().optional().describe("Max related memories to include (default: 5)"),
|
|
728
|
+
}, async (args) => {
|
|
729
|
+
try {
|
|
730
|
+
const body = {
|
|
731
|
+
include_memories: args.include_memories !== false,
|
|
732
|
+
memory_limit: args.memory_limit || 5,
|
|
733
|
+
};
|
|
734
|
+
if (args.handoff_id)
|
|
735
|
+
body.handoff_id = args.handoff_id;
|
|
736
|
+
const r = (await api("POST", "/v1/session/handoff/restore", body));
|
|
737
|
+
if (r.status === "not_found")
|
|
738
|
+
return ok("No pending handoff found.");
|
|
739
|
+
const conv = (r.conversation || [])
|
|
740
|
+
.slice(-20)
|
|
741
|
+
.map((t) => `[${t.role}] ${t.content?.substring(0, 300) || ""}`)
|
|
742
|
+
.join("\n\n");
|
|
743
|
+
const mems = (r.memories || [])
|
|
744
|
+
.map((m) => `[${((m.score || 0) * 100).toFixed(0)}%] ${m.content?.substring(0, 200) || ""}`)
|
|
745
|
+
.join("\n");
|
|
746
|
+
return ok(`Handoff ${r.handoff_id} restored: ${r.turns_count} turns, ${(r.memories || []).length} memories\n\n` +
|
|
747
|
+
`=== Old Session ===\n${conv}\n\n` +
|
|
748
|
+
(mems ? `=== Related Memories ===\n${mems}` : ""));
|
|
749
|
+
}
|
|
750
|
+
catch (e) {
|
|
751
|
+
return err(e);
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
// 26. session_handoff_complete
|
|
755
|
+
server.tool("session_handoff_complete", "Complete a session handoff — archive old session conversation into long-term MemoryAI storage. Call this when the new session has enough context (e.g., after working for a while).", {
|
|
756
|
+
handoff_id: z.string().optional().describe("Specific handoff ID, or omit for latest"),
|
|
757
|
+
archive_to_memory: z.boolean().optional().describe("Store old conversation as MemoryAI chunks (default: true)"),
|
|
758
|
+
}, async (args) => {
|
|
759
|
+
try {
|
|
760
|
+
const body = {
|
|
761
|
+
archive_to_memory: args.archive_to_memory !== false,
|
|
762
|
+
};
|
|
763
|
+
if (args.handoff_id)
|
|
764
|
+
body.handoff_id = args.handoff_id;
|
|
765
|
+
const r = (await api("POST", "/v1/session/handoff/complete", body));
|
|
766
|
+
if (r.status === "not_found")
|
|
767
|
+
return ok("No pending handoff found.");
|
|
768
|
+
return ok(`Handoff ${r.handoff_id} completed: ${r.chunks_archived} chunks archived to long-term memory.`);
|
|
769
|
+
}
|
|
770
|
+
catch (e) {
|
|
771
|
+
return err(e);
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
// 27. session_handoff_status
|
|
775
|
+
server.tool("session_handoff_status", "Check current session handoff status — whether there's a pending handoff and its state.", {}, async () => {
|
|
776
|
+
try {
|
|
777
|
+
const r = (await api("GET", "/v1/session/handoff/status"));
|
|
778
|
+
if (!r.handoff_id)
|
|
779
|
+
return ok("No handoffs found.");
|
|
780
|
+
return ok(`Handoff Status:\n` +
|
|
781
|
+
`- ID: ${r.handoff_id}\n` +
|
|
782
|
+
`- Active: ${r.active}\n` +
|
|
783
|
+
`- Status: ${r.status}\n` +
|
|
784
|
+
`- Turns: ${r.turns_count}\n` +
|
|
785
|
+
`- Tokens: ${r.tokens_snapshot}\n` +
|
|
786
|
+
`- Created: ${r.created_at}` +
|
|
787
|
+
(r.completed_at ? `\n- Completed: ${r.completed_at}` : "") +
|
|
788
|
+
(r.archived_chunks ? `\n- Archived chunks: ${r.archived_chunks}` : ""));
|
|
789
|
+
}
|
|
790
|
+
catch (e) {
|
|
791
|
+
return err(e);
|
|
792
|
+
}
|
|
793
|
+
});
|
|
703
794
|
async function main() {
|
|
704
795
|
const transport = new StdioServerTransport();
|
|
705
796
|
await server.connect(transport);
|