Skip to content

Commit 83077fd

Browse files
authored
Merge branch 'main' into main
2 parents 18adf4d + e54aa44 commit 83077fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1862
-2085
lines changed

agent/agent_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,8 +1650,10 @@ func TestAgent_Lifecycle(t *testing.T) {
16501650
t.Run("ShutdownScriptOnce", func(t *testing.T) {
16511651
t.Parallel()
16521652
logger := testutil.Logger(t)
1653+
ctx := testutil.Context(t, testutil.WaitMedium)
16531654
expected := "this-is-shutdown"
16541655
derpMap, _ := tailnettest.RunDERPAndSTUN(t)
1656+
statsCh := make(chan *proto.Stats, 50)
16551657

16561658
client := agenttest.NewClient(t,
16571659
logger,
@@ -1670,7 +1672,7 @@ func TestAgent_Lifecycle(t *testing.T) {
16701672
RunOnStop: true,
16711673
}},
16721674
},
1673-
make(chan *proto.Stats, 50),
1675+
statsCh,
16741676
tailnet.NewCoordinator(logger),
16751677
)
16761678
defer client.Close()
@@ -1695,6 +1697,11 @@ func TestAgent_Lifecycle(t *testing.T) {
16951697
return len(content) > 0 // something is in the startup log file
16961698
}, testutil.WaitShort, testutil.IntervalMedium)
16971699

1700+
// In order to avoid shutting down the agent before it is fully started and triggering
1701+
// errors, we'll wait until the agent is fully up. It's a bit hokey, but among the last things the agent starts
1702+
// is the stats reporting, so getting a stats report is a good indication the agent is fully up.
1703+
_ = testutil.RequireRecvCtx(ctx, t, statsCh)
1704+
16981705
err := agent.Close()
16991706
require.NoError(t, err, "agent should be closed successfully")
17001707

cli/exp_mcp.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,21 +402,28 @@ 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)
409411
} else {
410412
cliui.Warnf(inv.Stderr, "CODER_AGENT_TOKEN is not set, task reporting will not be available")
411413
}
412-
if appStatusSlug != "" {
414+
if appStatusSlug == "" {
413415
cliui.Warnf(inv.Stderr, "CODER_MCP_APP_STATUS_SLUG is not set, task reporting will not be available.")
414416
} else {
415417
clientCtx = toolsdk.WithWorkspaceAppStatusSlug(clientCtx, appStatusSlug)
416418
}
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
}) {
@@ -689,6 +696,11 @@ func getAgentToken(fs afero.Fs) (string, error) {
689696
// mcpFromSDK adapts a toolsdk.Tool to go-mcp's server.ServerTool.
690697
// It assumes that the tool responds with a valid JSON object.
691698
func mcpFromSDK(sdkTool toolsdk.Tool[any]) server.ServerTool {
699+
// NOTE: some clients will silently refuse to use tools if there is an issue
700+
// with the tool's schema or configuration.
701+
if sdkTool.Schema.Properties == nil {
702+
panic("developer error: schema properties cannot be nil")
703+
}
692704
return server.ServerTool{
693705
Tool: mcp.Tool{
694706
Name: sdkTool.Tool.Name,

cli/testdata/coder_list_--output_json.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"count": 0,
6868
"available": 0,
6969
"most_recently_seen": null
70-
}
70+
},
71+
"template_version_preset_id": null
7172
},
7273
"latest_app_status": null,
7374
"outdated": false,

coderd/apidoc/docs.go

Lines changed: 13 additions & 103 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 13 additions & 93 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderdtest/coderdtest.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
421421
handler.ServeHTTP(w, r)
422422
}
423423
}))
424+
t.Logf("coderdtest server listening on %s", srv.Listener.Addr().String())
424425
srv.Config.BaseContext = func(_ net.Listener) context.Context {
425426
return ctx
426427
}
@@ -433,7 +434,12 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
433434
} else {
434435
srv.Start()
435436
}
436-
t.Cleanup(srv.Close)
437+
t.Logf("coderdtest server started on %s", srv.URL)
438+
t.Cleanup(func() {
439+
t.Logf("closing coderdtest server on %s", srv.Listener.Addr().String())
440+
srv.Close()
441+
t.Logf("closed coderdtest server on %s", srv.Listener.Addr().String())
442+
})
437443

438444
tcpAddr, ok := srv.Listener.Addr().(*net.TCPAddr)
439445
require.True(t, ok)

0 commit comments

Comments
 (0)