Skip to content

Commit 26e5bf0

Browse files
refactor: convert projects, labels, and dynamic_tools to NewTool pattern
This PR converts projects.go, labels.go, and dynamic_tools.go from the legacy NewServerToolLegacy wrapper pattern to the new NewTool pattern with proper ToolDependencies. Changes: - projects.go: Convert all 9 project functions to use NewTool with ToolHandlerFor[map[string]any, any] and 3-return-value handlers - projects_test.go: Update tests to use new serverTool.Handler(deps) pattern - labels.go: Convert GetLabel, ListLabels, and LabelWrite to NewTool pattern - labels_test.go: Update tests to use new pattern - dynamic_tools.go: Refactor functions to return ServerTool directly (using NewServerToolLegacy internally since they have special dependencies) - tools.go: Remove NewServerToolLegacy wrappers for dynamic tools registration Co-authored-by: Adam Holt <omgitsads@users.noreply.github.com>
1 parent 3396501 commit 26e5bf0

File tree

6 files changed

+1031
-937
lines changed

6 files changed

+1031
-937
lines changed

pkg/github/dynamic_tools.go

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ func ToolsetEnum(toolsetGroup *toolsets.ToolsetGroup) []any {
2020
return toolsetNames
2121
}
2222

23-
func EnableToolset(s *mcp.Server, toolsetGroup *toolsets.ToolsetGroup, t translations.TranslationHelperFunc) (mcp.Tool, mcp.ToolHandlerFor[map[string]any, any]) {
24-
return mcp.Tool{
25-
Name: "enable_toolset",
26-
Description: t("TOOL_ENABLE_TOOLSET_DESCRIPTION", "Enable one of the sets of tools the GitHub MCP server provides, use get_toolset_tools and list_available_toolsets first to see what this will enable"),
27-
Annotations: &mcp.ToolAnnotations{
28-
Title: t("TOOL_ENABLE_TOOLSET_USER_TITLE", "Enable a toolset"),
29-
// Not modifying GitHub data so no need to show a warning
30-
ReadOnlyHint: true,
31-
},
32-
InputSchema: &jsonschema.Schema{
33-
Type: "object",
34-
Properties: map[string]*jsonschema.Schema{
35-
"toolset": {
36-
Type: "string",
37-
Description: "The name of the toolset to enable",
38-
Enum: ToolsetEnum(toolsetGroup),
39-
},
23+
func EnableToolset(s *mcp.Server, toolsetGroup *toolsets.ToolsetGroup, t translations.TranslationHelperFunc) toolsets.ServerTool {
24+
return toolsets.NewServerToolLegacy(mcp.Tool{
25+
Name: "enable_toolset",
26+
Description: t("TOOL_ENABLE_TOOLSET_DESCRIPTION", "Enable one of the sets of tools the GitHub MCP server provides, use get_toolset_tools and list_available_toolsets first to see what this will enable"),
27+
Annotations: &mcp.ToolAnnotations{
28+
Title: t("TOOL_ENABLE_TOOLSET_USER_TITLE", "Enable a toolset"),
29+
// Not modifying GitHub data so no need to show a warning
30+
ReadOnlyHint: true,
31+
},
32+
InputSchema: &jsonschema.Schema{
33+
Type: "object",
34+
Properties: map[string]*jsonschema.Schema{
35+
"toolset": {
36+
Type: "string",
37+
Description: "The name of the toolset to enable",
38+
Enum: ToolsetEnum(toolsetGroup),
4039
},
41-
Required: []string{"toolset"},
4240
},
41+
Required: []string{"toolset"},
4342
},
43+
},
4444
mcp.ToolHandlerFor[map[string]any, any](func(_ context.Context, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
4545
// We need to convert the toolsets back to a map for JSON serialization
4646
toolsetName, err := RequiredParam[string](args, "toolset")
@@ -64,22 +64,22 @@ func EnableToolset(s *mcp.Server, toolsetGroup *toolsets.ToolsetGroup, t transla
6464
toolset.RegisterTools(s)
6565

6666
return utils.NewToolResultText(fmt.Sprintf("Toolset %s enabled", toolsetName)), nil, nil
67-
})
67+
}))
6868
}
6969

70-
func ListAvailableToolsets(toolsetGroup *toolsets.ToolsetGroup, t translations.TranslationHelperFunc) (mcp.Tool, mcp.ToolHandlerFor[map[string]any, any]) {
71-
return mcp.Tool{
72-
Name: "list_available_toolsets",
73-
Description: t("TOOL_LIST_AVAILABLE_TOOLSETS_DESCRIPTION", "List all available toolsets this GitHub MCP server can offer, providing the enabled status of each. Use this when a task could be achieved with a GitHub tool and the currently available tools aren't enough. Call get_toolset_tools with these toolset names to discover specific tools you can call"),
74-
Annotations: &mcp.ToolAnnotations{
75-
Title: t("TOOL_LIST_AVAILABLE_TOOLSETS_USER_TITLE", "List available toolsets"),
76-
ReadOnlyHint: true,
77-
},
78-
InputSchema: &jsonschema.Schema{
79-
Type: "object",
80-
Properties: map[string]*jsonschema.Schema{},
81-
},
70+
func ListAvailableToolsets(toolsetGroup *toolsets.ToolsetGroup, t translations.TranslationHelperFunc) toolsets.ServerTool {
71+
return toolsets.NewServerToolLegacy(mcp.Tool{
72+
Name: "list_available_toolsets",
73+
Description: t("TOOL_LIST_AVAILABLE_TOOLSETS_DESCRIPTION", "List all available toolsets this GitHub MCP server can offer, providing the enabled status of each. Use this when a task could be achieved with a GitHub tool and the currently available tools aren't enough. Call get_toolset_tools with these toolset names to discover specific tools you can call"),
74+
Annotations: &mcp.ToolAnnotations{
75+
Title: t("TOOL_LIST_AVAILABLE_TOOLSETS_USER_TITLE", "List available toolsets"),
76+
ReadOnlyHint: true,
8277
},
78+
InputSchema: &jsonschema.Schema{
79+
Type: "object",
80+
Properties: map[string]*jsonschema.Schema{},
81+
},
82+
},
8383
mcp.ToolHandlerFor[map[string]any, any](func(_ context.Context, _ *mcp.CallToolRequest, _ map[string]any) (*mcp.CallToolResult, any, error) {
8484
// We need to convert the toolsetGroup back to a map for JSON serialization
8585

@@ -103,29 +103,29 @@ func ListAvailableToolsets(toolsetGroup *toolsets.ToolsetGroup, t translations.T
103103
}
104104

105105
return utils.NewToolResultText(string(r)), nil, nil
106-
})
106+
}))
107107
}
108108

109-
func GetToolsetsTools(toolsetGroup *toolsets.ToolsetGroup, t translations.TranslationHelperFunc) (mcp.Tool, mcp.ToolHandlerFor[map[string]any, any]) {
110-
return mcp.Tool{
111-
Name: "get_toolset_tools",
112-
Description: t("TOOL_GET_TOOLSET_TOOLS_DESCRIPTION", "Lists all the capabilities that are enabled with the specified toolset, use this to get clarity on whether enabling a toolset would help you to complete a task"),
113-
Annotations: &mcp.ToolAnnotations{
114-
Title: t("TOOL_GET_TOOLSET_TOOLS_USER_TITLE", "List all tools in a toolset"),
115-
ReadOnlyHint: true,
116-
},
117-
InputSchema: &jsonschema.Schema{
118-
Type: "object",
119-
Properties: map[string]*jsonschema.Schema{
120-
"toolset": {
121-
Type: "string",
122-
Description: "The name of the toolset you want to get the tools for",
123-
Enum: ToolsetEnum(toolsetGroup),
124-
},
109+
func GetToolsetsTools(toolsetGroup *toolsets.ToolsetGroup, t translations.TranslationHelperFunc) toolsets.ServerTool {
110+
return toolsets.NewServerToolLegacy(mcp.Tool{
111+
Name: "get_toolset_tools",
112+
Description: t("TOOL_GET_TOOLSET_TOOLS_DESCRIPTION", "Lists all the capabilities that are enabled with the specified toolset, use this to get clarity on whether enabling a toolset would help you to complete a task"),
113+
Annotations: &mcp.ToolAnnotations{
114+
Title: t("TOOL_GET_TOOLSET_TOOLS_USER_TITLE", "List all tools in a toolset"),
115+
ReadOnlyHint: true,
116+
},
117+
InputSchema: &jsonschema.Schema{
118+
Type: "object",
119+
Properties: map[string]*jsonschema.Schema{
120+
"toolset": {
121+
Type: "string",
122+
Description: "The name of the toolset you want to get the tools for",
123+
Enum: ToolsetEnum(toolsetGroup),
125124
},
126-
Required: []string{"toolset"},
127125
},
126+
Required: []string{"toolset"},
128127
},
128+
},
129129
mcp.ToolHandlerFor[map[string]any, any](func(_ context.Context, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
130130
// We need to convert the toolsetGroup back to a map for JSON serialization
131131
toolsetName, err := RequiredParam[string](args, "toolset")
@@ -154,5 +154,5 @@ func GetToolsetsTools(toolsetGroup *toolsets.ToolsetGroup, t translations.Transl
154154
}
155155

156156
return utils.NewToolResultText(string(r)), nil, nil
157-
})
157+
}))
158158
}

0 commit comments

Comments
 (0)