Skip to content

fix(cli): modify exp mcp configure to also read claude API key from CLAUDE_API_KEY env #17229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions cli/exp_mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ func (*RootCmd) mcpConfigureClaudeDesktop() *serpent.Command {

func (*RootCmd) mcpConfigureClaudeCode() *serpent.Command {
var (
apiKey string
claudeAPIKey string
claudeConfigPath string
claudeMDPath string
systemPrompt string
appStatusSlug string
testBinaryName string

deprecatedCoderMCPClaudeAPIKey string
)
cmd := &serpent.Command{
Use: "claude-code <project-directory>",
Expand All @@ -140,6 +142,14 @@ func (*RootCmd) mcpConfigureClaudeCode() *serpent.Command {
} else {
configureClaudeEnv["CODER_AGENT_TOKEN"] = agentToken
}
if claudeAPIKey == "" {
if deprecatedCoderMCPClaudeAPIKey == "" {
cliui.Warnf(inv.Stderr, "CLAUDE_API_KEY is not set.")
} else {
cliui.Warnf(inv.Stderr, "CODER_MCP_CLAUDE_API_KEY is deprecated, use CLAUDE_API_KEY instead")
claudeAPIKey = deprecatedCoderMCPClaudeAPIKey
}
}
if appStatusSlug != "" {
configureClaudeEnv["CODER_MCP_APP_STATUS_SLUG"] = appStatusSlug
}
Expand All @@ -151,7 +161,7 @@ func (*RootCmd) mcpConfigureClaudeCode() *serpent.Command {
if err := configureClaude(fs, ClaudeConfig{
// TODO: will this always be stable?
AllowedTools: []string{`mcp__coder__coder_report_task`},
APIKey: apiKey,
APIKey: claudeAPIKey,
ConfigPath: claudeConfigPath,
ProjectDirectory: projectDirectory,
MCPServers: map[string]ClaudeConfigMCP{
Expand Down Expand Up @@ -191,11 +201,18 @@ func (*RootCmd) mcpConfigureClaudeCode() *serpent.Command {
Default: filepath.Join(os.Getenv("HOME"), ".claude", "CLAUDE.md"),
},
{
Name: "api-key",
Description: "The API key to use for the Claude Code server.",
Env: "CODER_MCP_CLAUDE_API_KEY",
Name: "claude-api-key",
Description: "The API key to use for the Claude Code server. This is also read from CLAUDE_API_KEY.",
Env: "CLAUDE_API_KEY",
Flag: "claude-api-key",
Value: serpent.StringOf(&apiKey),
Value: serpent.StringOf(&claudeAPIKey),
},
{
Name: "mcp-claude-api-key",
Description: "Hidden alias for CLAUDE_API_KEY. This will be removed in a future version.",
Env: "CODER_MCP_CLAUDE_API_KEY",
Value: serpent.StringOf(&deprecatedCoderMCPClaudeAPIKey),
Hidden: true,
},
{
Name: "system-prompt",
Expand Down
Loading