|
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"
|
@@ -254,3 +255,46 @@ func GetNotificationThread(getClient GetClientFn, t translations.TranslationHelp
|
254 | 255 | return mcp.NewToolResultText(string(r)), nil
|
255 | 256 | }
|
256 | 257 | }
|
| 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 | +} |
0 commit comments