Skip to content

fix(mcp): actionable error when [mcp] extra is missing (#159)#162

Closed
J0nd1sk wants to merge 1 commit into
TSchonleber:mainfrom
J0nd1sk:fix/mcp-friendly-error-159
Closed

fix(mcp): actionable error when [mcp] extra is missing (#159)#162
J0nd1sk wants to merge 1 commit into
TSchonleber:mainfrom
J0nd1sk:fix/mcp-friendly-error-159

Conversation

@J0nd1sk

@J0nd1sk J0nd1sk commented Jun 29, 2026

Copy link
Copy Markdown

Closes #159.

Problem

brainctl-mcp imported the MCP SDK unguarded at mcp_server.py:36. Without the optional [mcp] extra (the default for pip install brainctl / pipx install brainctl), it crashed with a bare ModuleNotFoundError, surfacing to MCP clients only as "failed to connect."

Fix

  • Guard from mcp.server import Server; on a missing mcp package, write an actionable hint to stderr (pip install 'brainctl[mcp]', plus the pipx inject variant) and exit(1). Any other ModuleNotFoundError re-raises unchanged.
  • Clarify the README Install section so [mcp] reads as part of the install command, not an optional second step.

Test

tests/test_mcp_missing_extra.py runs the server import in a subprocess with mcp blocked at import time and asserts a clean exit(1) with the hint (no traceback). Normal import path (with mcp present) is unaffected.

Verification

$ pytest tests/test_mcp_missing_extra.py -q
1 passed

`brainctl-mcp` (entry point agentmemory.mcp_server:run) imported the MCP
SDK at module top level with no guard. On a plain `pip install brainctl`
/ `pipx install brainctl` (no `[mcp]` extra) it died with a bare
`ModuleNotFoundError: No module named 'mcp'` traceback, and the MCP
client only reported "failed to connect" — giving the user no idea an
extra was required.

Guard the import and exit(1) with the exact fix (`pip install
'brainctl[mcp]'`, plus the pipx-inject variant). Also clarify the README
Install section so `[mcp]` is presented as part of the install command,
not an optional second step.

Fixes #159

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@J0nd1sk J0nd1sk closed this by deleting the head repository Jun 30, 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.

[Bug] brainctl-mcp crashes with raw ModuleNotFoundError when the [mcp] extra isn't installed

1 participant