Add notification_read and notification_write tools (#172)
Add notification management via two new MCP tools using the method-dispatch pattern: - `notification_read`: list notifications (global or repo-scoped, with status/subject_type/since/before filters) and get single notification thread by ID - `notification_write`: mark single notification as read, mark all notifications as read (global or repo-scoped) --- This PR was written with the help of Claude Opus 4.6 Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/172 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-committed-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
gitea_sdk "code.gitea.io/sdk/gitea"
|
||||
)
|
||||
|
||||
func slimThread(t *gitea_sdk.NotificationThread) map[string]any {
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
m := map[string]any{
|
||||
"id": t.ID,
|
||||
"unread": t.Unread,
|
||||
"updated_at": t.UpdatedAt,
|
||||
}
|
||||
if t.Pinned {
|
||||
m["pinned"] = true
|
||||
}
|
||||
if t.Repository != nil {
|
||||
m["repository"] = t.Repository.FullName
|
||||
}
|
||||
if t.Subject != nil {
|
||||
subject := map[string]any{
|
||||
"title": t.Subject.Title,
|
||||
"type": t.Subject.Type,
|
||||
"state": t.Subject.State,
|
||||
}
|
||||
if t.Subject.HTMLURL != "" {
|
||||
subject["html_url"] = t.Subject.HTMLURL
|
||||
}
|
||||
if t.Subject.LatestCommentHTMLURL != "" {
|
||||
subject["latest_comment_html_url"] = t.Subject.LatestCommentHTMLURL
|
||||
}
|
||||
m["subject"] = subject
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func slimThreads(threads []*gitea_sdk.NotificationThread) []map[string]any {
|
||||
out := make([]map[string]any, 0, len(threads))
|
||||
for _, t := range threads {
|
||||
if t == nil {
|
||||
continue
|
||||
}
|
||||
m := map[string]any{
|
||||
"id": t.ID,
|
||||
"unread": t.Unread,
|
||||
"updated_at": t.UpdatedAt,
|
||||
}
|
||||
if t.Pinned {
|
||||
m["pinned"] = true
|
||||
}
|
||||
if t.Repository != nil {
|
||||
m["repository"] = t.Repository.FullName
|
||||
}
|
||||
if t.Subject != nil {
|
||||
m["subject"] = map[string]any{
|
||||
"title": t.Subject.Title,
|
||||
"type": t.Subject.Type,
|
||||
"state": t.Subject.State,
|
||||
}
|
||||
}
|
||||
out = append(out, m)
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user