Skip to content

bug: Claude Code module butchers MCP setup, produces invalid config, and overcomplicates script #562

@solidDoWant

Description

@solidDoWant

The Claude Code module MCP server setup via the mcp var produces an invalid MCP config. Here's how the README says to specify MCP servers:

module "claude-code" {
  source   = "registry.coder.com/coder/claude-code/coder"
  version  = "4.2.1"
  agent_id = coder_agent.example.id
  workdir  = "/home/coder/project"

  claude_api_key = "xxxx-xxxxx-xxxx"
  # OR
  claude_code_oauth_token = "xxxxx-xxxx-xxxx"


  mcp = <<-EOF
  {
    "mcpServers": {
      "my-custom-tool": {
        "command": "my-tool-server"
        "args": ["--port", "8080"]
      }
    }
  }
  EOF
}

Rather than just patching the .claude.json config file, this attempts to load the config via claude mcp add, after splitting each tool into key value pairs. The actual command executes in this case is claude mcp add 'my-custom-tool' '{"command": "my-tool-server", "args": ["--port", "8080"]}. The CLI treats this JSON string as a command, producing this MCP config:

{
  "mcpServers": {
    "type": "stdio"
    "command": "{\"command\": \"my-tool-server\", \"args\": [\"--port\", \"8080\"]}",
    "args": [],
    "env": {}
  }
}

It should produce:

{
  "mcpServers": {
    "type": "stdio"
    "command": "my-tool-server",
    "args": ["--port", "8080"],
    "env": {}
  }
}

Even if this somehow worked (e.g. if the code was updated to parse this prior to calling claude mcp add), it wouldn't handle remote MCP servers.

This can be way simplified - just use jq to merge the and/or set the MCP server key within the claude code config.

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions