Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdbdef79

Browse files
refactor: update notification functions to use GetClientFn . Fix conflicts
1 parentb5b3211 commitdbdef79

File tree

2 files changed

+79
-30
lines changed

2 files changed

+79
-30
lines changed

‎pkg/github/notifications.go

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
// getNotifications creates a tool to list notifications for the current user.
18-
funcgetNotifications(client*github.Client,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
18+
funcGetNotifications(getClientGetClientFn,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
1919
returnmcp.NewTool("get_notifications",
2020
mcp.WithDescription(t("TOOL_GET_NOTIFICATIONS_DESCRIPTION","Get notifications for the authenticated GitHub user")),
2121
mcp.WithBoolean("all",
@@ -38,33 +38,38 @@ func getNotifications(client *github.Client, t translations.TranslationHelperFun
3838
),
3939
),
4040
func(ctx context.Context,request mcp.CallToolRequest) (*mcp.CallToolResult,error) {
41+
client,err:=getClient(ctx)
42+
iferr!=nil {
43+
returnnil,fmt.Errorf("failed to get GitHub client: %w",err)
44+
}
45+
4146
// Extract optional parameters with defaults
42-
all,err:=optionalParamWithDefault[bool](request,"all",false)
47+
all,err:=OptionalBoolParamWithDefault(request,"all",false)
4348
iferr!=nil {
4449
returnmcp.NewToolResultError(err.Error()),nil
4550
}
4651

47-
participating,err:=optionalParamWithDefault[bool](request,"participating",false)
52+
participating,err:=OptionalBoolParamWithDefault(request,"participating",false)
4853
iferr!=nil {
4954
returnmcp.NewToolResultError(err.Error()),nil
5055
}
5156

52-
since,err:=optionalParam[string](request,"since")
57+
since,err:=OptionalStringParamWithDefault(request,"since","")
5358
iferr!=nil {
5459
returnmcp.NewToolResultError(err.Error()),nil
5560
}
5661

57-
before,err:=optionalParam[string](request,"before")
62+
before,err:=OptionalStringParam(request,"before")
5863
iferr!=nil {
5964
returnmcp.NewToolResultError(err.Error()),nil
6065
}
6166

62-
perPage,err:=optionalIntParamWithDefault(request,"per_page",30)
67+
perPage,err:=OptionalIntParamWithDefault(request,"per_page",30)
6368
iferr!=nil {
6469
returnmcp.NewToolResultError(err.Error()),nil
6570
}
6671

67-
page,err:=optionalIntParamWithDefault(request,"page",1)
72+
page,err:=OptionalIntParamWithDefault(request,"page",1)
6873
iferr!=nil {
6974
returnmcp.NewToolResultError(err.Error()),nil
7075
}
@@ -122,7 +127,7 @@ func getNotifications(client *github.Client, t translations.TranslationHelperFun
122127
}
123128

124129
// markNotificationRead creates a tool to mark a notification as read.
125-
funcmarkNotificationRead(client*github.Client,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
130+
funcMarkNotificationRead(getclientGetClientFn,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
126131
returnmcp.NewTool("mark_notification_read",
127132
mcp.WithDescription(t("TOOL_MARK_NOTIFICATION_READ_DESCRIPTION","Mark a notification as read")),
128133
mcp.WithString("threadID",
@@ -131,6 +136,11 @@ func markNotificationRead(client *github.Client, t translations.TranslationHelpe
131136
),
132137
),
133138
func(ctx context.Context,request mcp.CallToolRequest) (*mcp.CallToolResult,error) {
139+
client,err:=getclient(ctx)
140+
iferr!=nil {
141+
returnnil,fmt.Errorf("failed to get GitHub client: %w",err)
142+
}
143+
134144
threadID,err:=requiredParam[string](request,"threadID")
135145
iferr!=nil {
136146
returnmcp.NewToolResultError(err.Error()),nil
@@ -154,16 +164,21 @@ func markNotificationRead(client *github.Client, t translations.TranslationHelpe
154164
}
155165
}
156166

157-
//markAllNotificationsRead creates a tool to mark all notifications as read.
158-
funcmarkAllNotificationsRead(client*github.Client,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
167+
//MarkAllNotificationsRead creates a tool to mark all notifications as read.
168+
funcMarkAllNotificationsRead(getClientGetClientFn,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
159169
returnmcp.NewTool("mark_all_notifications_read",
160170
mcp.WithDescription(t("TOOL_MARK_ALL_NOTIFICATIONS_READ_DESCRIPTION","Mark all notifications as read")),
161171
mcp.WithString("lastReadAt",
162172
mcp.Description("Describes the last point that notifications were checked (optional). Default: Now"),
163173
),
164174
),
165175
func(ctx context.Context,request mcp.CallToolRequest) (*mcp.CallToolResult,error) {
166-
lastReadAt,err:=optionalParam[string](request,"lastReadAt")
176+
client,err:=getClient(ctx)
177+
iferr!=nil {
178+
returnnil,fmt.Errorf("failed to get GitHub client: %w",err)
179+
}
180+
181+
lastReadAt,err:=OptionalStringParam(request,"lastReadAt")
167182
iferr!=nil {
168183
returnmcp.NewToolResultError(err.Error()),nil
169184
}
@@ -197,8 +212,8 @@ func markAllNotificationsRead(client *github.Client, t translations.TranslationH
197212
}
198213
}
199214

200-
//getNotificationThread creates a tool to get a specific notification thread.
201-
funcgetNotificationThread(client*github.Client,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
215+
//GetNotificationThread creates a tool to get a specific notification thread.
216+
funcGetNotificationThread(getClientGetClientFn,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
202217
returnmcp.NewTool("get_notification_thread",
203218
mcp.WithDescription(t("TOOL_GET_NOTIFICATION_THREAD_DESCRIPTION","Get a specific notification thread")),
204219
mcp.WithString("threadID",
@@ -207,6 +222,11 @@ func getNotificationThread(client *github.Client, t translations.TranslationHelp
207222
),
208223
),
209224
func(ctx context.Context,request mcp.CallToolRequest) (*mcp.CallToolResult,error) {
225+
client,err:=getClient(ctx)
226+
iferr!=nil {
227+
returnnil,fmt.Errorf("failed to get GitHub client: %w",err)
228+
}
229+
210230
threadID,err:=requiredParam[string](request,"threadID")
211231
iferr!=nil {
212232
returnmcp.NewToolResultError(err.Error()),nil

‎pkg/github/server.go

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ func NewServer(getClient GetClientFn, version string, readOnly bool, t translati
9191
s.AddTool(GetCodeScanningAlert(getClient,t))
9292
s.AddTool(ListCodeScanningAlerts(getClient,t))
9393

94-
// Add GitHub tools - Notifications
94+
// Add GitHub tools - Notifications
95+
s.AddTool(GetNotifications(getClient,t))
96+
s.AddTool(GetNotificationThread(getClient,t))
9597
if!readOnly {
96-
s.AddTool(markNotificationRead(client,t))
97-
s.AddTool(markAllNotificationsRead(client,t))
98+
s.AddTool(MarkNotificationRead(getClient,t))
99+
s.AddTool(MarkAllNotificationsRead(getClient,t))
98100
}
99-
101+
100102
returns
101103
}
102104

@@ -237,28 +239,55 @@ func OptionalIntParam(r mcp.CallToolRequest, p string) (int, error) {
237239
returnint(v),nil
238240
}
239241

240-
// optionalParamWithDefault is a generic helper function that can be used to fetch a requested parameter from the request
241-
// with a default value if the parameter is not provided or is zero value.
242-
funcoptionalParamWithDefault[Tcomparable](r mcp.CallToolRequest,pstring,dT) (T,error) {
243-
varzeroT
244-
v,err:=optionalParam[T](r,p)
242+
// OptionalIntParamWithDefault is a helper function that can be used to fetch a requested parameter from the request
243+
// similar to optionalIntParam, but it also takes a default value.
244+
funcOptionalIntParamWithDefault(r mcp.CallToolRequest,pstring,dint) (int,error) {
245+
v,err:=OptionalIntParam(r,p)
245246
iferr!=nil {
246-
returnzero,err
247+
return0,err
247248
}
248-
ifv==zero {
249+
ifv==0 {
249250
returnd,nil
250251
}
251252
returnv,nil
252253
}
253254

254-
//OptionalIntParamWithDefault is a helper function that can be used to fetch a requested parameter from the request
255-
// similar tooptionalIntParam, but it also takes a default value.
256-
funcOptionalIntParamWithDefault(r mcp.CallToolRequest,pstring,dint) (int,error) {
257-
v,err:=OptionalIntParam(r,p)
255+
//OptionalBoolParamWithDefault is a helper function that can be used to fetch a requested parameter from the request
256+
// similar tooptionalParam, but it also takes a default value.
257+
funcOptionalBoolParamWithDefault(r mcp.CallToolRequest,pstring,dbool) (bool,error) {
258+
v,err:=OptionalParam[bool](r,p)
258259
iferr!=nil {
259-
return0,err
260+
returnfalse,err
260261
}
261-
ifv==0 {
262+
ifv==false {
263+
returnd,nil
264+
}
265+
returnv,nil
266+
}
267+
268+
// OptionalStringParam is a helper function that can be used to fetch a requested parameter from the request.
269+
// It does the following checks:
270+
// 1. Checks if the parameter is present in the request, if not, it returns its zero-value
271+
// 2. If it is present, it checks if the parameter is of the expected type and returns it
272+
funcOptionalStringParam(r mcp.CallToolRequest,pstring) (string,error) {
273+
v,err:=OptionalParam[string](r,p)
274+
iferr!=nil {
275+
return"",err
276+
}
277+
ifv=="" {
278+
return"",nil
279+
}
280+
returnv,nil
281+
}
282+
283+
// OptionalStringParamWithDefault is a helper function that can be used to fetch a requested parameter from the request
284+
// similar to optionalParam, but it also takes a default value.
285+
funcOptionalStringParamWithDefault(r mcp.CallToolRequest,pstring,dstring) (string,error) {
286+
v,err:=OptionalParam[string](r,p)
287+
iferr!=nil {
288+
return"",err
289+
}
290+
ifv=="" {
262291
returnd,nil
263292
}
264293
returnv,nil

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp