Skip to content

fix(mcp): .mcp.json project-context fallback — no 'missing CLAUDE_PLUGIN_ROOT' warning — 0.24.5#18

Merged
Cain-Ish merged 1 commit into
mainfrom
fix/mcp-project-context-fallback
Jun 2, 2026
Merged

fix(mcp): .mcp.json project-context fallback — no 'missing CLAUDE_PLUGIN_ROOT' warning — 0.24.5#18
Cain-Ish merged 1 commit into
mainfrom
fix/mcp-project-context-fallback

Conversation

@Cain-Ish

@Cain-Ish Cain-Ish commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Symptom

Opening the cloned repo as a project (e.g. on Windows C:\Workplace\Projects\claude-code-plugin):

[Warning] [knowledge-base] mcpServers.knowledge-base: Missing environment variables: CLAUDE_PLUGIN_ROOT

Root cause — ours (config), not a Claude bug

The repo-root .mcp.json is read in two contexts: as the plugin's MCP manifest (plugin context — CLAUDE_PLUGIN_ROOT is set) and as the project-scoped MCP config when the repo is opened as a project (CLAUDE_PLUGIN_ROOT is not set). The path used a bare ${CLAUDE_PLUGIN_ROOT} with no default, so the project context couldn't resolve it → the warning, and the server didn't start there. Claude was correctly reporting the missing var.

Fix

${CLAUDE_PLUGIN_ROOT}${CLAUDE_PLUGIN_ROOT:-.} (the documented ${VAR:-default} expansion).

  • Plugin context: the var is set, so the :- default is never evaluated → the installed-plugin MCP is byte-for-byte unchanged — zero regression risk to existing installs.
  • Project context: falls back to a repo-relative path → no missing-var warning.

validate-plugin.sh gains a regression guard that fails on a bare ${CLAUDE_PLUGIN_ROOT} in .mcp.json (+ 2 test-validate-plugin.sh cases: bad form fails, fixed form passes). Verified against the Claude Code MCP docs via the claude-code-guide agent (confirmed ${VAR:-default} is supported; ${VAR:?error} is not).

Verification

Full suite green (72 shell + 357 vitest); validator passes on the real plugin; version lockstep 0.24.5; upgrade migration row added. Config/script/test-only — no state migration.

🤖 Generated with Claude Code

…AUDE_PLUGIN_ROOT') — 0.24.5

The repo-root .mcp.json is read BOTH as the plugin's MCP manifest (plugin
context, CLAUDE_PLUGIN_ROOT set) AND as the project-scoped MCP config when the
cloned repo is opened as a project (CLAUDE_PLUGIN_ROOT unset). The bare
${CLAUDE_PLUGIN_ROOT} had no default, so the project context warned 'Missing
environment variables: CLAUDE_PLUGIN_ROOT' and the server didn't start there.

Fix: ${CLAUDE_PLUGIN_ROOT:-.} (documented ${VAR:-default} expansion). In plugin
context the var is set so the default is never evaluated -> the installed-plugin
MCP is unchanged (zero regression risk); in project context it falls back to a
repo-relative path so the warning is gone. validate-plugin.sh now fails on a bare
${CLAUDE_PLUGIN_ROOT} in .mcp.json (regression guard + 2 test cases). Confirmed
via the claude-code-guide / Claude Code MCP docs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 2, 2026 21:58
@Cain-Ish Cain-Ish merged commit dc709ab into main Jun 2, 2026
1 check passed
@Cain-Ish Cain-Ish deleted the fix/mcp-project-context-fallback branch June 2, 2026 21:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a cross-context MCP config issue where the repo-root .mcp.json is interpreted both as the plugin MCP manifest and as project-scoped MCP config; in project context CLAUDE_PLUGIN_ROOT is unset, causing a “Missing environment variables: CLAUDE_PLUGIN_ROOT” warning and preventing the knowledge-base server from starting.

Changes:

  • Update .mcp.json to use ${CLAUDE_PLUGIN_ROOT:-.} so the path resolves in both plugin and project contexts.
  • Add a validator guard in scripts/validate-plugin.sh to fail if .mcp.json contains a bare ${CLAUDE_PLUGIN_ROOT} (no default).
  • Add regression tests for the validator behavior and bump version metadata/docs to 0.24.5.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test-validate-plugin.sh Adds regression cases ensuring bare ${CLAUDE_PLUGIN_ROOT} fails validation and the :-. fallback passes.
scripts/validate-plugin.sh Enforces the “no bare ${CLAUDE_PLUGIN_ROOT} in .mcp.json” rule to prevent project-context warnings.
.mcp.json Switches MCP server path to ${CLAUDE_PLUGIN_ROOT:-.} to support both contexts.
skills/upgrade/SKILL.md Documents the 0.24.5 migration note for the .mcp.json cross-context fix.
.claude-plugin/plugin.json Bumps plugin version to 0.24.5.
.claude-plugin/marketplace.json Bumps marketplace version to 0.24.5.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants