|
6 | 6 | "fmt"
|
7 | 7 | "io"
|
8 | 8 | "net/http"
|
| 9 | + "strconv" |
9 | 10 | "time"
|
10 | 11 |
|
11 | 12 | "github.com/github/github-mcp-server/pkg/translations"
|
@@ -234,3 +235,41 @@ func getNotificationThread(client *github.Client, t translations.TranslationHelp
|
234 | 235 | return mcp.NewToolResultText(string(r)), nil
|
235 | 236 | }
|
236 | 237 | }
|
| 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 | +} |
0 commit comments