Skip to content

fix: pass plugin mcp env overrides#386

Open
LaplaceYoung wants to merge 1 commit into
rohitg00:mainfrom
LaplaceYoung:fix/375-plugin-mcp-env
Open

fix: pass plugin mcp env overrides#386
LaplaceYoung wants to merge 1 commit into
rohitg00:mainfrom
LaplaceYoung:fix/375-plugin-mcp-env

Conversation

@LaplaceYoung
Copy link
Copy Markdown

@LaplaceYoung LaplaceYoung commented May 15, 2026

Summary

  • Pass AGENTMEMORY_URL and AGENTMEMORY_SECRET through the bundled plugin MCP server config.
  • Keep http://localhost:3111 as the default MCP server target when AGENTMEMORY_URL is unset.
  • Add regression coverage for the plugin MCP env block.
  • Document the remote/protected Claude Code launch path.

Fixes #375

Test plan

  • npm test -- --run test/codex-plugin.test.ts
  • npx tsdown
  • git diff --check

Notes

  • npm run build reaches the tsdown compile step on Windows, then the shell copy tail exits on true because the script uses Unix shell syntax.
  • npm test on Windows reports path-sensitive failures in test/obsidian-export.test.ts and test/compress-file.test.ts; 894 tests pass, including test/codex-plugin.test.ts.

Summary by CodeRabbit

  • Documentation

    • Expanded installation guide with comprehensive configuration instructions for deploying agentmemory in remote and protected deployment environments. Now includes detailed environment variable documentation, descriptions, default values, concrete setup examples, and recommended best practices to guide users through proper configuration.
  • Tests

    • Added automated tests to validate environment variable configuration and ensure proper fallback behavior.

Review Change Stack

Signed-off-by: laplace young <yangqk12@whu.edu.cn>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 15, 2026

Someone is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

📝 Walkthrough

Walkthrough

The PR extends the agentmemory MCP server configuration to support environment variable overrides for remote deployments. The .mcp.json configuration now includes AGENTMEMORY_URL and AGENTMEMORY_SECRET settings with defaults, a test validates this configuration, and the README documents the feature.

Changes

MCP Server Environment Variable Configuration

Layer / File(s) Summary
MCP env var configuration, test, and documentation
plugin/.mcp.json, test/codex-plugin.test.ts, README.md
The agentmemory MCP server config now includes env block with AGENTMEMORY_URL (defaulting to http://localhost:3111) and AGENTMEMORY_SECRET (defaulting to empty string). A new test asserts these environment variables are present with expected ${VAR:-default} fallback format. README documents how to set these values for remote or protected deployments.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • rohitg00/agentmemory#141: Introduced the initial agentmemory MCP server auto-wiring via plugin/.mcp.json that this PR extends with environment variable configuration.
  • rohitg00/agentmemory#282: Previously updated AgentMemory MCP install snippets with AGENTMEMORY_URL env wiring; this PR generalizes and solidifies that pattern in the plugin configuration.
  • rohitg00/agentmemory#311: Established the baseline test/codex-plugin.test.ts suite that this PR extends with environment variable assertions.

Poem

🐰 A memory that roams far and wide,
No longer bound by localhost's side,
With secrets passed and URLs set free,
Remote deployments dance with glee.
The config whispers, tests confirm the way,
Documentation lights the path today. 🌙

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding MCP environment variable overrides to the plugin configuration to resolve issue #375.
Linked Issues check ✅ Passed The PR implements the primary objective from #375 by passing AGENTMEMORY_URL and AGENTMEMORY_SECRET env vars through the bundled plugin MCP server config, resolving the hardcoded localhost limitation.
Out of Scope Changes check ✅ Passed All changes are directly within scope: .mcp.json configuration update, README documentation, and regression test coverage for the MCP env block.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
README.md (1)

358-359: 💤 Low value

Consider adding a concrete example of setting environment variables.

The documentation clearly explains what to do, but developers unfamiliar with environment variable configuration might benefit from a concrete example of how to launch Claude Code with these variables set.

📝 Suggested documentation enhancement
 For remote or protected deployments, launch Claude Code with `AGENTMEMORY_URL` and `AGENTMEMORY_SECRET` set. The plugin passes both values through to its bundled MCP server, with `http://localhost:3111` as the default URL.
+
+Example (macOS/Linux):
+```bash
+AGENTMEMORY_URL=https://my-server.example.com:3111 \
+AGENTMEMORY_SECRET=my-secret-token \
+claude
+```
+
+Example (Windows PowerShell):
+```powershell
+$env:AGENTMEMORY_URL="https://my-server.example.com:3111"
+$env:AGENTMEMORY_SECRET="my-secret-token"
+claude
+```
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@README.md` around lines 358 - 359, Add concrete examples showing how to set
AGENTMEMORY_URL and AGENTMEMORY_SECRET when launching Claude Code: show a POSIX
shell example using inline env vars (AGENTMEMORY_URL=... AGENTMEMORY_SECRET=...
claude or export ...; claude) and a Windows PowerShell example using
$env:AGENTMEMORY_URL="..." and $env:AGENTMEMORY_SECRET="..." followed by
invoking claude; reference the environment variable names AGENTMEMORY_URL and
AGENTMEMORY_SECRET and the command claude so readers can copy/paste the
snippets.
test/codex-plugin.test.ts (1)

49-65: 💤 Low value

LGTM! Consider adding runtime integration test coverage.

The test correctly validates that the environment variable template strings are present in the configuration. However, it doesn't verify the actual runtime behavior—whether MCP clients successfully substitute these variables when they're set or fall back to defaults when unset.

While this config validation is appropriate for a unit test, consider documenting in the test plan how the runtime behavior is verified (e.g., manual testing with AGENTMEMORY_URL=https://remote-server:3111 claude ... or integration tests that spawn actual MCP sessions).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/codex-plugin.test.ts` around lines 49 - 65, The current unit test in the
"plugin MCP server inherits remote agentmemory environment overrides" case only
asserts template strings in the .mcp.json (the mcp variable produced by
readJson) but doesn't exercise runtime substitution; add an integration test
that spawns or simulates an MCP client/server using the same .mcp.json (reuse
the mcp variable from test/codex-plugin.test.ts) and verifies two runtime
scenarios: (1) with AGENTMEMORY_URL and AGENTMEMORY_SECRET set in process.env
the running MCP process resolves those into concrete values, and (2) with them
unset the MCP process falls back to the default template values; implement this
by launching the MCP command from mcp.mcpServers.agentmemory.command (or a small
helper that loads the same config) and asserting the effective environment seen
by the child process or IPC message matches expected resolved URLs/secrets.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@plugin/.mcp.json`:
- Around line 6-9: The env entries in plugin/.mcp.json use shell-style
"${VAR:-default}" expansion which is not portable across MCP clients; update the
AGENTMEMORY_URL and AGENTMEMORY_SECRET entries to use a cross-client compatible
variable syntax (e.g. the VS Code-style "${env:AGENTMEMORY_URL}" /
"${env:AGENTMEMORY_SECRET}") and remove the ":-default" fallback from the JSON,
and implement any defaults in the plugin initialization code (where
AGENTMEMORY_URL and AGENTMEMORY_SECRET are read) so that functions referencing
those keys (AGENTMEMORY_URL, AGENTMEMORY_SECRET) get a safe default at runtime
instead of relying on shell expansion.

---

Nitpick comments:
In `@README.md`:
- Around line 358-359: Add concrete examples showing how to set AGENTMEMORY_URL
and AGENTMEMORY_SECRET when launching Claude Code: show a POSIX shell example
using inline env vars (AGENTMEMORY_URL=... AGENTMEMORY_SECRET=... claude or
export ...; claude) and a Windows PowerShell example using
$env:AGENTMEMORY_URL="..." and $env:AGENTMEMORY_SECRET="..." followed by
invoking claude; reference the environment variable names AGENTMEMORY_URL and
AGENTMEMORY_SECRET and the command claude so readers can copy/paste the
snippets.

In `@test/codex-plugin.test.ts`:
- Around line 49-65: The current unit test in the "plugin MCP server inherits
remote agentmemory environment overrides" case only asserts template strings in
the .mcp.json (the mcp variable produced by readJson) but doesn't exercise
runtime substitution; add an integration test that spawns or simulates an MCP
client/server using the same .mcp.json (reuse the mcp variable from
test/codex-plugin.test.ts) and verifies two runtime scenarios: (1) with
AGENTMEMORY_URL and AGENTMEMORY_SECRET set in process.env the running MCP
process resolves those into concrete values, and (2) with them unset the MCP
process falls back to the default template values; implement this by launching
the MCP command from mcp.mcpServers.agentmemory.command (or a small helper that
loads the same config) and asserting the effective environment seen by the child
process or IPC message matches expected resolved URLs/secrets.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 36f307a8-6612-4f7c-9cf6-968db4860c16

📥 Commits

Reviewing files that changed from the base of the PR and between 4b354b7 and 9dfa6ce.

📒 Files selected for processing (3)
  • README.md
  • plugin/.mcp.json
  • test/codex-plugin.test.ts

Comment thread plugin/.mcp.json
Comment on lines +6 to +9
"env": {
"AGENTMEMORY_URL": "${AGENTMEMORY_URL:-http://localhost:3111}",
"AGENTMEMORY_SECRET": "${AGENTMEMORY_SECRET:-}"
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for documentation of env var syntax in MCP-related files and comments

# Check if there are any other .mcp.json examples in the repo
echo "=== Other MCP config examples in repo ==="
fd -e json -e md . | xargs rg -l 'mcpServers.*env' -A5 -B5

# Check README and docs for MCP env var documentation
echo "=== MCP env var documentation in README ==="
rg -C5 'AGENTMEMORY_URL.*localhost.*3111' README.md

# Check if there are integration tests that actually exercise this
echo "=== Tests that might validate runtime behavior ==="
rg -C3 'AGENTMEMORY_URL|AGENTMEMORY_SECRET' test/

Repository: rohitg00/agentmemory

Length of output: 1967


🌐 Web query:

MCP Model Context Protocol environment variable syntax specification

💡 Result:

There is no single, protocol-level “MCP Model Context Protocol environment variable syntax specification” in the upstream MCP spec itself. What is standardized in MCP: 1) The MCP protocol spec defines an HTTP authorization framework for HTTP-based transports, but it explicitly does not require stdio clients/servers to follow that HTTP auth scheme and instead notes that credentials should come from the environment for stdio implementations. [1] What “environment variable syntax” does exist for MCP today: A) MCP client configuration formats (e.g., VS Code / Cursor style mcp.json, and other MCP client tools) each implement their own string interpolation / env expansion rules. - VS Code’s MCP configuration reference shows that the env field is “Environment variables for the server” and also supports an envFile field. [2] - A VS Code issue discussing env-var placeholders in mcp.json shows the commonly used pattern ${env:VARIABLE_NAME} referenced by VS Code’s variable system, and reports that behavior can differ depending on where the config comes from (user mcp.json vs plugin-provided). [3] B) Some MCP client libraries / wrappers don’t expand ${VAR} placeholders at all (they pass them through as literal strings), which is not an MCP spec guarantee. - A LangChain MCP adapters issue states that ${VAR} syntax in the env block is “widely-used” but that their adapter passes those values through without resolving them. [4] C) MCP-related runtimes and deployment tools introduce their own environment-variable templating syntax (again, not MCP core). - Example: code/config templates for an MCP server can use ${VAR}-style substitution in some tooling; one MCP Hub docs page documents ${...} expansion and ${VAR_NAME:-default} defaults as supported by that product. [5] - Example: 1mcp-app/agent documents a set of environment variables for configuring the agent itself (prefixed ONE_MCP_), which is tool-specific rather than part of MCP protocol syntax. [6] So what syntax should you use? - If you are editing an MCP client config file such as VS Code’s mcp.json, use the syntax that that specific client supports. In VS Code discussions, ${env:VARIABLE_NAME} is the referenced form. [3] - If you’re using another MCP client/runtime, follow its docs; some support ${VAR} expansion, others require ${env:VAR}, and some don’t expand placeholders when passed in the env map. [2][4] If you tell me which exact MCP client/tool you’re using (e.g., VS Code Copilot MCP, Cursor, Claude Desktop, a specific SDK like openai-agents-js, or a specific MCP gateway), I can look up that tool’s exact environment-variable placeholder grammar and confirm with citations.

Citations:


Verify MCP client compatibility for environment variable syntax ${VAR:-default}.

The ${VAR:-default} syntax uses shell parameter expansion, not standard JSON. Web search confirms that MCP clients do NOT have a shared standard for environment variable substitution—each client implements its own rules:

  • VS Code/Cursor use ${env:VARIABLE_NAME} syntax
  • Some MCP clients (e.g., LangChain adapters) do not expand ${VAR} placeholders at all, treating them as literal strings
  • A few tools support ${VAR:-default}, but coverage is not universal

This configuration may break when deployed to clients that don't recognize this syntax. Test with your target MCP clients (Claude Code, Cursor, Cline, Windsurf) or use the ${env:VARIABLE_NAME} syntax documented in VS Code's MCP configuration reference if cross-client compatibility is required.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugin/.mcp.json` around lines 6 - 9, The env entries in plugin/.mcp.json use
shell-style "${VAR:-default}" expansion which is not portable across MCP
clients; update the AGENTMEMORY_URL and AGENTMEMORY_SECRET entries to use a
cross-client compatible variable syntax (e.g. the VS Code-style
"${env:AGENTMEMORY_URL}" / "${env:AGENTMEMORY_SECRET}") and remove the
":-default" fallback from the JSON, and implement any defaults in the plugin
initialization code (where AGENTMEMORY_URL and AGENTMEMORY_SECRET are read) so
that functions referencing those keys (AGENTMEMORY_URL, AGENTMEMORY_SECRET) get
a safe default at runtime instead of relying on shell expansion.

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.

Feature: Plugin should inherit MCP server env vars from environment

1 participant