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

Function NewTool

pkg/github/dependencies.go:227–240  ·  view source on GitHub ↗

NewTool creates a ServerTool that retrieves ToolDependencies from context at call time. This avoids creating closures at registration time, which is important for performance in servers that create a new server instance per request (like the remote server). The handler function receives deps extrac

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

Source from the content-addressed store, hash-verified

225// AcceptedScopes are automatically derived using the scope hierarchy (e.g., if
226// public_repo is required, repo is also accepted since repo grants public_repo).
227func NewTool[In, Out any](
228 toolset inventory.ToolsetMetadata,
229 tool mcp.Tool,
230 requiredScopes []scopes.Scope,
231 handler func(ctx context.Context, deps ToolDependencies, req *mcp.CallToolRequest, args In) (*mcp.CallToolResult, Out, error),
232) inventory.ServerTool {
233 st := inventory.NewServerToolWithContextHandler(tool, toolset, func(ctx context.Context, req *mcp.CallToolRequest, args In) (*mcp.CallToolResult, Out, error) {
234 deps := MustDepsFromContext(ctx)
235 return handler(ctx, deps, req, args)
236 })
237 st.RequiredScopes = scopes.ToStringSlice(requiredScopes...)
238 st.AcceptedScopes = scopes.ExpandScopes(requiredScopes...)
239 return st
240}
241
242// NewToolFromHandler creates a ServerTool that retrieves ToolDependencies from context at call time.
243// Use this when you have a handler that conforms to mcp.ToolHandler directly.

Callers 15

GetCommitFunction · 0.85
ListCommitsFunction · 0.85
ListBranchesFunction · 0.85
CreateOrUpdateFileFunction · 0.85
CreateRepositoryFunction · 0.85
GetFileContentsFunction · 0.85
ForkRepositoryFunction · 0.85
DeleteFileFunction · 0.85
CreateBranchFunction · 0.85
PushFilesFunction · 0.85
ListTagsFunction · 0.85
GetTagFunction · 0.85

Calls 4

ToStringSliceFunction · 0.92
ExpandScopesFunction · 0.92
MustDepsFromContextFunction · 0.85

Tested by 1

HelloWorldToolFunction · 0.68