Skip to content

Commit 162afb4

Browse files
committed
feat(cli, config, install): enhance MCP server configuration with SUPAMEM_PROJECT_ROOT
- Updated cmd_mcp_server to accept SUPAMEM_PROJECT_ROOT environment variable for dynamic configuration loading. - Enhanced config documentation to clarify the use of SUPAMEM_PROJECT_ROOT when launching the server outside the repository. - Refactored MCP overlay in cursor.py to conditionally inject SUPAMEM_PROJECT_ROOT based on the presence of the config file in the current working directory.
1 parent 01443c4 commit 162afb4

4 files changed

Lines changed: 32 additions & 11 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"version": 1,
3+
"lastRunAtMs": 0,
4+
"turnsSinceLastRun": 1,
5+
"lastTranscriptMtimeMs": null,
6+
"lastProcessedGenerationId": "32fae60f-1417-4a59-8650-e81412d14f7f",
7+
"trialStartedAtMs": null
8+
}

src/supamem/cli.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,16 @@ def cmd_mcp_server(
9090
host: str = typer.Option("127.0.0.1", "--host", help="HTTP bind host (only used when --transport http)."),
9191
) -> None:
9292
"""Run the dual-memory MCP server."""
93+
import os
94+
95+
from pathlib import Path
96+
9397
from supamem.config import load_config
9498
from supamem.mcp_server import run_http, run_stdio
9599

96-
cfg, _chain = load_config()
100+
root = os.environ.get("SUPAMEM_PROJECT_ROOT", "").strip()
101+
cfg_root = Path(root) if root else None
102+
cfg, _chain = load_config(cfg_root)
97103
if transport is Transport.stdio:
98104
run_stdio(cfg)
99105
elif transport is Transport.http:

src/supamem/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Resolution order (highest to lowest):
44
55
1. ``$SUPAMEM_CONFIG`` env var pointing to an explicit TOML file
6-
2. ``<cwd>/.supamem/config.toml`` (the canonical project config)
6+
2. ``<cwd>/.supamem/config.toml`` (the canonical project config).
7+
MCP stdio defaults ``cwd`` to ``Path.cwd()``; set ``SUPAMEM_PROJECT_ROOT`` to your
8+
workspace root when the host launches the server outside the repo (Cursor/IDE).
79
3. ``<cwd>/pyproject.toml`` ``[tool.supamem]`` section
810
4. Auto-detect: presence of ``<cwd>/.claude/insights/`` seeds ``sources``
911
5. Defaults baked into ``ResolvedConfig``

src/supamem/install/cursor.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@
2424

2525
log = logging.getLogger("supamem.install.cursor")
2626

27-
MCP_OVERLAY: dict[str, Any] = {
28-
"mcpServers": {
29-
"supamem": {
30-
"command": "supamem",
31-
"args": ["mcp-server", "--transport", "stdio"],
32-
"env": {"DM_MCP_SOURCE": "mcp_cursor"},
33-
}
27+
28+
def _mcp_supamem_entry(cwd: Path) -> dict[str, Any]:
29+
"""Cursor MCP stanza — inject SUPAMEM_PROJECT_ROOT when bootstrapped in-repo."""
30+
env: dict[str, str] = {"DM_MCP_SOURCE": "mcp_cursor"}
31+
if (cwd / ".supamem" / "config.toml").is_file():
32+
env["SUPAMEM_PROJECT_ROOT"] = str(cwd.resolve())
33+
return {
34+
"command": "supamem",
35+
"args": ["mcp-server", "--transport", "stdio"],
36+
"env": env,
3437
}
35-
}
3638

3739
SESSION_START_HOOK: dict[str, Any] = {
3840
"sessionStart": [
@@ -90,7 +92,10 @@ def install(*, dry_run: bool = False) -> InstallResult:
9092
diffs: list[str] = []
9193

9294
cur_mcp = _read_json(mcp_path)
93-
merged_mcp = deep_merge_json(cur_mcp, MCP_OVERLAY)
95+
merged_mcp = deep_merge_json(
96+
cur_mcp,
97+
{"mcpServers": {"supamem": _mcp_supamem_entry(cwd)}},
98+
)
9499
res_mcp = atomic_write_json(mcp_path, merged_mcp, dry_run=dry_run)
95100
if res_mcp.diff:
96101
diffs.append(res_mcp.diff)

0 commit comments

Comments
 (0)