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

Function NewToolFromHandler

pkg/github/dependencies.go:250–263  ·  view source on GitHub ↗

NewToolFromHandler creates a ServerTool that retrieves ToolDependencies from context at call time. Use this when you have a handler that conforms to mcp.ToolHandler directly. The handler function receives deps extracted from context via MustDepsFromContext. Ensure ContextWithDeps is called to injec

(
	toolset inventory.ToolsetMetadata,
	tool mcp.Tool,
	requiredScopes []scopes.Scope,
	handler func(ctx context.Context, deps ToolDependencies, req *mcp.CallToolRequest) (*mcp.CallToolResult, error),
)

Source from the content-addressed store, hash-verified

248// requiredScopes specifies the minimum OAuth scopes needed for this tool.
249// AcceptedScopes are automatically derived using the scope hierarchy.
250func NewToolFromHandler(
251 toolset inventory.ToolsetMetadata,
252 tool mcp.Tool,
253 requiredScopes []scopes.Scope,
254 handler func(ctx context.Context, deps ToolDependencies, req *mcp.CallToolRequest) (*mcp.CallToolResult, error),
255) inventory.ServerTool {
256 st := inventory.NewServerTool(tool, toolset, func(ctx context.Context, req *mcp.CallToolRequest) (*mcp.CallToolResult, error) {
257 deps := MustDepsFromContext(ctx)
258 return handler(ctx, deps, req)
259 })
260 st.RequiredScopes = scopes.ToStringSlice(requiredScopes...)
261 st.AcceptedScopes = scopes.ExpandScopes(requiredScopes...)
262 return st
263}
264
265type RequestDeps struct {
266 // Static dependencies

Callers

nothing calls this directly

Calls 4

NewServerToolFunction · 0.92
ToStringSliceFunction · 0.92
ExpandScopesFunction · 0.92
MustDepsFromContextFunction · 0.85

Tested by

no test coverage detected