Skip to content

Conversation

@jandroav
Copy link

@jandroav jandroav commented Nov 8, 2025

Summary

Fixes support for the CLAUDE_CONFIG_DIR environment variable when configuring Claude Code clients.

Problem

The Docker MCP Gateway's Claude Code client configuration did not respect the CLAUDE_CONFIG_DIR environment variable, always defaulting to ~/.claude.json regardless 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 with CLAUDE_CONFIG_DIR set, 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

  • Updated cmd/docker-mcp/client/config.yml: Modified the claude-code client configuration to prioritize $CLAUDE_CONFIG_DIR/.claude.json before
    falling back to $HOME/.claude.json
  • Enhanced cmd/docker-mcp/client/global.go: Added isPathValid() function to validate environment variables in paths and updated Update() to filter
    out paths with undefined or empty environment variables
  • Added comprehensive tests in cmd/docker-mcp/client/global_test.go: Tests for path validation, environment variable priority, and fallback behavior
  • Updated README.md: Added documentation for the CLAUDE_CONFIG_DIR environment variable with usage examples

Behavior

  • When CLAUDE_CONFIG_DIR is set and non-empty: Configuration is written to $CLAUDE_CONFIG_DIR/.claude.json
  • When CLAUDE_CONFIG_DIR is unset or empty: Configuration falls back to $HOME/.claude.json
  • Priority: Existing files in CLAUDE_CONFIG_DIR location are used first if they exist

Testing

All existing tests pass, plus new tests added:

  • TestIsPathValid: Validates path checking logic for defined, undefined, and empty environment variables
  • TestGlobalCfgProcessor_Update_WithEnvVarPaths: Verifies configuration uses custom directory when CLAUDE_CONFIG_DIR is set
  • TestGlobalCfgProcessor_Update_FallbackWhenEnvVarUndefined: Verifies fallback to default location when variable is not set
  • TestGlobalCfgProcessor_Update_AllPathsInvalid: Verifies proper error handling

This PR fixes #225

…environment variable

- Introduced environment variable handling in the MCP CLI for custom config paths.
- Updated config.yml to include CLAUDE_CONFIG_DIR in path checks.
- Implemented isPathValid function to validate paths with environment variables.
- Added tests for path validation and configuration updates with environment variables.
@jandroav jandroav requested a review from a team as a code owner November 8, 2025 06:46
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.

CLAUDE_CONFIG_DIR not handled

1 participant