|
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 | returnmcp.NewToolResultText(string(r)),nil
|
255 | 256 | }
|
256 | 257 | }
|
| 258 | + |
| 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 | +} |
| 273 | + |
| 274 | +threadIDStr,err:=requiredParam[string](request,"threadID") |
| 275 | +iferr!=nil { |
| 276 | +returnmcp.NewToolResultError(err.Error()),nil |
| 277 | +} |
| 278 | + |
| 279 | +threadID,err:=strconv.ParseInt(threadIDStr,10,64) |
| 280 | +iferr!=nil { |
| 281 | +returnmcp.NewToolResultError("Invalid threadID: must be a numeric value"),nil |
| 282 | +} |
| 283 | + |
| 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() }() |
| 289 | + |
| 290 | +ifresp.StatusCode!=http.StatusResetContent&&resp.StatusCode!=http.StatusOK { |
| 291 | +body,err:=io.ReadAll(resp.Body) |
| 292 | +iferr!=nil { |
| 293 | +returnnil,fmt.Errorf("failed to read response body: %w",err) |
| 294 | +} |
| 295 | +returnmcp.NewToolResultError(fmt.Sprintf("failed to mark notification as done: %s",string(body))),nil |
| 296 | +} |
| 297 | + |
| 298 | +returnmcp.NewToolResultText("Notification marked as done"),nil |
| 299 | +} |
| 300 | +} |