8000 fix(cli): modify `exp mcp configure` to also read claude API key from… · coder/coder@4aa45a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4aa45a5

Browse files
authored
fix(cli): modify exp mcp configure to also read claude API key from CLAUDE_API_KEY env (#17229)
Currently you have to set `CODER_MCP_CLAUDE_API_KEY`, which can be obnoxious.
1 parent 998724d commit 4aa45a5

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

cli/exp_mcp.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,14 @@ func (*RootCmd) mcpConfigureClaudeDesktop() *serpent.Command {
110110

111111
func (*RootCmd) mcpConfigureClaudeCode() *serpent.Command {
112112
var (
113-
apiKey string
113+
claudeAPIKey string
114114
claudeConfigPath string
115115
claudeMDPath string
116116
systemPrompt string
117117
appStatusSlug string
118118
testBinaryName string
119+
120+
deprecatedCoderMCPClaudeAPIKey string
119121
)
120122
cmd := &serpent.Command{
121123
Use: "claude-code <project-directory>",
@@ -140,6 +142,14 @@ func (*RootCmd) mcpConfigureClaudeCode() *serpent.Command {
140142
} else {
141143
configureClaudeEnv["CODER_AGENT_TOKEN"] = agentToken
142144
}
145+
if claudeAPIKey == "" {
146+
if deprecatedCoderMCPClaudeAPIKey == "" {
147+
cliui.Warnf(inv.Stderr, "CLAUDE_API_KEY is not set.")
148+
} else {
149+
cliui.Warnf(inv.Stderr, "CODER_MCP_CLAUDE_API_KEY is deprecated, use CLAUDE_API_KEY instead")
150+
claudeAPIKey = deprecatedCoderMCPClaudeAPIKey
151+
}
152+
}
143153
if appStatusSlug != "" {
144154
configureClaudeEnv["CODER_MCP_APP_STATUS_SLUG"] = appStatusSlug
145155
}
@@ -151,7 +161,7 @@ func (*RootCmd) mcpConfigureClaudeCode() *serpent.Command {
151161
if err := configureClaude(fs, ClaudeConfig{
152162
// TODO: will this always be stable?
153163
AllowedTools: []string{`mcp__coder__coder_report_task`},
154-
APIKey: apiKey,
164+
APIKey: claudeAPIKey,
155165
ConfigPath: claudeConfigPath,
156166
ProjectDirectory: projectDirectory,
157167
MCPServers: map[string]ClaudeConfigMCP{
@@ -191,11 +201,18 @@ func (*RootCmd) mcpConfigureClaudeCode() *serpent.Command {
191201
Default: filepath.Join(os.Getenv("HOME"), ".claude", "CLAUDE.md"),
192202
},
193203
{
194-
Name: "api-key",
195-
Description: "The API key to use for the Claude Code server.",
196-
Env: "CODER_MCP_CLAUDE_API_KEY",
204+
Name: "claude-api-key",
205+
Description: "The API key to use for the Claude Code server. This is also read from CLAUDE_API_KEY.",
206+
Env: "CLAUDE_API_KEY",
197207
Flag: "claude-api-key",
198-
Value: serpent.StringOf(&apiKey),
208+
Value: serpent.StringOf(&claudeAPIKey),
209+
},
210+
{
211+
Name: "mcp-claude-api-key",
212+
Description: "Hidden alias for CLAUDE_API_KEY. This will be removed in a future version.",
213+
Env: "CODER_MCP_CLAUDE_API_KEY",
214+
Value: serpent.StringOf(&deprecatedCoderMCPClaudeAPIKey),
215+
Hidden: true,
199216
},
200217
{
201218
Name: "system-prompt",

0 commit comments

Comments
 (0)
0