Skip to content

Commit 2981433

Browse files
fix: add mcp command with setup guidance (MemPalace#315)
* fix: add mcp command with setup guidance * fix: include --palace guidance in mcp command output * fix: make mcp guidance commands copy-pastable --------- Co-authored-by: Milla J <millaj1217@gmail.com>
1 parent 69afba3 commit 2981433

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,9 @@ mempalace compress --wing myapp # AAAK compress
585585

586586
# Status
587587
mempalace status # palace overview
588+
589+
# MCP
590+
mempalace mcp # show MCP setup command
588591
```
589592

590593
All commands accept `--palace <path>` to override the default location.

mempalace/cli.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
mempalace mine <dir> Mine project files (default)
1515
mempalace mine <dir> --mode convos Mine conversation exports
1616
mempalace search "query" Find anything, exact words
17+
mempalace mcp Show MCP setup command
1718
mempalace wake-up Show L0 + L1 wake-up context
1819
mempalace wake-up --wing my_app Wake-up for a specific project
1920
mempalace status Show what's been filed
@@ -28,6 +29,7 @@
2829

2930
import os
3031
import sys
32+
import shlex
3133
import argparse
3234
from pathlib import Path
3335

@@ -241,6 +243,27 @@ def cmd_instructions(args):
241243
run_instructions(name=args.name)
242244

243245

246+
def cmd_mcp(args):
247+
"""Show how to wire MemPalace into MCP-capable hosts."""
248+
base_server_cmd = "python -m mempalace.mcp_server"
249+
250+
if args.palace:
251+
resolved_palace = str(Path(args.palace).expanduser())
252+
server_cmd = f"{base_server_cmd} --palace {shlex.quote(resolved_palace)}"
253+
else:
254+
server_cmd = base_server_cmd
255+
256+
print("MemPalace MCP quick setup:")
257+
print(f" claude mcp add mempalace -- {server_cmd}")
258+
print("\nRun the server directly:")
259+
print(f" {server_cmd}")
260+
261+
if not args.palace:
262+
print("\nOptional custom palace:")
263+
print(f" claude mcp add mempalace -- {base_server_cmd} --palace /path/to/palace")
264+
print(f" {base_server_cmd} --palace /path/to/palace")
265+
266+
244267
def cmd_compress(args):
245268
"""Compress drawers in a wing using AAAK Dialect."""
246269
import chromadb
@@ -501,6 +524,12 @@ def main():
501524
help="Rebuild palace vector index from stored data (fixes segfaults after corruption)",
502525
)
503526

527+
# mcp
528+
sub.add_parser(
529+
"mcp",
530+
help="Show MCP setup command for connecting MemPalace to your AI client",
531+
)
532+
504533
# status
505534
sub.add_parser("status", help="Show what's been filed")
506535

@@ -532,6 +561,7 @@ def main():
532561
"mine": cmd_mine,
533562
"split": cmd_split,
534563
"search": cmd_search,
564+
"mcp": cmd_mcp,
535565
"compress": cmd_compress,
536566
"wake-up": cmd_wakeup,
537567
"repair": cmd_repair,

mempalace/instructions/help.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ AI memory system. Store everything, find anything. Local, free, no API key.
6060
mempalace compress Compress palace storage
6161
mempalace status Show palace status
6262
mempalace repair Rebuild vector index
63+
mempalace mcp Show MCP setup command
6364
mempalace hook run Run hook logic (for harness integration)
6465
mempalace instructions <name> Output skill instructions
6566

tests/test_cli.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import argparse
44
import sys
5+
from pathlib import Path
56
from unittest.mock import MagicMock, patch
67

78
import pytest
@@ -326,6 +327,35 @@ def test_main_split_dispatches():
326327
mock_cmd.assert_called_once()
327328

328329

330+
def test_mcp_command_prints_setup_guidance(monkeypatch, capsys):
331+
monkeypatch.setattr(sys, "argv", ["mempalace", "mcp"])
332+
333+
main()
334+
335+
captured = capsys.readouterr()
336+
assert "MemPalace MCP quick setup:" in captured.out
337+
assert "claude mcp add mempalace -- python -m mempalace.mcp_server" in captured.out
338+
assert "\nOptional custom palace:\n" in captured.out
339+
assert "python -m mempalace.mcp_server --palace /path/to/palace" in captured.out
340+
assert "[--palace /path/to/palace]" not in captured.out
341+
assert captured.err == ""
342+
343+
344+
def test_mcp_command_uses_custom_palace_path_when_provided(monkeypatch, capsys):
345+
monkeypatch.setattr(sys, "argv", ["mempalace", "--palace", "~/tmp/my palace", "mcp"])
346+
347+
main()
348+
349+
captured = capsys.readouterr()
350+
expanded = str(Path("~/tmp/my palace").expanduser())
351+
352+
assert "python -m mempalace.mcp_server --palace" in captured.out
353+
assert expanded in captured.out
354+
assert "Optional custom palace:" not in captured.out
355+
assert "[--palace /path/to/palace]" not in captured.out
356+
assert captured.err == ""
357+
358+
329359
def test_main_hook_no_subcommand_prints_help(capsys):
330360
with patch("sys.argv", ["mempalace", "hook"]):
331361
main()

0 commit comments

Comments
 (0)