Skip to content

refactor: simplify NewServerTool naming#2510

Merged
SamMorrowDrums merged 1 commit into
mainfrom
sammorrowdrums/redo-new-server-tool-cleanup
May 20, 2026
Merged

refactor: simplify NewServerTool naming#2510
SamMorrowDrums merged 1 commit into
mainfrom
sammorrowdrums/redo-new-server-tool-cleanup

Conversation

@SamMorrowDrums
Copy link
Copy Markdown
Collaborator

Summary

Cleanup of the NewServerTool* constructor naming in pkg/inventory. Re-do of #1800 against current main (the original PR was stacked on a branch that no longer reflects the codebase).

What changed

  • Renamed NewServerToolFromHandlerNewServerTool (the simpler, preferred name for the raw handler constructor)
  • Renamed the deprecated generic NewServerTool[In, Out]NewServerToolWithDeps to free up the simpler name and make its closure-based nature explicit in the name
  • Removed NewServerToolWithRawContextHandler — it had no real callers other than a thin pass-through and just duplicated NewServerTool's behavior
  • Updated all call sites:
    • pkg/github/dependencies.go (NewToolFromHandler)
    • pkg/github/dynamic_tools.go (NewDynamicToolNewServerToolWithDeps)
    • pkg/inventory/registry_test.go (3 mock tool helpers)

MCP impact

  • No tool or API changes — internal refactor only

Lint & tests

  • script/lint — 0 issues
  • script/test — all tests pass

Docs

  • Not needed — internal function rename, no user-facing documentation

@SamMorrowDrums SamMorrowDrums requested a review from a team as a code owner May 20, 2026 08:01
Copilot AI review requested due to automatic review settings May 20, 2026 08:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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] to NewServerToolWithDeps[In, Out].
  • Renamed NewServerToolFromHandler to NewServerTool and removed NewServerToolWithRawContextHandler.
  • 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 thread pkg/inventory/server_tool.go Outdated
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 thread pkg/github/dependencies.go Outdated
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
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>
@SamMorrowDrums SamMorrowDrums force-pushed the sammorrowdrums/redo-new-server-tool-cleanup branch from 5b022ba to 39dcba6 Compare May 20, 2026 08:12
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 SamMorrowDrums merged commit 970155a into main May 20, 2026
18 checks passed
@SamMorrowDrums SamMorrowDrums deleted the sammorrowdrums/redo-new-server-tool-cleanup branch May 20, 2026 08:14
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants