Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion plugin/.mcp.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"mcpServers": {
"agentmemory": {
"command": "npx",
"args": ["-y", "@agentmemory/mcp"]
"args": ["-y", "@agentmemory/mcp"],
"env": {
"AGENTMEMORY_URL": "${AGENTMEMORY_URL}",
"AGENTMEMORY_SECRET": "${AGENTMEMORY_SECRET}"
}
}
}
}
10 changes: 9 additions & 1 deletion src/cli/connect/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ import { dirname, join } from "node:path";
import { homedir } from "node:os";
import * as p from "@clack/prompts";

// Env values use ${VAR} expansion so the wired MCP entry inherits
// AGENTMEMORY_URL / AGENTMEMORY_SECRET from the user's shell. When the
// vars are unset, the host (Claude Code, Cursor, etc.) substitutes an
// empty string; the standalone shim treats empty as missing and falls
// back to http://localhost:3111. This lets a single wired entry serve
// both local and remote (Kubernetes / reverse-proxied) deployments
// without doctor-warning duplicates (#375).
export const AGENTMEMORY_MCP_BLOCK = {
command: "npx",
args: ["-y", "@agentmemory/mcp"],
env: {
AGENTMEMORY_URL: "http://localhost:3111",
AGENTMEMORY_URL: "${AGENTMEMORY_URL}",
AGENTMEMORY_SECRET: "${AGENTMEMORY_SECRET}",
},
};

Expand Down
21 changes: 21 additions & 0 deletions test/cli-connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ describe("agentmemory connect — claude-code adapter (mock filesystem)", () =>
expect(second.kind).toBe("already-wired");
});

it("install() writes env passthrough block for AGENTMEMORY_URL + AGENTMEMORY_SECRET (#375)", async () => {
// Remote deployments (k8s, reverse proxy) set AGENTMEMORY_URL +
// AGENTMEMORY_SECRET in the shell. The wired MCP entry must honour
// those via ${VAR} expansion so a single entry covers both local
// and remote without the user needing to add a duplicate config
// that triggers a /doctor duplicate-server warning.
const claudeDir = join(tmpHome, ".claude");
require("node:fs").mkdirSync(claudeDir, { recursive: true });
writeFileSync(join(tmpHome, ".claude.json"), JSON.stringify({}));

const a = await loadAdapter();
const result = await a.install({ dryRun: false, force: false });
expect(result.kind).toBe("installed");

const config = JSON.parse(readFileSync(join(tmpHome, ".claude.json"), "utf-8"));
const entry = config.mcpServers.agentmemory;
expect(entry.env).toBeDefined();
expect(entry.env.AGENTMEMORY_URL).toBe("${AGENTMEMORY_URL}");
expect(entry.env.AGENTMEMORY_SECRET).toBe("${AGENTMEMORY_SECRET}");
});

it("install() with --force re-writes even when already wired", async () => {
require("node:fs").mkdirSync(join(tmpHome, ".claude"), { recursive: true });
writeFileSync(
Expand Down