Skip to content

Commit 6eaa8d3

Browse files
authored
Notifications Mark as done with number implementation (#270)
1 parent f75c234 commit 6eaa8d3

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

pkg/github/notifications.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88
"net/http"
9+
"strconv"
910
"time"
1011

1112
"github.com/github/github-mcp-server/pkg/translations"
@@ -254,3 +255,46 @@ func GetNotificationThread(getClient GetClientFn, t translations.TranslationHelp
254255
return mcp.NewToolResultText(string(r)), nil
255256
}
256257
}
258+
259+
// markNotificationDone creates a tool to mark a notification as done.
260+
func MarkNotificationDone(getclient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
261+
return mcp.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+
if err != nil {
271+
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
272+
}
273+
274+
threadIDStr, err := requiredParam[string](request, "threadID")
275+
if err != nil {
276+
return mcp.NewToolResultError(err.Error()), nil
277+
}
278+
279+
threadID, err := strconv.ParseInt(threadIDStr, 10, 64)
280+
if err != nil {
281+
return mcp.NewToolResultError("Invalid threadID: must be a numeric value"), nil
282+
}
283+
284+
resp, err := client.Activity.MarkThreadDone(ctx, threadID)
285+
if err != nil {
286+
return nil, fmt.Errorf("failed to mark notification as done: %w", err)
287+
}
288+
defer func() { _ = resp.Body.Close() }()
289+
290+
if resp.StatusCode != http.StatusResetContent && resp.StatusCode != http.StatusOK {
291+
body, err := io.ReadAll(resp.Body)
292+
if err != nil {
293+
return nil, fmt.Errorf("failed to read response body: %w", err)
294+
}
295+
return mcp.NewToolResultError(fmt.Sprintf("failed to mark notification as done: %s", string(body))), nil
296+
}
297+
298+
return mcp.NewToolResultText("Notification marked as done"), nil
299+
}
300+
}

pkg/github/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func NewServer(getClient GetClientFn, version string, readOnly bool, t translati
9797
if !readOnly {
9898
s.AddTool(MarkNotificationRead(getClient, t))
9999
s.AddTool(MarkAllNotificationsRead(getClient, t))
100+
s.AddTool(MarkNotificationDone(getClient, t))
100101
}
101102

102103
return s

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy