Skip to content

fix: add mcp subcommand to CLI so mempalace mcp works for Claude Desktop (#355) - #372

Closed
RhettOP wants to merge 5 commits into
MemPalace:developfrom
RhettOP:fix/issue-355-add-mcp-subcommand
Closed

fix: add mcp subcommand to CLI so mempalace mcp works for Claude Desktop (#355)#372
RhettOP wants to merge 5 commits into
MemPalace:developfrom
RhettOP:fix/issue-355-add-mcp-subcommand

Conversation

@RhettOP

@RhettOP RhettOP commented Apr 9, 2026

Copy link
Copy Markdown

Problem

Running mempalace mcp (as instructed in the Claude Desktop setup docs) gives:

error: argument command: invalid choice: 'mcp'

The MCP server code exists at mempalace/mcp_server.py and has a working main() function, but the mcp subcommand was not wired into mempalace/cli.py.

Fix

Added an mcp subcommand to mempalace/cli.py following the established pattern:

  • Added cmd_mcp() function that calls mcp_server.main()
  • Added p_mcp subparser with descriptive help text
  • Added "mcp": cmd_mcp entry to the dispatch dict

Verification

# Help works
$ python3 -m mempalace mcp --help
usage: __main__.py mcp [-h]

optional arguments:
  -h, --help  show this help message and exit

# JSON-RPC works
$ echo {"jsonrpc":"2.0","method":"initialize","params":{},"id":1}' | python3 -m mempalace mcp
MemPalace MCP Server starting...
{"jsonrpc": "2.0", "id": 1, "result": {"protocolVersion": "2024-11-05", "capabilities": {"tools": {}}, "serverInfo": {"name": "mempalace", "version": "3.0.14"}}}

Fixes #355

@bgauryy

bgauryy commented Apr 9, 2026

Copy link
Copy Markdown

PR Review: fix: add mcp subcommand to CLI so mempalace mcp works for Claude Desktop (#355)

Executive Summary

Aspect Value
PR Goal Wire existing mcp_server.main() into the CLI as mempalace mcp subcommand
Files Changed 1 (mempalace/cli.py)
Risk Level LOW — purely additive, no existing behaviour modified
Review Mode Quick
Review Effort 1 — small, focused bug fix
Recommendation APPROVE

Affected Areas: mempalace/cli.py → new cmd_mcp() → calls mempalace/mcp_server.py:main()

Business Impact: Running mempalace mcp (as documented in Claude Desktop setup) was broken — raised invalid choice: 'mcp'. This fix makes the documented command work.

Flow Changes: New CLI entry point mempalace mcp → lazy-imports mcp_server.main() → starts JSON-RPC stdio loop. No existing commands affected.

Ratings

Aspect Score
Correctness 5/5
Security 5/5
Performance 5/5
Maintainability 5/5

PR Health

Consistency Analysis

The new subcommand follows the exact pattern established by all other CLI commands:

Check Existing pattern (cmd_repair) PR (cmd_mcp) Match?
def cmd_*(args): signature def cmd_repair(args): def cmd_mcp(args):
Lazy import inside function body import chromadb from .mcp_server import main as mcp_main
sub.add_parser(name, help=...) sub.add_parser("repair", help=...) sub.add_parser("mcp", help=...)
Dispatch dict entry "repair": cmd_repair "mcp": cmd_mcp

Integration Verification

  • mcp_server.main() confirmed: Exists at mempalace/mcp_server.py, takes zero arguments, runs a stdin.readline() loop with JSON-RPC protocol handling. Handles KeyboardInterrupt, json.JSONDecodeError, and generic Exception internally.
  • No argument mismatch: cmd_mcp(args) calls mcp_main() with no arguments, matching the def main(): signature exactly.
  • Lazy import: MCP server dependencies are only loaded when mempalace mcp is invoked, avoiding startup cost for other commands.

Issues

No HIGH or MEDIUM issues found.

Low Priority (Optional)

# Location Confidence Finding
1 cli.py:229 MED args parameter is accepted but unused in cmd_mcp. Not a bug (dispatch pattern requires it), but if the project lints for unused params, consider # noqa: ARG001 or a future --verbose/--transport flag.

Flow Impact Analysis

main() [cli.py]
  └─ parser.parse_args() → args.command == "mcp"
  └─ dispatch["mcp"] → cmd_mcp(args)
       └─ from .mcp_server import main as mcp_main
       └─ mcp_main()  # blocks on stdin JSON-RPC loop

Blast radius: Zero. Purely additive — no existing commands, signatures, or dispatch paths are modified. cmd_mcp is a new leaf function with no callers other than the dispatch dict.


Created by Octocode MCP https://octocode.ai

@virtualwingwomen

Copy link
Copy Markdown

🫡🙏🙏

@web3guru888 web3guru888 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix — this has been a real UX gap. The mempalace mcp command is documented in the Claude Desktop setup but wasn't actually wired in, so new users hit an immediate wall.

The implementation follows the existing CLI pattern correctly:

  • Lazy import via from .mcp_server import main inside the function ✅
  • Subparser registration in the right place ✅
  • Dispatch entry added ✅

A couple of minor observations:

  1. No --port or --transport flagsmcp_server.main() is stdio-only today, but if a future PR adds SSE/streamable-HTTP transport, having the subparser ready for arguments would be nice. Not a blocker for this PR though.
  2. Positional placement — the mcp subparser is added between instructions and repair, which is fine, but grouping it near the other server-y commands (if any exist later) might read better in --help output.

Overall this is a straightforward, correct fix. Tested verification in the PR description looks good.

🔭 Reviewed as part of the MemPalace-AGI integration project — autonomous research with perfect memory. Community interaction updates are posted regularly on the dashboard.

@bensig
bensig changed the base branch from main to develop April 11, 2026 22:22
…gistration

The merge of fix/issue-355-add-mcp-subcommand onto develop introduced two
cmd_mcp() definitions and two sub.add_parser('mcp', ...) calls, causing:

  argparse.ArgumentError: argument command: conflicting subparser: mcp

which broke all test_cli.py tests on CI.

Fix: keep the upstream cmd_mcp (setup guidance with --palace flag), remove
the simpler launcher-only version added in the original PR commit.
@RhettOP

RhettOP commented Apr 11, 2026

Copy link
Copy Markdown
Author

Fixed. The merge introduced two cmd_mcp() definitions and two sub.add_parser('mcp', ...) calls, which caused:

argparse.ArgumentError: argument command: conflicting subparser: mcp

...and broke all test_cli.py tests.

Fix: removed the duplicate simpler launcher-only cmd_mcp and duplicate subparser registration. Kept the upstream version (setup guidance with --palace flag). Tested locally — 40/40 test_cli.py tests pass. CI should be green now.

@RhettOP

RhettOP commented Apr 11, 2026

Copy link
Copy Markdown
Author

Closing — issue #355 was already fully fixed by PR #315 (merged April 9th by @kpulik). That PR added the same mcp subcommand with setup guidance and --palace flag, plus proper tests. Our PR duplicated that work and introduced the conflicting subparser bug. No further action needed here.

@RhettOP RhettOP closed this Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pip package does not include mcp subcommand.. the Claude Desktop setup instructions fail :(

5 participants