Skip to content

Commit 00e705a

Browse files
committed
fix(cli): exp mcp: do not add coder_report_task if agent token not available
1 parent bc5d245 commit 00e705a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cli/exp_mcp.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,9 @@ func mcpServerHandler(inv *serpent.Invocation, client *codersdk.Client, instruct
402402
// Create a new context for the tools with all relevant information.
403403
clientCtx := toolsdk.WithClient(ctx, client)
404404
// Get the workspace agent token from the environment.
405+
var hasAgentClient bool
405406
if agentToken, err := getAgentToken(fs); err == nil && agentToken != "" {
407+
hasAgentClient = true
406408
agentClient := agentsdk.New(client.URL)
407409
agentClient.SetSessionToken(agentToken)
408410
clientCtx = toolsdk.WithAgentClient(clientCtx, agentClient)
@@ -417,6 +419,11 @@ func mcpServerHandler(inv *serpent.Invocation, client *codersdk.Client, instruct
417419

418420
// Register tools based on the allowlist (if specified)
419421
for _, tool := range toolsdk.All {
422+
// Skip adding the coder_report_task tool if there is no agent client
423+
if !hasAgentClient && tool.Tool.Name == "coder_report_task" {
424+
cliui.Warnf(inv.Stderr, "Task reporting not available")
425+
continue
426+
}
420427
if len(allowedTools) == 0 || slices.ContainsFunc(allowedTools, func(t string) bool {
421428
return t == tool.Tool.Name
422429
}) {

0 commit comments

Comments
 (0)