Skip to content

Commit 2075a36

Browse files
committed
Notifications Mark as done with number implementation
1 parent bdb59e0 commit 2075a36

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

pkg/github/notifications.go

Lines changed: 39 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"
@@ -234,3 +235,41 @@ func getNotificationThread(client *github.Client, t translations.TranslationHelp
234235
return mcp.NewToolResultText(string(r)), nil
235236
}
236237
}
238+
239+
// markNotificationDone creates a tool to mark a notification as done.
240+
func markNotificationDone(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
241+
return mcp.NewTool("mark_notification_done",
242+
mcp.WithDescription(t("TOOL_MARK_NOTIFICATION_DONE_DESCRIPTION", "Mark a notification as done")),
243+
mcp.WithString("threadID",
244+
mcp.Required(),
245+
mcp.Description("The ID of the notification thread"),
246+
),
247+
),
248+
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
249+
threadIDStr, err := requiredParam[string](request, "threadID")
250+
if err != nil {
251+
return mcp.NewToolResultError(err.Error()), nil
252+
}
253+
254+
threadID, err := strconv.ParseInt(threadIDStr, 10, 64)
255+
if err != nil {
256+
return mcp.NewToolResultError("Invalid threadID: must be a numeric value"), nil
257+
}
258+
259+
resp, err := client.Activity.MarkThreadDone(ctx, threadID)
260+
if err != nil {
261+
return nil, fmt.Errorf("failed to mark notification as done: %w", err)
262+
}
263+
defer func() { _ = resp.Body.Close() }()
264+
265+
if resp.StatusCode != http.StatusResetContent && resp.StatusCode != http.StatusOK {
266+
body, err := io.ReadAll(resp.Body)
267+
if err != nil {
268+
return nil, fmt.Errorf("failed to read response body: %w", err)
269+
}
270+
return mcp.NewToolResultError(fmt.Sprintf("failed to mark notification as done: %s", string(body))), nil
271+
}
272+
273+
return mcp.NewToolResultText("Notification marked as done"), nil
274+
}
275+
}

pkg/github/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func NewServer(client *github.Client, readOnly bool, t translations.TranslationH
8484
if !readOnly {
8585
s.AddTool(markNotificationRead(client, t))
8686
s.AddTool(markAllNotificationsRead(client, t))
87+
s.AddTool(markNotificationDone(client, t))
8788
}
8889
return s
8990
}

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