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

Commitee6618e

Browse files
authored
Combine tools
1 parentbc897a1 commitee6618e

File tree

1 file changed

+79
-136
lines changed

1 file changed

+79
-136
lines changed

‎pkg/github/notifications.go

Lines changed: 79 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -127,50 +127,19 @@ func GetNotifications(getClient GetClientFn, t translations.TranslationHelperFun
127127
}
128128
}
129129

130-
//markNotificationRead creates a tool to marka notificationas read.
131-
funcMarkNotificationRead(getclientGetClientFn,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
132-
returnmcp.NewTool("mark_notification_read",
133-
mcp.WithDescription(t("TOOL_MARK_NOTIFICATION_READ_DESCRIPTION","Mark a notification as read")),
134-
mcp.WithString("threadID",
130+
//ManageNotifications creates a tool tomanage notifications (markas read, mark allas read, or mark as done).
131+
funcManageNotifications(getClientGetClientFn,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
132+
returnmcp.NewTool("manage_notifications",
133+
mcp.WithDescription(t("TOOL_MANAGE_NOTIFICATIONS_DESCRIPTION","Manage notifications (mark as read, mark all as read, or mark as done)")),
134+
mcp.WithString("action",
135135
mcp.Required(),
136-
mcp.Description("The ID of the notification thread"),
136+
mcp.Description("The action to perform: 'mark_read', 'mark_all_read', or 'mark_done'"),
137+
),
138+
mcp.WithString("threadID",
139+
mcp.Description("The ID of the notification thread (required for 'mark_read' and 'mark_done')"),
137140
),
138-
),
139-
func(ctx context.Context,request mcp.CallToolRequest) (*mcp.CallToolResult,error) {
140-
client,err:=getclient(ctx)
141-
iferr!=nil {
142-
returnnil,fmt.Errorf("failed to get GitHub client: %w",err)
143-
}
144-
145-
threadID,err:=requiredParam[string](request,"threadID")
146-
iferr!=nil {
147-
returnmcp.NewToolResultError(err.Error()),nil
148-
}
149-
150-
resp,err:=client.Activity.MarkThreadRead(ctx,threadID)
151-
iferr!=nil {
152-
returnnil,fmt.Errorf("failed to mark notification as read: %w",err)
153-
}
154-
deferfunc() {_=resp.Body.Close() }()
155-
156-
ifresp.StatusCode!=http.StatusResetContent&&resp.StatusCode!=http.StatusOK {
157-
body,err:=io.ReadAll(resp.Body)
158-
iferr!=nil {
159-
returnnil,fmt.Errorf("failed to read response body: %w",err)
160-
}
161-
returnmcp.NewToolResultError(fmt.Sprintf("failed to mark notification as read: %s",string(body))),nil
162-
}
163-
164-
returnmcp.NewToolResultText("Notification marked as read"),nil
165-
}
166-
}
167-
168-
// MarkAllNotificationsRead creates a tool to mark all notifications as read.
169-
funcMarkAllNotificationsRead(getClientGetClientFn,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
170-
returnmcp.NewTool("mark_all_notifications_read",
171-
mcp.WithDescription(t("TOOL_MARK_ALL_NOTIFICATIONS_READ_DESCRIPTION","Mark all notifications as read")),
172141
mcp.WithString("lastReadAt",
173-
mcp.Description("Describes the last point that notifications were checked (optional). Default: Now"),
142+
mcp.Description("Describes the last point that notifications were checked (optional, for 'mark_all_read'). Default: Now"),
174143
),
175144
),
176145
func(ctx context.Context,request mcp.CallToolRequest) (*mcp.CallToolResult,error) {
@@ -179,122 +148,96 @@ func MarkAllNotificationsRead(getClient GetClientFn, t translations.TranslationH
179148
returnnil,fmt.Errorf("failed to get GitHub client: %w",err)
180149
}
181150

182-
lastReadAt,err:=OptionalStringParam(request,"lastReadAt")
151+
action,err:=requiredParam[string](request,"action")
183152
iferr!=nil {
184153
returnmcp.NewToolResultError(err.Error()),nil
185154
}
186155

187-
varmarkReadOptions github.Timestamp
188-
iflastReadAt!="" {
189-
lastReadTime,err:=time.Parse(time.RFC3339,lastReadAt)
156+
switchaction {
157+
case"mark_read":
158+
threadID,err:=requiredParam[string](request,"threadID")
190159
iferr!=nil {
191-
returnmcp.NewToolResultError(fmt.Sprintf("invalid lastReadAt time format, should be RFC3339/ISO8601: %v",err)),nil
192-
}
193-
markReadOptions= github.Timestamp{
194-
Time:lastReadTime,
160+
returnmcp.NewToolResultError(err.Error()),nil
195161
}
196-
}
197-
198-
resp,err:=client.Activity.MarkNotificationsRead(ctx,markReadOptions)
199-
iferr!=nil {
200-
returnnil,fmt.Errorf("failed to mark all notifications as read: %w",err)
201-
}
202-
deferfunc() {_=resp.Body.Close() }()
203162

204-
ifresp.StatusCode!=http.StatusResetContent&&resp.StatusCode!=http.StatusOK {
205-
body,err:=io.ReadAll(resp.Body)
163+
resp,err:=client.Activity.MarkThreadRead(ctx,threadID)
206164
iferr!=nil {
207-
returnnil,fmt.Errorf("failed to read response body: %w",err)
165+
returnnil,fmt.Errorf("failed to mark notification as read: %w",err)
166+
}
167+
deferfunc() {_=resp.Body.Close() }()
168+
169+
ifresp.StatusCode!=http.StatusResetContent&&resp.StatusCode!=http.StatusOK {
170+
body,err:=io.ReadAll(resp.Body)
171+
iferr!=nil {
172+
returnnil,fmt.Errorf("failed to read response body: %w",err)
173+
}
174+
returnmcp.NewToolResultError(fmt.Sprintf("failed to mark notification as read: %s",string(body))),nil
208175
}
209-
returnmcp.NewToolResultError(fmt.Sprintf("failed to mark all notifications as read: %s",string(body))),nil
210-
}
211-
212-
returnmcp.NewToolResultText("All notifications marked as read"),nil
213-
}
214-
}
215-
216-
// GetNotificationThread creates a tool to get a specific notification thread.
217-
funcGetNotificationThread(getClientGetClientFn,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
218-
returnmcp.NewTool("get_notification_thread",
219-
mcp.WithDescription(t("TOOL_GET_NOTIFICATION_THREAD_DESCRIPTION","Get a specific notification thread")),
220-
mcp.WithString("threadID",
221-
mcp.Required(),
222-
mcp.Description("The ID of the notification thread"),
223-
),
224-
),
225-
func(ctx context.Context,request mcp.CallToolRequest) (*mcp.CallToolResult,error) {
226-
client,err:=getClient(ctx)
227-
iferr!=nil {
228-
returnnil,fmt.Errorf("failed to get GitHub client: %w",err)
229-
}
230-
231-
threadID,err:=requiredParam[string](request,"threadID")
232-
iferr!=nil {
233-
returnmcp.NewToolResultError(err.Error()),nil
234-
}
235176

236-
thread,resp,err:=client.Activity.GetThread(ctx,threadID)
237-
iferr!=nil {
238-
returnnil,fmt.Errorf("failed to get notification thread: %w",err)
239-
}
240-
deferfunc() {_=resp.Body.Close() }()
177+
returnmcp.NewToolResultText("Notification marked as read"),nil
241178

242-
ifresp.StatusCode!=http.StatusOK {
243-
body,err:=io.ReadAll(resp.Body)
179+
case"mark_done":
180+
threadIDStr,err:=requiredParam[string](request,"threadID")
244181
iferr!=nil {
245-
returnnil,fmt.Errorf("failed to read response body: %w",err)
182+
returnmcp.NewToolResultError(err.Error()),nil
246183
}
247-
returnmcp.NewToolResultError(fmt.Sprintf("failed to get notification thread: %s",string(body))),nil
248-
}
249-
250-
r,err:=json.Marshal(thread)
251-
iferr!=nil {
252-
returnnil,fmt.Errorf("failed to marshal response: %w",err)
253-
}
254184

255-
returnmcp.NewToolResultText(string(r)),nil
256-
}
257-
}
185+
threadID,err:=strconv.ParseInt(threadIDStr,10,64)
186+
iferr!=nil {
187+
returnmcp.NewToolResultError("Invalid threadID: must be a numeric value"),nil
188+
}
258189

259-
// markNotificationDone creates a tool to mark a notification as done.
260-
funcMarkNotificationDone(getclientGetClientFn,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) {
261-
returnmcp.NewTool("mark_notification_done",
262-
mcp.WithDescription(t("TOOL_MARK_NOTIFICATION_DONE_DESCRIPTION","Mark a notification as done")),
263-
mcp.WithString("threadID",
264-
mcp.Required(),
265-
mcp.Description("The ID of the notification thread"),
266-
),
267-
),
268-
func(ctx context.Context,request mcp.CallToolRequest) (*mcp.CallToolResult,error) {
269-
client,err:=getclient(ctx)
270-
iferr!=nil {
271-
returnnil,fmt.Errorf("failed to get GitHub client: %w",err)
272-
}
190+
resp,err:=client.Activity.MarkThreadDone(ctx,threadID)
191+
iferr!=nil {
192+
returnnil,fmt.Errorf("failed to mark notification as done: %w",err)
193+
}
194+
deferfunc() {_=resp.Body.Close() }()
195+
196+
ifresp.StatusCode!=http.StatusResetContent&&resp.StatusCode!=http.StatusOK {
197+
body,err:=io.ReadAll(resp.Body)
198+
iferr!=nil {
199+
returnnil,fmt.Errorf("failed to read response body: %w",err)
200+
}
201+
returnmcp.NewToolResultError(fmt.Sprintf("failed to mark notification as done: %s",string(body))),nil
202+
}
273203

274-
threadIDStr,err:=requiredParam[string](request,"threadID")
275-
iferr!=nil {
276-
returnmcp.NewToolResultError(err.Error()),nil
277-
}
204+
returnmcp.NewToolResultText("Notification marked as done"),nil
278205

279-
threadID,err:=strconv.ParseInt(threadIDStr,10,64)
280-
iferr!=nil {
281-
returnmcp.NewToolResultError("Invalid threadID: must be a numeric value"),nil
282-
}
206+
case"mark_all_read":
207+
lastReadAt,err:=OptionalStringParam(request,"lastReadAt")
208+
iferr!=nil {
209+
returnmcp.NewToolResultError(err.Error()),nil
210+
}
283211

284-
resp,err:=client.Activity.MarkThreadDone(ctx,threadID)
285-
iferr!=nil {
286-
returnnil,fmt.Errorf("failed to mark notification as done: %w",err)
287-
}
288-
deferfunc() {_=resp.Body.Close() }()
212+
varmarkReadOptions github.Timestamp
213+
iflastReadAt!="" {
214+
lastReadTime,err:=time.Parse(time.RFC3339,lastReadAt)
215+
iferr!=nil {
216+
returnmcp.NewToolResultError(fmt.Sprintf("invalid lastReadAt time format, should be RFC3339/ISO8601: %v",err)),nil
217+
}
218+
markReadOptions= github.Timestamp{
219+
Time:lastReadTime,
220+
}
221+
}
289222

290-
ifresp.StatusCode!=http.StatusResetContent&&resp.StatusCode!=http.StatusOK {
291-
body,err:=io.ReadAll(resp.Body)
223+
resp,err:=client.Activity.MarkNotificationsRead(ctx,markReadOptions)
292224
iferr!=nil {
293-
returnnil,fmt.Errorf("failed toread response body: %w",err)
225+
returnnil,fmt.Errorf("failed tomark all notifications as read: %w",err)
294226
}
295-
returnmcp.NewToolResultError(fmt.Sprintf("failed to mark notification as done: %s",string(body))),nil
296-
}
227+
deferfunc() {_=resp.Body.Close() }()
228+
229+
ifresp.StatusCode!=http.StatusResetContent&&resp.StatusCode!=http.StatusOK {
230+
body,err:=io.ReadAll(resp.Body)
231+
iferr!=nil {
232+
returnnil,fmt.Errorf("failed to read response body: %w",err)
233+
}
234+
returnmcp.NewToolResultError(fmt.Sprintf("failed to mark all notifications as read: %s",string(body))),nil
235+
}
236+
237+
returnmcp.NewToolResultText("All notifications marked as read"),nil
297238

298-
returnmcp.NewToolResultText("Notification marked as done"),nil
239+
default:
240+
returnmcp.NewToolResultError("Invalid action: must be 'mark_read', 'mark_all_read', or 'mark_done'"),nil
241+
}
299242
}
300243
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp