Skip to content

Commit 345584c

Browse files
Rename NewServerToolWithRawContextHandler to NewServerTool
- Renamed deprecated NewServerTool[In, Out] to NewServerToolWithDeps[In, Out] - Updated dynamic_tools.go to use NewServerToolWithDeps (for special case with DynamicToolDependencies) - Renamed NewServerToolWithRawContextHandler to NewServerTool - Updated all call sites in dependencies.go and registry_test.go - All tests pass, linter passes Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
1 parent 02314ef commit 345584c

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

pkg/github/dependencies.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func NewToolFromHandler(
182182
requiredScopes []scopes.Scope,
183183
handler func(ctx context.Context, deps ToolDependencies, req *mcp.CallToolRequest) (*mcp.CallToolResult, error),
184184
) inventory.ServerTool {
185-
st := inventory.NewServerToolWithRawContextHandler(tool, toolset, func(ctx context.Context, req *mcp.CallToolRequest) (*mcp.CallToolResult, error) {
185+
st := inventory.NewServerTool(tool, toolset, func(ctx context.Context, req *mcp.CallToolRequest) (*mcp.CallToolResult, error) {
186186
deps := MustDepsFromContext(ctx)
187187
return handler(ctx, deps, req)
188188
})

pkg/github/dynamic_tools.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ type DynamicToolDependencies struct {
2828

2929
// NewDynamicTool creates a ServerTool with fully-typed DynamicToolDependencies.
3030
// Dynamic tools use a different dependency structure (DynamicToolDependencies) than regular
31-
// tools (ToolDependencies), so they intentionally use the closure pattern.
31+
// tools (ToolDependencies), so they use NewServerToolWithDeps which creates closures.
3232
func NewDynamicTool(toolset inventory.ToolsetMetadata, tool mcp.Tool, handler func(deps DynamicToolDependencies) mcp.ToolHandlerFor[map[string]any, any]) inventory.ServerTool {
33-
//nolint:staticcheck // SA1019: Dynamic tools use a different deps structure, closure pattern is intentional
34-
return inventory.NewServerTool(tool, toolset, func(d any) mcp.ToolHandlerFor[map[string]any, any] {
33+
return inventory.NewServerToolWithDeps(tool, toolset, func(d any) mcp.ToolHandlerFor[map[string]any, any] {
3534
return handler(d.(DynamicToolDependencies))
3635
})
3736
}

pkg/inventory/registry_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func testToolsetMetadataWithDefault(id string, isDefault bool) ToolsetMetadata {
2828

2929
// mockToolWithDefault creates a mock tool with a default toolset flag
3030
func mockToolWithDefault(name string, toolsetID string, readOnly bool, isDefault bool) ServerTool {
31-
return NewServerToolWithRawContextHandler(
31+
return NewServerTool(
3232
mcp.Tool{
3333
Name: name,
3434
Annotations: &mcp.ToolAnnotations{
@@ -45,7 +45,7 @@ func mockToolWithDefault(name string, toolsetID string, readOnly bool, isDefault
4545

4646
// mockTool creates a minimal ServerTool for testing
4747
func mockTool(name string, toolsetID string, readOnly bool) ServerTool {
48-
return NewServerToolWithRawContextHandler(
48+
return NewServerTool(
4949
mcp.Tool{
5050
Name: name,
5151
Annotations: &mcp.ToolAnnotations{

pkg/inventory/server_tool.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ func (st *ServerTool) RegisterFunc(s *mcp.Server, deps any) {
115115
s.AddTool(&toolCopy, handler)
116116
}
117117

118-
// NewServerTool creates a ServerTool from a tool definition, toolset metadata, and a typed handler function.
118+
// NewServerToolWithDeps creates a ServerTool from a tool definition, toolset metadata, and a typed handler function.
119119
// The handler function takes dependencies (as any) and returns a typed handler.
120120
// Callers should type-assert deps to their typed dependencies struct.
121121
//
122-
// Deprecated: This creates closures at registration time. For better performance in
123-
// per-request server scenarios, use NewServerToolWithContextHandler instead.
124-
func NewServerTool[In any, Out any](tool mcp.Tool, toolset ToolsetMetadata, handlerFn func(deps any) mcp.ToolHandlerFor[In, Out]) ServerTool {
122+
// This function creates closures at registration time and should only be used for special cases
123+
// where the deps structure differs from the standard ToolDependencies (e.g., dynamic tools).
124+
// For regular tools, use NewServerToolWithContextHandler or NewServerTool instead.
125+
func NewServerToolWithDeps[In any, Out any](tool mcp.Tool, toolset ToolsetMetadata, handlerFn func(deps any) mcp.ToolHandlerFor[In, Out]) ServerTool {
125126
return ServerTool{
126127
Tool: tool,
127128
Toolset: toolset,
@@ -163,13 +164,13 @@ func NewServerToolWithContextHandler[In any, Out any](tool mcp.Tool, toolset Too
163164
}
164165
}
165166

166-
// NewServerToolWithRawContextHandler creates a ServerTool with a raw handler that receives deps via context.
167+
// NewServerTool creates a ServerTool with a raw handler that receives deps via context.
167168
// This is the preferred approach for tools that use mcp.ToolHandler directly because it doesn't
168169
// create closures at registration time.
169170
//
170171
// The handler function is stored directly without wrapping in a deps closure.
171172
// Dependencies should be injected into context before calling tool handlers.
172-
func NewServerToolWithRawContextHandler(tool mcp.Tool, toolset ToolsetMetadata, handler mcp.ToolHandler) ServerTool {
173+
func NewServerTool(tool mcp.Tool, toolset ToolsetMetadata, handler mcp.ToolHandler) ServerTool {
173174
return ServerTool{
174175
Tool: tool,
175176
Toolset: toolset,

0 commit comments

Comments
 (0)