feat: Add support for custom configuration directory via CLAUDE_CONFIG_DIR #224
+213
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes support for the
CLAUDE_CONFIG_DIRenvironment variable when configuring Claude Code clients.Problem
The Docker MCP Gateway's Claude Code client configuration did not respect the
CLAUDE_CONFIG_DIRenvironment variable, always defaulting to~/.claude.jsonregardless of whether users had set a custom configuration directory. This broke multi-profile workflows where users maintain separate Claude Code installations for different contexts (e.g., work vs. personal). When users clicked the 'Connect' button in the MCP Toolkit UI withCLAUDE_CONFIG_DIRset, the gateway would configure the wrong Claude Code installation, causing the MCP servers to be unavailable in the intended profile and potentially exposing them in an unintended one.Changes
cmd/docker-mcp/client/config.yml: Modified theclaude-codeclient configuration to prioritize$CLAUDE_CONFIG_DIR/.claude.jsonbeforefalling back to
$HOME/.claude.jsoncmd/docker-mcp/client/global.go: AddedisPathValid()function to validate environment variables in paths and updatedUpdate()to filterout paths with undefined or empty environment variables
cmd/docker-mcp/client/global_test.go: Tests for path validation, environment variable priority, and fallback behaviorREADME.md: Added documentation for theCLAUDE_CONFIG_DIRenvironment variable with usage examplesBehavior
CLAUDE_CONFIG_DIRis set and non-empty: Configuration is written to$CLAUDE_CONFIG_DIR/.claude.jsonCLAUDE_CONFIG_DIRis unset or empty: Configuration falls back to$HOME/.claude.jsonCLAUDE_CONFIG_DIRlocation are used first if they existTesting
All existing tests pass, plus new tests added:
TestIsPathValid: Validates path checking logic for defined, undefined, and empty environment variablesTestGlobalCfgProcessor_Update_WithEnvVarPaths: Verifies configuration uses custom directory whenCLAUDE_CONFIG_DIRis setTestGlobalCfgProcessor_Update_FallbackWhenEnvVarUndefined: Verifies fallback to default location when variable is not setTestGlobalCfgProcessor_Update_AllPathsInvalid: Verifies proper error handlingThis PR fixes #225