refactor: simplify NewServerTool naming#2510
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors constructor naming in pkg/inventory to make the “raw handler” constructor the simple default (NewServerTool) and to clarify the deprecated, closure-based generic constructor (NewServerToolWithDeps), updating all internal call sites accordingly.
Changes:
- Renamed deprecated generic
NewServerTool[In, Out]toNewServerToolWithDeps[In, Out]. - Renamed
NewServerToolFromHandlertoNewServerTooland removedNewServerToolWithRawContextHandler. - Updated usages in GitHub tool wiring and inventory tests.
Show a summary per file
| File | Description |
|---|---|
| pkg/inventory/server_tool.go | Renames/reshapes ServerTool constructors and removes NewServerToolWithRawContextHandler. |
| pkg/inventory/registry_test.go | Updates test helpers to use the renamed NewServerTool. |
| pkg/github/dynamic_tools.go | Switches dynamic tools to use NewServerToolWithDeps (deprecated constructor) explicitly. |
| pkg/github/dependencies.go | Updates raw-handler tool creation to use NewServerTool instead of the removed raw-context helper. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 2
Comment on lines
169
to
173
| // NewServerTool creates a ServerTool from a tool definition, toolset metadata, and a raw handler function. | ||
| // Use this when you have a handler that already conforms to mcp.ToolHandler. | ||
| // | ||
| // Deprecated: This creates closures at registration time. For better performance in | ||
| // per-request server scenarios, use NewServerToolWithRawContextHandler instead. | ||
| func NewServerToolFromHandler(tool mcp.Tool, toolset ToolsetMetadata, handlerFn func(deps any) mcp.ToolHandler) ServerTool { | ||
| func NewServerTool(tool mcp.Tool, toolset ToolsetMetadata, handlerFn func(deps any) mcp.ToolHandler) ServerTool { | ||
| return ServerTool{Tool: tool, Toolset: toolset, HandlerFunc: handlerFn} | ||
| } |
Comment on lines
+256
to
+260
| st := inventory.NewServerTool(tool, toolset, func(_ any) mcp.ToolHandler { | ||
| return func(ctx context.Context, req *mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||
| deps := MustDepsFromContext(ctx) | ||
| return handler(ctx, deps, req) | ||
| } |
RossTarrant
previously approved these changes
May 20, 2026
- Rename NewServerToolWithRawContextHandler -> NewServerTool. This is the preferred constructor for raw mcp.ToolHandler tools because it avoids creating closures at registration time, which matters for per-request servers that re-register all tools on every request. - Rename deprecated generic NewServerTool[In, Out] -> NewServerToolWithDeps to free up the simpler name and make its closure-based nature explicit. The dynamic tools package is the only legitimate user of this constructor because DynamicToolDependencies differs from the standard ToolDependencies. - Remove deprecated NewServerToolFromHandler. Its only callers can use the new NewServerTool directly via context-injected deps. - Update all call sites in dependencies.go, dynamic_tools.go, and registry_test.go. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
5b022ba to
39dcba6
Compare
SamMorrowDrums
added a commit
that referenced
this pull request
May 20, 2026
When tool argument unmarshalling fails (wrong types, malformed JSON), return a CallToolResult with IsError: true instead of a Go error. Returning a Go error is converted by the SDK into a JSON-RPC protocol error (-32603), which is invisible to agents and prevents self-correction. Returning IsError: true with the validation message lets agents see the problem and retry with corrected arguments. Affects: - NewServerToolWithDeps (was NewServerTool prior to the rename in #2510) - NewServerToolWithContextHandler Fixes #1952. Re-applies #2488 by @blackwell-systems on top of the NewServerTool rename. Co-authored-by: blackwell-systems <236632453+blackwell-systems@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
SamMorrowDrums
added a commit
that referenced
this pull request
May 20, 2026
* refactor: simplify NewServerTool naming - Rename NewServerToolWithRawContextHandler -> NewServerTool. This is the preferred constructor for raw mcp.ToolHandler tools because it avoids creating closures at registration time, which matters for per-request servers that re-register all tools on every request. - Rename deprecated generic NewServerTool[In, Out] -> NewServerToolWithDeps to free up the simpler name and make its closure-based nature explicit. The dynamic tools package is the only legitimate user of this constructor because DynamicToolDependencies differs from the standard ToolDependencies. - Remove deprecated NewServerToolFromHandler. Its only callers can use the new NewServerTool directly via context-injected deps. - Update all call sites in dependencies.go, dynamic_tools.go, and registry_test.go. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: return isError for argument validation failures When tool argument unmarshalling fails (wrong types, malformed JSON), return a CallToolResult with IsError: true instead of a Go error. Returning a Go error is converted by the SDK into a JSON-RPC protocol error (-32603), which is invisible to agents and prevents self-correction. Returning IsError: true with the validation message lets agents see the problem and retry with corrected arguments. Affects: - NewServerToolWithDeps (was NewServerTool prior to the rename in #2510) - NewServerToolWithContextHandler Fixes #1952. Re-applies #2488 by @blackwell-systems on top of the NewServerTool rename. Co-authored-by: blackwell-systems <236632453+blackwell-systems@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: blackwell-systems <236632453+blackwell-systems@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cleanup of the
NewServerTool*constructor naming inpkg/inventory. Re-do of #1800 against currentmain(the original PR was stacked on a branch that no longer reflects the codebase).What changed
NewServerToolFromHandler→NewServerTool(the simpler, preferred name for the raw handler constructor)NewServerTool[In, Out]→NewServerToolWithDepsto free up the simpler name and make its closure-based nature explicit in the nameNewServerToolWithRawContextHandler— it had no real callers other than a thin pass-through and just duplicatedNewServerTool's behaviorpkg/github/dependencies.go(NewToolFromHandler)pkg/github/dynamic_tools.go(NewDynamicTool→NewServerToolWithDeps)pkg/inventory/registry_test.go(3 mock tool helpers)MCP impact
Lint & tests
script/lint— 0 issuesscript/test— all tests passDocs