MCPcopy
hub / github.com/github/github-mcp-server / NewServerTool

Function NewServerTool

pkg/inventory/server_tool.go:158–167  ·  view source on GitHub ↗

NewServerTool creates a ServerTool with a raw handler that receives deps via context. This is the preferred constructor for tools that use mcp.ToolHandler directly because it doesn't create closures at registration time, which is critical for performance in servers that create a new instance per req

(tool mcp.Tool, toolset ToolsetMetadata, handler mcp.ToolHandler)

Source from the content-addressed store, hash-verified

156// The handler function is stored directly without wrapping in a deps closure.
157// Dependencies should be injected into context before calling tool handlers.
158func NewServerTool(tool mcp.Tool, toolset ToolsetMetadata, handler mcp.ToolHandler) ServerTool {
159 return ServerTool{
160 Tool: tool,
161 Toolset: toolset,
162 // HandlerFunc ignores deps - deps are retrieved from context at call time
163 HandlerFunc: func(_ any) mcp.ToolHandler {
164 return handler
165 },
166 }
167}

Callers 4

NewToolFromHandlerFunction · 0.92
mockToolWithDefaultFunction · 0.85
mockToolFunction · 0.85
mockToolWithMetaFunction · 0.85

Calls

no outgoing calls

Tested by 3

mockToolWithDefaultFunction · 0.68
mockToolFunction · 0.68
mockToolWithMetaFunction · 0.68