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:
121
operation/user/profile.go
Normal file
121
operation/user/profile.go
Normal file
@@ -0,0 +1,121 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.lethalbits.com/lethalbits/gitea-mcp/pkg/gitea"
|
||||
"git.lethalbits.com/lethalbits/gitea-mcp/pkg/log"
|
||||
"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 (
|
||||
GetUserInfoToolName = "get_user_info"
|
||||
GetUserSettingsToolName = "get_user_settings"
|
||||
UpdateUserSettingsToolName = "update_user_settings"
|
||||
)
|
||||
|
||||
var (
|
||||
GetUserInfoTool = mcp.NewTool(
|
||||
GetUserInfoToolName,
|
||||
mcp.WithDescription("Get a user's public information by username"),
|
||||
mcp.WithString("username", mcp.Required(), mcp.Description("username")),
|
||||
)
|
||||
|
||||
GetUserSettingsTool = mcp.NewTool(
|
||||
GetUserSettingsToolName,
|
||||
mcp.WithDescription("Get the authenticated user's settings"),
|
||||
)
|
||||
|
||||
UpdateUserSettingsTool = mcp.NewTool(
|
||||
UpdateUserSettingsToolName,
|
||||
mcp.WithDescription("Update the authenticated user's settings"),
|
||||
mcp.WithString("full_name", mcp.Description("full name")),
|
||||
mcp.WithString("description", mcp.Description("user bio/description")),
|
||||
mcp.WithString("website", mcp.Description("website URL")),
|
||||
mcp.WithString("location", mcp.Description("location")),
|
||||
mcp.WithString("language", mcp.Description("language preference")),
|
||||
mcp.WithString("theme", mcp.Description("UI theme")),
|
||||
mcp.WithBoolean("hide_email", mcp.Description("hide email from profile")),
|
||||
mcp.WithBoolean("hide_activity", mcp.Description("hide activity from profile")),
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
Tool.RegisterRead(server.ServerTool{Tool: GetUserInfoTool, Handler: GetUserByNameFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: GetUserSettingsTool, Handler: GetUserSettingsFn})
|
||||
Tool.RegisterWrite(server.ServerTool{Tool: UpdateUserSettingsTool, Handler: UpdateUserSettingsFn})
|
||||
}
|
||||
|
||||
func GetUserByNameFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called GetUserByNameFn")
|
||||
username, ok := req.GetArguments()["username"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("username is required"))
|
||||
}
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
user, _, err := client.GetUserInfo(username)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get user %s err: %v", username, err))
|
||||
}
|
||||
return to.TextResult(user)
|
||||
}
|
||||
|
||||
func GetUserSettingsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called GetUserSettingsFn")
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
settings, _, err := client.GetUserSettings()
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get user settings err: %v", err))
|
||||
}
|
||||
return to.TextResult(settings)
|
||||
}
|
||||
|
||||
func UpdateUserSettingsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called UpdateUserSettingsFn")
|
||||
opt := gitea_sdk.UserSettingsOptions{}
|
||||
if v, ok := req.GetArguments()["full_name"].(string); ok {
|
||||
opt.FullName = &v
|
||||
}
|
||||
if v, ok := req.GetArguments()["description"].(string); ok {
|
||||
opt.Description = &v
|
||||
}
|
||||
if v, ok := req.GetArguments()["website"].(string); ok {
|
||||
opt.Website = &v
|
||||
}
|
||||
if v, ok := req.GetArguments()["location"].(string); ok {
|
||||
opt.Location = &v
|
||||
}
|
||||
if v, ok := req.GetArguments()["language"].(string); ok {
|
||||
opt.Language = &v
|
||||
}
|
||||
if v, ok := req.GetArguments()["theme"].(string); ok {
|
||||
opt.Theme = &v
|
||||
}
|
||||
if v, ok := req.GetArguments()["hide_email"].(bool); ok {
|
||||
opt.HideEmail = &v
|
||||
}
|
||||
if v, ok := req.GetArguments()["hide_activity"].(bool); ok {
|
||||
opt.HideActivity = &v
|
||||
}
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
settings, _, err := client.UpdateUserSettings(opt)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("update user settings err: %v", err))
|
||||
}
|
||||
return to.TextResult(settings)
|
||||
}
|
||||
Reference in New Issue
Block a user