@@ -15,7 +15,7 @@ import (
15
15
)
16
16
17
17
// getNotifications creates a tool to list notifications for the current user.
18
- func getNotifications ( client * github. Client , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
18
+ func GetNotifications ( getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
19
19
return mcp .NewTool ("get_notifications" ,
20
20
mcp .WithDescription (t ("TOOL_GET_NOTIFICATIONS_DESCRIPTION" , "Get notifications for the authenticated GitHub user" )),
21
21
mcp .WithBoolean ("all" ,
@@ -38,33 +38,38 @@ func getNotifications(client *github.Client, t translations.TranslationHelperFun
38
38
),
39
39
),
40
40
func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
41
+ client , err := getClient (ctx )
42
+ if err != nil {
43
+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
44
+ }
45
+
41
46
// Extract optional parameters with defaults
42
- all , err := optionalParamWithDefault [ bool ] (request , "all" , false )
47
+ all , err := OptionalBoolParamWithDefault (request , "all" , false )
43
48
if err != nil {
44
49
return mcp .NewToolResultError (err .Error ()), nil
45
50
}
46
51
47
- participating , err := optionalParamWithDefault [ bool ] (request , "participating" , false )
52
+ participating , err := OptionalBoolParamWithDefault (request , "participating" , false )
48
53
if err != nil {
49
54
return mcp .NewToolResultError (err .Error ()), nil
50
55
}
51
56
52
- since , err := optionalParam [ string ] (request , "since" )
57
+ since , err := OptionalStringParamWithDefault (request , "since" , " " )
53
58
if err != nil {
54
59
return mcp .NewToolResultError (err .Error ()), nil
55
60
}
56
61
57
- before , err := optionalParam [ string ] (request , "before" )
62
+ before , err := OptionalStringParam (request , "before" )
58
63
if err != nil {
59
64
return mcp .NewToolResultError (err .Error ()), nil
60
65
}
61
66
62
- perPage , err := optionalIntParamWithDefault (request , "per_page" , 30 )
67
+ perPage , err := OptionalIntParamWithDefault (request , "per_page" , 30 )
63
68
if err != nil {
64
69
return mcp .NewToolResultError (err .Error ()), nil
65
70
}
66
71
67
- page , err := optionalIntParamWithDefault (request , "page" , 1 )
72
+ page , err := OptionalIntParamWithDefault (request , "page" , 1 )
68
73
if err != nil {
69
74
return mcp .NewToolResultError (err .Error ()), nil
70
75
}
@@ -122,7 +127,7 @@ func getNotifications(client *github.Client, t translations.TranslationHelperFun
122
127
}
123
128
124
129
// markNotificationRead creates a tool to mark a notification as read.
125
- func markNotificationRead ( client * github. Client , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
130
+ func MarkNotificationRead ( getclient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
126
131
return mcp .NewTool ("mark_notification_read" ,
127
132
mcp .WithDescription (t ("TOOL_MARK_NOTIFICATION_READ_DESCRIPTION" , "Mark a notification as read" )),
128
133
mcp .WithString ("threadID" ,
@@ -131,6 +136,11 @@ func markNotificationRead(client *github.Client, t translations.TranslationHelpe
131
136
),
132
137
),
133
138
func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
139
+ client , err := getclient (ctx )
140
+ if err != nil {
141
+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
142
+ }
143
+
134
144
threadID , err := requiredParam [string ](request , "threadID" )
135
145
if err != nil {
136
146
return mcp .NewToolResultError (err .Error ()), nil
@@ -154,16 +164,21 @@ func markNotificationRead(client *github.Client, t translations.TranslationHelpe
154
164
}
155
165
}
156
166
157
- // markAllNotificationsRead creates a tool to mark all notifications as read.
158
- func markAllNotificationsRead ( client * github. Client , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
167
+ // MarkAllNotificationsRead creates a tool to mark all notifications as read.
168
+ func MarkAllNotificationsRead ( getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
159
169
return mcp .NewTool ("mark_all_notifications_read" ,
160
170
mcp .WithDescription (t ("TOOL_MARK_ALL_NOTIFICATIONS_READ_DESCRIPTION" , "Mark all notifications as read" )),
161
171
mcp .WithString ("lastReadAt" ,
162
172
mcp .Description ("Describes the last point that notifications were checked (optional). Default: Now" ),
163
173
),
164
174
),
165
175
func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
166
- lastReadAt , err := optionalParam [string ](request , "lastReadAt" )
176
+ client , err := getClient (ctx )
177
+ if err != nil {
178
+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
179
+ }
180
+
181
+ lastReadAt , err := OptionalStringParam (request , "lastReadAt" )
167
182
if err != nil {
168
183
return mcp .NewToolResultError (err .Error ()), nil
169
184
}
@@ -197,8 +212,8 @@ func markAllNotificationsRead(client *github.Client, t translations.TranslationH
197
212
}
198
213
}
199
214
200
- // getNotificationThread creates a tool to get a specific notification thread.
201
- func getNotificationThread ( client * github. Client , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
215
+ // GetNotificationThread creates a tool to get a specific notification thread.
216
+ func GetNotificationThread ( getClient GetClientFn , t translations.TranslationHelperFunc ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
202
217
return mcp .NewTool ("get_notification_thread" ,
203
218
mcp .WithDescription (t ("TOOL_GET_NOTIFICATION_THREAD_DESCRIPTION" , "Get a specific notification thread" )),
204
219
mcp .WithString ("threadID" ,
@@ -207,6 +222,11 @@ func getNotificationThread(client *github.Client, t translations.TranslationHelp
207
222
),
208
223
),
209
224
func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
225
+ client , err := getClient (ctx )
226
+ if err != nil {
227
+ return nil , fmt .Errorf ("failed to get GitHub client: %w" , err )
228
+ }
229
+
210
230
threadID , err := requiredParam [string ](request , "threadID" )
211
231
if err != nil {
212
232
return mcp .NewToolResultError (err .Error ()), nil
0 commit comments