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

Method RegisterFunc

pkg/inventory/server_tool.go:111–120  ·  view source on GitHub ↗

RegisterFunc registers the tool with the server using the provided dependencies. Icons are automatically applied from the toolset metadata if not already set. A shallow copy of the tool is made to avoid mutating the original ServerTool. Panics if the tool has no handler - all tools should have handl

(s *mcp.Server, deps any)

Source from the content-addressed store, hash-verified

109// A shallow copy of the tool is made to avoid mutating the original ServerTool.
110// Panics if the tool has no handler - all tools should have handlers.
111func (st *ServerTool) RegisterFunc(s *mcp.Server, deps any) {
112 handler := st.Handler(deps) // This will panic if HandlerFunc is nil
113 // Make a shallow copy of the tool to avoid mutating the original
114 toolCopy := st.Tool
115 // Apply icons from toolset metadata if tool doesn't have icons set
116 if len(toolCopy.Icons) == 0 {
117 toolCopy.Icons = st.Toolset.Icons()
118 }
119 s.AddTool(&toolCopy, handler)
120}
121
122// NewServerToolWithContextHandler creates a ServerTool with a handler that receives deps via context.
123// This is the preferred approach for tools because it doesn't create closures at registration time,

Callers 1

RegisterToolsMethod · 0.80

Calls 2

HandlerMethod · 0.95
IconsMethod · 0.80

Tested by

no test coverage detected