Skip to content

Commit e348d1e

Browse files
committed
require project directory
1 parent 769a1eb commit e348d1e

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

cli/exp_mcp.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,17 @@ func (*RootCmd) mcpConfigureClaudeCode() *serpent.Command {
111111
var (
112112
apiKey string
113113
claudeConfigPath string
114-
projectDirectory string
115114
systemPrompt string
116-
taskPrompt string
117115
testBinaryName string
118116
)
119117
cmd := &serpent.Command{
120-
Use: "claude-code",
121-
Short: "Configure the Claude Code server.",
118+
Use: "claude-code <project-directory>",
119+
Short: "Configure the Claude Code server. You will need to run this command for each project you want to use. Specify the project directory as the first argument.",
122120
Handler: func(inv *serpent.Invocation) error {
121+
if len(inv.Args) == 0 {
122+
return xerrors.Errorf("project directory is required")
123+
}
124+
projectDirectory := inv.Args[0]
123125
fs := afero.NewOsFs()
124126
binPath, err := os.Executable()
125127
if err != nil {
@@ -174,20 +176,6 @@ func (*RootCmd) mcpConfigureClaudeCode() *serpent.Command {
174176
Flag: "claude-system-prompt",
175177
Value: serpent.StringOf(&systemPrompt),
176178
},
177-
{
178-
Name: "task-prompt",
179-
Description: "The task prompt to use for the Claude Code server.",
180-
Env: "CODER_MCP_CLAUDE_TASK_PROMPT",
181-
Flag: "claude-task-prompt",
182-
Value: serpent.StringOf(&taskPrompt),
183-
},
184-
{
185-
Name: "project-directory",
186-
Description: "The project directory to use for the Claude Code server.",
187-
Env: "CODER_MCP_CLAUDE_PROJECT_DIRECTORY",
188-
Flag: "claude-project-directory",
189-
Value: serpent.StringOf(&projectDirectory),
190-
},
191179
{
192180
Name: "test-binary-name",
193181
Description: "Only used for testing.",
@@ -428,7 +416,7 @@ func configureClaude(fs afero.Fs, cfg ClaudeConfig) error {
428416
return xerrors.Errorf("failed to stat claude config: %w", err)
429417
}
430418
// Touch the file to create it if it doesn't exist.
431-
if err = afero.WriteFile(fs, cfg.ConfigPath, []byte(`{}`), 0600); err != nil {
419+
if err = afero.WriteFile(fs, cfg.ConfigPath, []byte(`{}`), 0o600); err != nil {
432420
return xerrors.Errorf("failed to touch claude config: %w", err)
433421
}
434422
}
@@ -513,7 +501,7 @@ func configureClaude(fs afero.Fs, cfg ClaudeConfig) error {
513501
if err != nil {
514502
return xerrors.Errorf("failed to marshal claude config: %w", err)
515503
}
516-
err = afero.WriteFile(fs, cfg.ConfigPath, newConfigBytes, 0644)
504+
err = afero.WriteFile(fs, cfg.ConfigPath, newConfigBytes, 0o644)
517505
if err != nil {
518506
return xerrors.Errorf("failed to write claude config: %w", err)
519507
}

cli/exp_mcp_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,18 @@ func TestExpMcpServer(t *testing.T) {
143143
})
144144
}
145145

146-
func TestExpMcpConfigure(t *testing.T) {
147-
t.Run("ClaudeCode", func(t *testing.T) {
146+
//nolint:tparallel,paralleltest
147+
func TestExpMcpConfigureClaudeCode(t *testing.T) {
148+
t.Run("NoProjectDirectory", func(t *testing.T) {
149+
ctx := testutil.Context(t, testutil.WaitShort)
150+
cancelCtx, cancel := context.WithCancel(ctx)
151+
t.Cleanup(cancel)
152+
153+
inv, _ := clitest.New(t, "exp", "mcp", "configure", "claude-code")
154+
err := inv.WithContext(cancelCtx).Run()
155+
require.ErrorContains(t, err, "project directory is required")
156+
})
157+
t.Run("NewConfig", func(t *testing.T) {
148158
t.Setenv("CODER_AGENT_TOKEN", "test-agent-token")
149159
ctx := testutil.Context(t, testutil.WaitShort)
150160
cancelCtx, cancel := context.WithCancel(ctx)
@@ -182,12 +192,10 @@ func TestExpMcpConfigure(t *testing.T) {
182192
}
183193
}`
184194

185-
inv, root := clitest.New(t, "exp", "mcp", "configure", "claude-code",
195+
inv, root := clitest.New(t, "exp", "mcp", "configure", "claude-code", "/path/to/project",
186196
"--claude-api-key=test-api-key",
187197
"--claude-config-path="+claudeConfigPath,
188-
"--claude-project-directory=/path/to/project",
189198
"--claude-system-prompt=test-system-prompt",
190-
"--claude-task-prompt=test-task-prompt",
191199
"--claude-test-binary-name=pathtothecoderbinary",
192200
)
193201
clitest.SetupConfig(t, client, root)
@@ -246,12 +254,10 @@ func TestExpMcpConfigure(t *testing.T) {
246254
}
247255
}`
248256

249-
inv, root := clitest.New(t, "exp", "mcp", "configure", "claude-code",
257+
inv, root := clitest.New(t, "exp", "mcp", "configure", "claude-code", "/path/to/project",
250258
"--claude-api-key=test-api-key",
251259
"--claude-config-path="+claudeConfigPath,
252-
"--claude-project-directory=/path/to/project",
253260
"--claude-system-prompt=test-system-prompt",
254-
"--claude-task-prompt=test-task-prompt",
255261
"--claude-test-binary-name=pathtothecoderbinary",
256262
)
257263

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy