|
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 | returnmcp.NewToolResultText(string(r)),nil
|
235 | 236 | }
|
236 | 237 | }
|
| 238 | + |
| 239 | +// markNotificationDone creates a tool to mark a notification as done. |
| 240 | +funcmarkNotificationDone(client*github.Client,t translations.TranslationHelperFunc) (tool mcp.Tool,handler server.ToolHandlerFunc) { |
| 241 | +returnmcp.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 | +iferr!=nil { |
| 251 | +returnmcp.NewToolResultError(err.Error()),nil |
| 252 | +} |
| 253 | + |
| 254 | +threadID,err:=strconv.ParseInt(threadIDStr,10,64) |
| 255 | +iferr!=nil { |
| 256 | +returnmcp.NewToolResultError("Invalid threadID: must be a numeric value"),nil |
| 257 | +} |
| 258 | + |
| 259 | +resp,err:=client.Activity.MarkThreadDone(ctx,threadID) |
| 260 | +iferr!=nil { |
| 261 | +returnnil,fmt.Errorf("failed to mark notification as done: %w",err) |
| 262 | +} |
| 263 | +deferfunc() {_=resp.Body.Close() }() |
| 264 | + |
| 265 | +ifresp.StatusCode!=http.StatusResetContent&&resp.StatusCode!=http.StatusOK { |
| 266 | +body,err:=io.ReadAll(resp.Body) |
| 267 | +iferr!=nil { |
| 268 | +returnnil,fmt.Errorf("failed to read response body: %w",err) |
| 269 | +} |
| 270 | +returnmcp.NewToolResultError(fmt.Sprintf("failed to mark notification as done: %s",string(body))),nil |
| 271 | +} |
| 272 | + |
| 273 | +returnmcp.NewToolResultText("Notification marked as done"),nil |
| 274 | +} |
| 275 | +} |