@@ -18,7 +18,7 @@ import (
18
18
type GetClientFn func (context.Context ) (* github.Client ,error )
19
19
20
20
// NewServer creates a new GitHub MCP server with the specified GH client and logger.
21
- func NewServer (getClient GetClientFn ,toolsetGroup * toolsets.ToolsetGroup ,version string ,readOnly bool , t translations.TranslationHelperFunc )* server.MCPServer {
21
+ func NewServer (getClient GetClientFn ,toolsetGroup * toolsets.ToolsetGroup ,version string ,t translations.TranslationHelperFunc )* server.MCPServer {
22
22
// Create a new MCP server
23
23
s := server .NewMCPServer (
24
24
"github-mcp-server" ,
@@ -29,73 +29,73 @@ func NewServer(getClient GetClientFn, toolsetGroup *toolsets.ToolsetGroup, versi
29
29
// Add GitHub tools - Users
30
30
s .AddTool (GetMe (getClient ,t ))// GetMe is always exposed and not part of configurable features
31
31
32
- if toolsetGroup .IsEnabled ("repos" ) {
33
- // Add GitHub Repository Resources
34
- s .AddResourceTemplate (GetRepositoryResourceContent (getClient ,t ))
35
- s .AddResourceTemplate (GetRepositoryResourceBranchContent (getClient ,t ))
36
- s .AddResourceTemplate (GetRepositoryResourceCommitContent (getClient ,t ))
37
- s .AddResourceTemplate (GetRepositoryResourceTagContent (getClient ,t ))
38
- s .AddResourceTemplate (GetRepositoryResourcePrContent (getClient ,t ))
39
-
40
- // Add GitHub tools - Repositories
41
- s .AddTool (SearchRepositories (getClient ,t ))
42
- s .AddTool (GetFileContents (getClient ,t ))
43
- s .AddTool (ListCommits (getClient ,t ))
44
- if ! readOnly {
45
- s .AddTool (CreateOrUpdateFile (getClient ,t ))
46
- s .AddTool (CreateRepository (getClient ,t ))
47
- s .AddTool (ForkRepository (getClient ,t ))
48
- s .AddTool (CreateBranch (getClient ,t ))
49
- s .AddTool (PushFiles (getClient ,t ))
32
+ for _ ,toolset := range toolsetGroup .Toolsets {
33
+ switch toolset .Name {
34
+ case "repos" :
35
+ toolset .AddTemplateResources (
36
+ toolsets .NewResourceTemplate (GetRepositoryResourceContent (getClient ,t )),
37
+ toolsets .NewResourceTemplate (GetRepositoryResourceBranchContent (getClient ,t )),
38
+ toolsets .NewResourceTemplate (GetRepositoryResourceCommitContent (getClient ,t )),
39
+ toolsets .NewResourceTemplate (GetRepositoryResourceTagContent (getClient ,t )),
40
+ toolsets .NewResourceTemplate (GetRepositoryResourcePrContent (getClient ,t )),
41
+ ).AddReadTools (
42
+ toolsets .NewServerTool (SearchRepositories (getClient ,t )),
43
+ toolsets .NewServerTool (GetFileContents (getClient ,t )),
44
+ toolsets .NewServerTool (ListCommits (getClient ,t )),
45
+ ).AddWriteTools (
46
+ toolsets .NewServerTool (CreateOrUpdateFile (getClient ,t )),
47
+ toolsets .NewServerTool (CreateRepository (getClient ,t )),
48
+ toolsets .NewServerTool (ForkRepository (getClient ,t )),
49
+ toolsets .NewServerTool (CreateBranch (getClient ,t )),
50
+ toolsets .NewServerTool (PushFiles (getClient ,t )),
51
+ )
52
+ case "issues" :
53
+ toolset .AddReadTools (
54
+ toolsets .NewServerTool (GetIssue (getClient ,t )),
55
+ toolsets .NewServerTool (SearchIssues (getClient ,t )),
56
+ toolsets .NewServerTool (ListIssues (getClient ,t )),
57
+ toolsets .NewServerTool (GetIssueComments (getClient ,t )),
58
+ ).AddWriteTools (
59
+ toolsets .NewServerTool (CreateIssue (getClient ,t )),
60
+ toolsets .NewServerTool (AddIssueComment (getClient ,t )),
61
+ toolsets .NewServerTool (UpdateIssue (getClient ,t )),
62
+ )
63
+ case "pull_requests" :
64
+ toolset .AddReadTools (
65
+ toolsets .NewServerTool (GetPullRequest (getClient ,t )),
66
+ toolsets .NewServerTool (ListPullRequests (getClient ,t )),
67
+ toolsets .NewServerTool (GetPullRequestFiles (getClient ,t )),
68
+ toolsets .NewServerTool (GetPullRequestStatus (getClient ,t )),
69
+ toolsets .NewServerTool (GetPullRequestComments (getClient ,t )),
70
+ toolsets .NewServerTool (GetPullRequestReviews (getClient ,t )),
71
+ ).AddWriteTools (
72
+ toolsets .NewServerTool (MergePullRequest (getClient ,t )),
73
+ toolsets .NewServerTool (UpdatePullRequestBranch (getClient ,t )),
74
+ toolsets .NewServerTool (CreatePullRequestReview (getClient ,t )),
75
+ toolsets .NewServerTool (CreatePullRequest (getClient ,t )),
76
+ )
77
+ case "search" :
78
+ toolset .AddReadTools (
79
+ toolsets .NewServerTool (SearchCode (getClient ,t )),
80
+ toolsets .NewServerTool (SearchUsers (getClient ,t )),
81
+ )
82
+ case "code_security" :
83
+ toolset .AddReadTools (
84
+ toolsets .NewServerTool (GetCodeScanningAlert (getClient ,t )),
85
+ toolsets .NewServerTool (ListCodeScanningAlerts (getClient ,t )),
86
+ )
87
+ case "experiments" :
88
+ toolset .AddReadTools (
89
+ toolsets .NewServerTool (ListAvailableToolsets (toolsetGroup ,t )),
90
+ toolsets .NewServerTool (EnableToolset (s ,toolsetGroup ,t )),
91
+ )
92
+ default :
93
+ panic (fmt .Sprintf ("Unknown toolset: %s" ,toolset .Name ))
50
94
}
51
95
}
52
96
53
- if toolsetGroup .IsEnabled ("issues" ) {
54
- // Add GitHub tools - Issues
55
- s .AddTool (GetIssue (getClient ,t ))
56
- s .AddTool (SearchIssues (getClient ,t ))
57
- s .AddTool (ListIssues (getClient ,t ))
58
- s .AddTool (GetIssueComments (getClient ,t ))
59
- if ! readOnly {
60
- s .AddTool (CreateIssue (getClient ,t ))
61
- s .AddTool (AddIssueComment (getClient ,t ))
62
- s .AddTool (UpdateIssue (getClient ,t ))
63
- }
64
- }
65
-
66
- if toolsetGroup .IsEnabled ("pull_requests" ) {
67
- // Add GitHub tools - Pull Requests
68
- s .AddTool (GetPullRequest (getClient ,t ))
69
- s .AddTool (ListPullRequests (getClient ,t ))
70
- s .AddTool (GetPullRequestFiles (getClient ,t ))
71
- s .AddTool (GetPullRequestStatus (getClient ,t ))
72
- s .AddTool (GetPullRequestComments (getClient ,t ))
73
- s .AddTool (GetPullRequestReviews (getClient ,t ))
74
- if ! readOnly {
75
- s .AddTool (MergePullRequest (getClient ,t ))
76
- s .AddTool (UpdatePullRequestBranch (getClient ,t ))
77
- s .AddTool (CreatePullRequestReview (getClient ,t ))
78
- s .AddTool (CreatePullRequest (getClient ,t ))
79
- }
80
- }
81
-
82
- if toolsetGroup .IsEnabled ("search" ) {
83
- // Add GitHub tools - Search
84
- s .AddTool (SearchCode (getClient ,t ))
85
- s .AddTool (SearchUsers (getClient ,t ))
86
- }
87
-
88
- if toolsetGroup .IsEnabled ("code_security" ) {
89
- // Add GitHub tools - Code Scanning
90
- s .AddTool (GetCodeScanningAlert (getClient ,t ))
91
- s .AddTool (ListCodeScanningAlerts (getClient ,t ))
92
- }
93
-
94
- if toolsetGroup .IsEnabled ("experiments" ) {
95
- s .AddTool (ListAvailableToolsets (toolsetGroup ,t ))
96
- s .AddTool (EnableToolset (s ,toolsetGroup ,t ))
97
- }
98
-
97
+ // Register the tools with the server
98
+ toolsetGroup .RegisterTools (s )
99
99
return s
100
100
}
101
101
@@ -150,9 +150,22 @@ func EnableToolset(s *server.MCPServer, toolsets *toolsets.ToolsetGroup, t trans
150
150
if err != nil {
151
151
return mcp .NewToolResultError (err .Error ()),nil
152
152
}
153
- toolsets .EnableFeature (toolsetName )
154
- // TODO s.AddTool()
155
- // TODO SEND TOOL UPDATE TO CLIENT
153
+ toolset := toolsets .Toolsets [toolsetName ]
154
+ if toolset == nil {
155
+ return mcp .NewToolResultError (fmt .Sprintf ("Toolset %s not found" ,toolsetName )),nil
156
+ }
157
+ if toolset .Enabled {
158
+ return mcp .NewToolResultText (fmt .Sprintf ("Toolset %s is already enabled" ,toolsetName )),nil
159
+ }
160
+
161
+ toolset .Enabled = true
162
+
163
+ // caution: this currently affects the global tools and notifies all clients:
164
+ //
165
+ // Send notification to all initialized sessions
166
+ // s.sendNotificationToAllClients("notifications/tools/list_changed", nil)
167
+ s .AddTools (toolset .GetActiveTools ()... )
168
+
156
169
return mcp .NewToolResultText (fmt .Sprintf ("Toolset %s enabled" ,toolsetName )),nil
157
170
}
158
171
}