Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c97ac4

Browse files
committed
fixup! add WithCleanContext middleware func
1 parent 7226330 commit 6c97ac4

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

cli/exp_mcp.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,8 @@ func mcpFromSDK(sdkTool toolsdk.Tool[any, any], tb toolsdk.Deps) server.ServerTo
713713
Required: sdkTool.Schema.Required,
714714
},
715715
},
716-
Handler: func(_ context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
717-
result, err := sdkTool.Handler(tb, request.Params.Arguments)
716+
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
717+
result, err := sdkTool.Handler(ctx, tb, request.Params.Arguments)
718718
if err != nil {
719719
return nil, err
720720
}

codersdk/toolsdk/toolsdk.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Deps struct {
2121
}
2222

2323
// HandlerFunc is a function that handles a tool call.
24-
type HandlerFunc[Arg, Ret any] func(tb Deps, args Arg) (Ret, error)
24+
type HandlerFunc[Arg, Ret any] func(context.Context, Deps, Arg) (Ret, error)
2525

2626
type Tool[Arg, Ret any] struct {
2727
aisdk.Tool
@@ -32,12 +32,12 @@ type Tool[Arg, Ret any] struct {
3232
func (t Tool[Arg, Ret]) Generic() Tool[any, any] {
3333
return Tool[any, any]{
3434
Tool: t.Tool,
35-
Handler: func(tb Deps, args any) (any, error) {
35+
Handler: func(ctx context.Context, tb Deps, args any) (any, error) {
3636
typedArg, ok := args.(Arg)
3737
if !ok {
3838
return nil, xerrors.Errorf("developer error: invalid argument type for tool %s", t.Tool.Name)
3939
}
40-
return t.Handler(tb, typedArg)
40+
return t.Handler(ctx, tb, typedArg)
4141
},
4242
}
4343
}
@@ -165,7 +165,7 @@ func wrapAll(mw func(HandlerFunc[any, any]) HandlerFunc[any, any], tools ...Tool
165165
var (
166166
// All is a list of all tools that can be used in the Coder CLI.
167167
// When you add a new tool, be sure to include it here!
168-
All = wrapAll(WithRecover,
168+
All = wrapAll(WithCleanContext, wrapAll(WithRecover,
169169
CreateTemplate.Generic(),
170170
CreateTemplateVersion.Generic(),
171171
CreateWorkspace.Generic(),
@@ -182,7 +182,7 @@ var (
182182
ReportTask.Generic(),
183183
UploadTarFile.Generic(),
184184
UpdateTemplateActiveVersion.Generic(),
185-
)
185+
)...)
186186

187187
ReportTask = Tool[ReportTaskArgs, string]{
188188
Tool: aisdk.Tool{

0 commit comments

Comments
 (0)