feat: expand MCP tool coverage from 93 to 299 tools
Some checks failed
release-nightly / release-image (push) Failing after 2m17s
Some checks failed
release-nightly / release-image (push) Failing after 2m17s
Fork the official gitea-mcp and massively extend API coverage: - Organization: orgs, members, teams, hooks, blocks, activity (34 tools) - User: profile, followers, keys, emails, repos, blocks (30 tools) - Repository: collaborators, webhooks, branch/tag protection, deploy keys, topics, git refs/trees/notes, commit status, stars/watchers, forks, transfers, mirrors, templates (53 tools) - Issue: reactions, pins, subscriptions, timeline, templates (16 tools) - Notifications: list, check, read, repo-scoped (7 tools) - Settings: API, attachment, repo, UI settings (4 tools) - Packages: list, get, delete, files, latest, link/unlink (7 tools) - Miscellaneous: server version, gitignore/label/license templates, markdown/markup rendering, node info, signing keys (12 tools) - Admin: user/org/repo CRUD, system webhooks, cron tasks, unadopted repos, emails, badges (23 tools) Module path updated to git.lethalbits.com/lethalbits/gitea-mcp.
This commit is contained in:
119
operation/user/emails.go
Normal file
119
operation/user/emails.go
Normal file
@@ -0,0 +1,119 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.lethalbits.com/lethalbits/gitea-mcp/pkg/gitea"
|
||||
"git.lethalbits.com/lethalbits/gitea-mcp/pkg/log"
|
||||
"git.lethalbits.com/lethalbits/gitea-mcp/pkg/params"
|
||||
"git.lethalbits.com/lethalbits/gitea-mcp/pkg/to"
|
||||
|
||||
gitea_sdk "code.gitea.io/sdk/gitea"
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
"github.com/mark3labs/mcp-go/server"
|
||||
)
|
||||
|
||||
const (
|
||||
ListEmailsToolName = "list_emails"
|
||||
AddEmailToolName = "add_email"
|
||||
DeleteEmailToolName = "delete_email"
|
||||
)
|
||||
|
||||
var (
|
||||
ListEmailsTool = mcp.NewTool(
|
||||
ListEmailsToolName,
|
||||
mcp.WithDescription("List the authenticated user's email addresses"),
|
||||
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
|
||||
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
|
||||
)
|
||||
|
||||
AddEmailTool = mcp.NewTool(
|
||||
AddEmailToolName,
|
||||
mcp.WithDescription("Add email addresses for the authenticated user"),
|
||||
mcp.WithArray("emails", mcp.Required(), mcp.Description("email addresses to add"), mcp.Items(map[string]any{"type": "string"})),
|
||||
)
|
||||
|
||||
DeleteEmailTool = mcp.NewTool(
|
||||
DeleteEmailToolName,
|
||||
mcp.WithDescription("Delete email addresses for the authenticated user"),
|
||||
mcp.WithArray("emails", mcp.Required(), mcp.Description("email addresses to delete"), mcp.Items(map[string]any{"type": "string"})),
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListEmailsTool, Handler: ListEmailsFn})
|
||||
Tool.RegisterWrite(server.ServerTool{Tool: AddEmailTool, Handler: AddEmailFn})
|
||||
Tool.RegisterWrite(server.ServerTool{Tool: DeleteEmailTool, Handler: DeleteEmailFn})
|
||||
}
|
||||
|
||||
func ListEmailsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListEmailsFn")
|
||||
page := params.GetOptionalInt(req.GetArguments(), "page", 1)
|
||||
pageSize := params.GetOptionalInt(req.GetArguments(), "pageSize", 100)
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
emails, _, err := client.ListEmails(gitea_sdk.ListEmailsOptions{
|
||||
ListOptions: gitea_sdk.ListOptions{Page: int(page), PageSize: int(pageSize)},
|
||||
})
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("list emails err: %v", err))
|
||||
}
|
||||
return to.TextResult(emails)
|
||||
}
|
||||
|
||||
func AddEmailFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called AddEmailFn")
|
||||
emailsArg, exists := req.GetArguments()["emails"]
|
||||
if !exists {
|
||||
return to.ErrorResult(fmt.Errorf("emails is required"))
|
||||
}
|
||||
emailsSlice, ok := emailsArg.([]any)
|
||||
if !ok {
|
||||
return to.ErrorResult(fmt.Errorf("emails must be an array"))
|
||||
}
|
||||
emails := make([]string, 0, len(emailsSlice))
|
||||
for _, e := range emailsSlice {
|
||||
if s, ok := e.(string); ok {
|
||||
emails = append(emails, s)
|
||||
}
|
||||
}
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
result, _, err := client.AddEmail(gitea_sdk.CreateEmailOption{Emails: emails})
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("add emails err: %v", err))
|
||||
}
|
||||
return to.TextResult(result)
|
||||
}
|
||||
|
||||
func DeleteEmailFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called DeleteEmailFn")
|
||||
emailsArg, exists := req.GetArguments()["emails"]
|
||||
if !exists {
|
||||
return to.ErrorResult(fmt.Errorf("emails is required"))
|
||||
}
|
||||
emailsSlice, ok := emailsArg.([]any)
|
||||
if !ok {
|
||||
return to.ErrorResult(fmt.Errorf("emails must be an array"))
|
||||
}
|
||||
emails := make([]string, 0, len(emailsSlice))
|
||||
for _, e := range emailsSlice {
|
||||
if s, ok := e.(string); ok {
|
||||
emails = append(emails, s)
|
||||
}
|
||||
}
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
_, err = client.DeleteEmail(gitea_sdk.DeleteEmailOption{Emails: emails})
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("delete emails err: %v", err))
|
||||
}
|
||||
return to.TextResult(map[string]any{"status": "deleted", "emails": emails})
|
||||
}
|
||||
Reference in New Issue
Block a user