Skip to content

fix(generate): strip env: prefix for Claude Code MCP env refs#71

Merged
Jott4 merged 1 commit into
mainfrom
jott4-/-claude-mcp-env-syntax
Jul 14, 2026
Merged

fix(generate): strip env: prefix for Claude Code MCP env refs#71
Jott4 merged 1 commit into
mainfrom
jott4-/-claude-mcp-env-syntax

Conversation

@Jott4

@Jott4 Jott4 commented Jul 10, 2026

Copy link
Copy Markdown
Member

Problem

Claude Code's .mcp.json expands only ${VAR} and ${VAR:-default}not ${env:VAR} (that's Cursor/Kiro-CLI syntax). buildClaudeCodeMcpEntry emitted mcp.env verbatim, so direct (non-proxy) MCP servers received the literal string ${env:VAR} as their token/URL and failed to authenticate (e.g. HubSpot 401, Dokploy "Invalid URL"). The proxy hid this because it expands ${env:VAR} internally — so anything moved out of the proxy silently broke.

Fix

Apply stripEnvPrefix (already used for the Kiro editor target) in buildClaudeCodeMcpEntry, covering both the npx and docker paths, in both the CLI (generate.ts) and core (prompt-builders.ts) copies. Result: Claude gets ${VAR}, which it expands from its process env.

Verified

  • packages/cli tsc clean; full pnpm build (tsup + DTS) green; pnpm test 22/22.
  • Confirmed manually in arvore-hub: rewriting ${env:VAR}${VAR} + providing the vars made 22 direct servers connect (HubSpot, Dokploy, MySQL, Postgres, etc.) that were failing.

Note

Consumers still need the env vars present in Claude Code's process (Claude does not auto-load .env) — via a launched-with-env shell or a settings.local.json env block. This PR fixes the syntax so those values actually resolve.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed MCP environment variable handling for Claude Code integrations.
    • Environment references using the ${env:VAR_NAME} format are now converted correctly for both Docker-based and npx-based MCP configurations.
    • Improved compatibility when configuring MCP servers for Claude Code and Kiro IDE.

Claude Code's .mcp.json only expands ${VAR} / ${VAR:-default}, not the
${env:VAR} form. buildClaudeCodeMcpEntry emitted mcp.env verbatim, so
direct (non-proxy) servers received the literal string ${env:VAR} as
their token/URL and failed to authenticate — the proxy masked this by
expanding ${env:VAR} itself. Apply stripEnvPrefix (already used for the
Kiro editor target) in both the CLI and core builders, covering the npx
and docker paths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
rhm-website Ready Ready Preview, Comment Jul 10, 2026 9:38pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Claude Code MCP generation now strips the CLI-style ${env:VAR_NAME} prefix from environment values in Docker and npx configurations across the CLI and core implementations.

Changes

MCP environment reference normalization

Layer / File(s) Summary
Normalize Claude Code MCP environment values
packages/cli/src/commands/generate.ts, packages/core/src/prompt-builders.ts
Both buildClaudeCodeMcpEntry implementations use stripped environment mappings for Docker -e arguments and npx configuration, with updated format-conversion comments in the CLI generator.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: stripping the env: prefix for Claude Code MCP env refs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jott4-/-claude-mcp-env-syntax

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.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
packages/cli/src/commands/generate.ts (1)

501-503: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider importing stripEnvPrefix and buildClaudeCodeMcpEntry from core instead of duplicating.

Both stripEnvPrefix (line 505) and buildClaudeCodeMcpEntry (line 479) are duplicated between the CLI and packages/core/src/prompt-builders.ts, where they are already exported. This PR applies the same fix to both copies, which is correct but widens the duplication surface — future divergences will require synchronized edits in two files.

If the CLI cannot depend on core for this path, consider extracting these into a shared utility module.

🤖 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 `@packages/cli/src/commands/generate.ts` around lines 501 - 503, Replace the
duplicated stripEnvPrefix and buildClaudeCodeMcpEntry implementations in the CLI
with imports from packages/core/src/prompt-builders.ts, reusing the exported
helpers. Update all call sites in generate.ts and remove the local definitions;
only introduce a shared utility if the CLI cannot depend on core.
🤖 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.

Nitpick comments:
In `@packages/cli/src/commands/generate.ts`:
- Around line 501-503: Replace the duplicated stripEnvPrefix and
buildClaudeCodeMcpEntry implementations in the CLI with imports from
packages/core/src/prompt-builders.ts, reusing the exported helpers. Update all
call sites in generate.ts and remove the local definitions; only introduce a
shared utility if the CLI cannot depend on core.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 39c52b06-ee86-4e9e-885a-ebd82cb2a322

📥 Commits

Reviewing files that changed from the base of the PR and between eb1cfb1 and 9c67654.

📒 Files selected for processing (2)
  • packages/cli/src/commands/generate.ts
  • packages/core/src/prompt-builders.ts

@Jott4
Jott4 merged commit f6826ab into main Jul 14, 2026
6 checks passed
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.

1 participant