@@ -400,21 +400,21 @@ func mcpServerHandler(inv *serpent.Invocation, client *codersdk.Client, instruct
400
400
)
401
401
402
402
// Create a new context for the tools with all relevant information.
403
- clientCtx := toolsdk .WithClient ( ctx , client )
403
+ tb := toolsdk .NewToolbox ( client )
404
404
// Get the workspace agent token from the environment.
405
405
var hasAgentClient bool
406
406
if agentToken , err := getAgentToken (fs ); err == nil && agentToken != "" {
407
407
hasAgentClient = true
408
408
agentClient := agentsdk .New (client .URL )
409
409
agentClient .SetSessionToken (agentToken )
410
- clientCtx = toolsdk .WithAgentClient (clientCtx , agentClient )
410
+ tb = tb .WithAgentClient (agentClient )
411
411
} else {
412
412
cliui .Warnf (inv .Stderr , "CODER_AGENT_TOKEN is not set, task reporting will not be available" )
413
413
}
414
414
if appStatusSlug == "" {
415
415
cliui .Warnf (inv .Stderr , "CODER_MCP_APP_STATUS_SLUG is not set, task reporting will not be available." )
416
416
} else {
417
- clientCtx = toolsdk . WithWorkspaceAppStatusSlug ( clientCtx , appStatusSlug )
417
+ tb = tb . WithAppStatusSlug ( appStatusSlug )
418
418
}
419
419
420
420
// Register tools based on the allowlist (if specified)
@@ -427,15 +427,15 @@ func mcpServerHandler(inv *serpent.Invocation, client *codersdk.Client, instruct
427
427
if len (allowedTools ) == 0 || slices .ContainsFunc (allowedTools , func (t string ) bool {
428
428
return t == tool .Tool .Name
429
429
}) {
430
- mcpSrv .AddTools (mcpFromSDK (tool ))
430
+ mcpSrv .AddTools (mcpFromSDK (tool , tb ))
431
431
}
432
432
}
433
433
434
434
srv := server .NewStdioServer (mcpSrv )
435
435
done := make (chan error )
436
436
go func () {
437
437
defer close (done )
438
- srvErr := srv .Listen (clientCtx , invStdin , invStdout )
438
+ srvErr := srv .Listen (ctx , invStdin , invStdout )
439
439
done <- srvErr
440
440
}()
441
441
@@ -695,7 +695,7 @@ func getAgentToken(fs afero.Fs) (string, error) {
695
695
696
696
// mcpFromSDK adapts a toolsdk.Tool to go-mcp's server.ServerTool.
697
697
// It assumes that the tool responds with a valid JSON object.
698
- func mcpFromSDK (sdkTool toolsdk.Tool [any , any ]) server.ServerTool {
698
+ func mcpFromSDK (sdkTool toolsdk.Tool [any , any ], tb toolsdk. Toolbox ) server.ServerTool {
699
699
// NOTE: some clients will silently refuse to use tools if there is an issue
700
700
// with the tool's schema or configuration.
701
701
if sdkTool .Schema .Properties == nil {
@@ -711,8 +711,8 @@ func mcpFromSDK(sdkTool toolsdk.Tool[any, any]) server.ServerTool {
711
711
Required : sdkTool .Schema .Required ,
712
712
},
713
713
},
714
- Handler : func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
715
- result , err := sdkTool .Handler (ctx , request .Params .Arguments )
714
+ Handler : func (_ context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
715
+ result , err := sdkTool .Handler (tb , request .Params .Arguments )
716
716
if err != nil {
717
717
return nil , err
718
718
}
0 commit comments