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:
125
operation/user/blocks.go
Normal file
125
operation/user/blocks.go
Normal file
@@ -0,0 +1,125 @@
|
||||
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/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 (
|
||||
ListMyBlocksToolName = "list_my_blocks"
|
||||
CheckUserBlockToolName = "check_user_block"
|
||||
BlockUserToolName = "block_user"
|
||||
UnblockUserToolName = "unblock_user"
|
||||
)
|
||||
|
||||
var (
|
||||
ListMyBlocksTool = mcp.NewTool(
|
||||
ListMyBlocksToolName,
|
||||
mcp.WithDescription("List users blocked by the authenticated user"),
|
||||
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
|
||||
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
|
||||
)
|
||||
|
||||
CheckUserBlockTool = mcp.NewTool(
|
||||
CheckUserBlockToolName,
|
||||
mcp.WithDescription("Check if the authenticated user has blocked a user"),
|
||||
mcp.WithString("username", mcp.Required(), mcp.Description("username to check")),
|
||||
)
|
||||
|
||||
BlockUserTool = mcp.NewTool(
|
||||
BlockUserToolName,
|
||||
mcp.WithDescription("Block a user"),
|
||||
mcp.WithString("username", mcp.Required(), mcp.Description("username to block")),
|
||||
)
|
||||
|
||||
UnblockUserTool = mcp.NewTool(
|
||||
UnblockUserToolName,
|
||||
mcp.WithDescription("Unblock a user"),
|
||||
mcp.WithString("username", mcp.Required(), mcp.Description("username to unblock")),
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListMyBlocksTool, Handler: ListMyBlocksFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: CheckUserBlockTool, Handler: CheckUserBlockFn})
|
||||
Tool.RegisterWrite(server.ServerTool{Tool: BlockUserTool, Handler: BlockUserFn})
|
||||
Tool.RegisterWrite(server.ServerTool{Tool: UnblockUserTool, Handler: UnblockUserFn})
|
||||
}
|
||||
|
||||
func ListMyBlocksFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListMyBlocksFn")
|
||||
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))
|
||||
}
|
||||
users, _, err := client.ListMyBlocks(gitea_sdk.ListUserBlocksOptions{
|
||||
ListOptions: gitea_sdk.ListOptions{Page: int(page), PageSize: int(pageSize)},
|
||||
})
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("list my blocks err: %v", err))
|
||||
}
|
||||
return to.TextResult(users)
|
||||
}
|
||||
|
||||
func CheckUserBlockFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called CheckUserBlockFn")
|
||||
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))
|
||||
}
|
||||
isBlocked, _, err := client.CheckUserBlock(username)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("check block %s err: %v", username, err))
|
||||
}
|
||||
return to.TextResult(map[string]any{"username": username, "is_blocked": isBlocked})
|
||||
}
|
||||
|
||||
func BlockUserFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called BlockUserFn")
|
||||
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))
|
||||
}
|
||||
_, err = client.BlockUser(username)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("block user %s err: %v", username, err))
|
||||
}
|
||||
return to.TextResult(map[string]string{"status": "blocked", "username": username})
|
||||
}
|
||||
|
||||
func UnblockUserFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called UnblockUserFn")
|
||||
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))
|
||||
}
|
||||
_, err = client.UnblockUser(username)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("unblock user %s err: %v", username, err))
|
||||
}
|
||||
return to.TextResult(map[string]string{"status": "unblocked", "username": username})
|
||||
}
|
||||
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})
|
||||
}
|
||||
210
operation/user/followers.go
Normal file
210
operation/user/followers.go
Normal file
@@ -0,0 +1,210 @@
|
||||
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/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 (
|
||||
ListMyFollowersToolName = "list_my_followers"
|
||||
ListMyFollowingToolName = "list_my_following"
|
||||
ListUserFollowersToolName = "list_user_followers"
|
||||
ListUserFollowingToolName = "list_user_following"
|
||||
CheckFollowingToolName = "check_following"
|
||||
FollowUserToolName = "follow_user"
|
||||
UnfollowUserToolName = "unfollow_user"
|
||||
)
|
||||
|
||||
var (
|
||||
ListMyFollowersTool = mcp.NewTool(
|
||||
ListMyFollowersToolName,
|
||||
mcp.WithDescription("List the authenticated user's followers"),
|
||||
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
|
||||
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
|
||||
)
|
||||
|
||||
ListMyFollowingTool = mcp.NewTool(
|
||||
ListMyFollowingToolName,
|
||||
mcp.WithDescription("List users the authenticated user is following"),
|
||||
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
|
||||
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
|
||||
)
|
||||
|
||||
ListUserFollowersTool = mcp.NewTool(
|
||||
ListUserFollowersToolName,
|
||||
mcp.WithDescription("List a user's followers"),
|
||||
mcp.WithString("username", mcp.Required(), mcp.Description("username")),
|
||||
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
|
||||
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
|
||||
)
|
||||
|
||||
ListUserFollowingTool = mcp.NewTool(
|
||||
ListUserFollowingToolName,
|
||||
mcp.WithDescription("List users a user is following"),
|
||||
mcp.WithString("username", mcp.Required(), mcp.Description("username")),
|
||||
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
|
||||
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
|
||||
)
|
||||
|
||||
CheckFollowingTool = mcp.NewTool(
|
||||
CheckFollowingToolName,
|
||||
mcp.WithDescription("Check if the authenticated user is following a user"),
|
||||
mcp.WithString("username", mcp.Required(), mcp.Description("username to check")),
|
||||
)
|
||||
|
||||
FollowUserTool = mcp.NewTool(
|
||||
FollowUserToolName,
|
||||
mcp.WithDescription("Follow a user"),
|
||||
mcp.WithString("username", mcp.Required(), mcp.Description("username to follow")),
|
||||
)
|
||||
|
||||
UnfollowUserTool = mcp.NewTool(
|
||||
UnfollowUserToolName,
|
||||
mcp.WithDescription("Unfollow a user"),
|
||||
mcp.WithString("username", mcp.Required(), mcp.Description("username to unfollow")),
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListMyFollowersTool, Handler: ListMyFollowersFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListMyFollowingTool, Handler: ListMyFollowingFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListUserFollowersTool, Handler: ListUserFollowersFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListUserFollowingTool, Handler: ListUserFollowingFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: CheckFollowingTool, Handler: CheckFollowingFn})
|
||||
Tool.RegisterWrite(server.ServerTool{Tool: FollowUserTool, Handler: FollowUserFn})
|
||||
Tool.RegisterWrite(server.ServerTool{Tool: UnfollowUserTool, Handler: UnfollowUserFn})
|
||||
}
|
||||
|
||||
func ListMyFollowersFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListMyFollowersFn")
|
||||
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))
|
||||
}
|
||||
followers, _, err := client.ListMyFollowers(gitea_sdk.ListFollowersOptions{
|
||||
ListOptions: gitea_sdk.ListOptions{Page: int(page), PageSize: int(pageSize)},
|
||||
})
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("list my followers err: %v", err))
|
||||
}
|
||||
return to.TextResult(followers)
|
||||
}
|
||||
|
||||
func ListMyFollowingFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListMyFollowingFn")
|
||||
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))
|
||||
}
|
||||
following, _, err := client.ListMyFollowing(gitea_sdk.ListFollowingOptions{
|
||||
ListOptions: gitea_sdk.ListOptions{Page: int(page), PageSize: int(pageSize)},
|
||||
})
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("list my following err: %v", err))
|
||||
}
|
||||
return to.TextResult(following)
|
||||
}
|
||||
|
||||
func ListUserFollowersFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListUserFollowersFn")
|
||||
username, ok := req.GetArguments()["username"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("username is required"))
|
||||
}
|
||||
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))
|
||||
}
|
||||
followers, _, err := client.ListFollowers(username, gitea_sdk.ListFollowersOptions{
|
||||
ListOptions: gitea_sdk.ListOptions{Page: int(page), PageSize: int(pageSize)},
|
||||
})
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("list %s followers err: %v", username, err))
|
||||
}
|
||||
return to.TextResult(followers)
|
||||
}
|
||||
|
||||
func ListUserFollowingFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListUserFollowingFn")
|
||||
username, ok := req.GetArguments()["username"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("username is required"))
|
||||
}
|
||||
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))
|
||||
}
|
||||
following, _, err := client.ListFollowing(username, gitea_sdk.ListFollowingOptions{
|
||||
ListOptions: gitea_sdk.ListOptions{Page: int(page), PageSize: int(pageSize)},
|
||||
})
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("list %s following err: %v", username, err))
|
||||
}
|
||||
return to.TextResult(following)
|
||||
}
|
||||
|
||||
func CheckFollowingFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called CheckFollowingFn")
|
||||
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))
|
||||
}
|
||||
isFollowing, _ := client.IsFollowing(username)
|
||||
return to.TextResult(map[string]any{"username": username, "is_following": isFollowing})
|
||||
}
|
||||
|
||||
func FollowUserFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called FollowUserFn")
|
||||
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))
|
||||
}
|
||||
_, err = client.Follow(username)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("follow user %s err: %v", username, err))
|
||||
}
|
||||
return to.TextResult(map[string]string{"status": "following", "username": username})
|
||||
}
|
||||
|
||||
func UnfollowUserFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called UnfollowUserFn")
|
||||
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))
|
||||
}
|
||||
_, err = client.Unfollow(username)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("unfollow user %s err: %v", username, err))
|
||||
}
|
||||
return to.TextResult(map[string]string{"status": "unfollowed", "username": username})
|
||||
}
|
||||
169
operation/user/keys.go
Normal file
169
operation/user/keys.go
Normal file
@@ -0,0 +1,169 @@
|
||||
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/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 (
|
||||
ListMyPublicKeysToolName = "list_my_public_keys"
|
||||
ListUserPublicKeysToolName = "list_user_public_keys"
|
||||
GetPublicKeyToolName = "get_public_key"
|
||||
CreatePublicKeyToolName = "create_public_key"
|
||||
DeletePublicKeyToolName = "delete_public_key"
|
||||
)
|
||||
|
||||
var (
|
||||
ListMyPublicKeysTool = mcp.NewTool(
|
||||
ListMyPublicKeysToolName,
|
||||
mcp.WithDescription("List the authenticated user's SSH public keys"),
|
||||
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
|
||||
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
|
||||
)
|
||||
|
||||
ListUserPublicKeysTool = mcp.NewTool(
|
||||
ListUserPublicKeysToolName,
|
||||
mcp.WithDescription("List a user's SSH public keys"),
|
||||
mcp.WithString("username", mcp.Required(), mcp.Description("username")),
|
||||
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
|
||||
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
|
||||
)
|
||||
|
||||
GetPublicKeyTool = mcp.NewTool(
|
||||
GetPublicKeyToolName,
|
||||
mcp.WithDescription("Get an SSH public key by ID"),
|
||||
mcp.WithNumber("id", mcp.Required(), mcp.Description("key ID")),
|
||||
)
|
||||
|
||||
CreatePublicKeyTool = mcp.NewTool(
|
||||
CreatePublicKeyToolName,
|
||||
mcp.WithDescription("Create an SSH public key for the authenticated user"),
|
||||
mcp.WithString("title", mcp.Required(), mcp.Description("key title")),
|
||||
mcp.WithString("key", mcp.Required(), mcp.Description("SSH public key content")),
|
||||
mcp.WithBoolean("read_only", mcp.Description("whether the key is read-only")),
|
||||
)
|
||||
|
||||
DeletePublicKeyTool = mcp.NewTool(
|
||||
DeletePublicKeyToolName,
|
||||
mcp.WithDescription("Delete an SSH public key"),
|
||||
mcp.WithNumber("id", mcp.Required(), mcp.Description("key ID")),
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListMyPublicKeysTool, Handler: ListMyPublicKeysFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListUserPublicKeysTool, Handler: ListUserPublicKeysFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: GetPublicKeyTool, Handler: GetPublicKeyFn})
|
||||
Tool.RegisterWrite(server.ServerTool{Tool: CreatePublicKeyTool, Handler: CreatePublicKeyFn})
|
||||
Tool.RegisterWrite(server.ServerTool{Tool: DeletePublicKeyTool, Handler: DeletePublicKeyFn})
|
||||
}
|
||||
|
||||
func ListMyPublicKeysFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListMyPublicKeysFn")
|
||||
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))
|
||||
}
|
||||
keys, _, err := client.ListMyPublicKeys(gitea_sdk.ListPublicKeysOptions{
|
||||
ListOptions: gitea_sdk.ListOptions{Page: int(page), PageSize: int(pageSize)},
|
||||
})
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("list my public keys err: %v", err))
|
||||
}
|
||||
return to.TextResult(keys)
|
||||
}
|
||||
|
||||
func ListUserPublicKeysFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListUserPublicKeysFn")
|
||||
username, ok := req.GetArguments()["username"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("username is required"))
|
||||
}
|
||||
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))
|
||||
}
|
||||
keys, _, err := client.ListPublicKeys(username, gitea_sdk.ListPublicKeysOptions{
|
||||
ListOptions: gitea_sdk.ListOptions{Page: int(page), PageSize: int(pageSize)},
|
||||
})
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("list %s public keys err: %v", username, err))
|
||||
}
|
||||
return to.TextResult(keys)
|
||||
}
|
||||
|
||||
func GetPublicKeyFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called GetPublicKeyFn")
|
||||
id, err := params.GetIndex(req.GetArguments(), "id")
|
||||
if err != nil {
|
||||
return to.ErrorResult(err)
|
||||
}
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
key, _, err := client.GetPublicKey(id)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get public key %d err: %v", id, err))
|
||||
}
|
||||
return to.TextResult(key)
|
||||
}
|
||||
|
||||
func CreatePublicKeyFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called CreatePublicKeyFn")
|
||||
title, ok := req.GetArguments()["title"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("title is required"))
|
||||
}
|
||||
key, ok := req.GetArguments()["key"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("key is required"))
|
||||
}
|
||||
opt := gitea_sdk.CreateKeyOption{
|
||||
Title: title,
|
||||
Key: key,
|
||||
}
|
||||
if v, ok := req.GetArguments()["read_only"].(bool); ok {
|
||||
opt.ReadOnly = v
|
||||
}
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
pubKey, _, err := client.CreatePublicKey(opt)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("create public key err: %v", err))
|
||||
}
|
||||
return to.TextResult(pubKey)
|
||||
}
|
||||
|
||||
func DeletePublicKeyFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called DeletePublicKeyFn")
|
||||
id, err := params.GetIndex(req.GetArguments(), "id")
|
||||
if err != nil {
|
||||
return to.ErrorResult(err)
|
||||
}
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
_, err = client.DeletePublicKey(id)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("delete public key %d err: %v", id, err))
|
||||
}
|
||||
return to.TextResult(map[string]any{"status": "deleted", "key_id": id})
|
||||
}
|
||||
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)
|
||||
}
|
||||
254
operation/user/repos.go
Normal file
254
operation/user/repos.go
Normal file
@@ -0,0 +1,254 @@
|
||||
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/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 (
|
||||
ListUserReposToolName = "list_user_repos"
|
||||
ListMyStarredToolName = "list_my_starred"
|
||||
StarRepoToolName = "star_repo"
|
||||
UnstarRepoToolName = "unstar_repo"
|
||||
CheckStarredToolName = "check_starred"
|
||||
ListMySubscriptionsToolName = "list_my_subscriptions"
|
||||
ListUserHeatmapToolName = "list_user_heatmap"
|
||||
ListUserActivityToolName = "list_user_activity"
|
||||
)
|
||||
|
||||
var (
|
||||
ListUserReposTool = mcp.NewTool(
|
||||
ListUserReposToolName,
|
||||
mcp.WithDescription("List a user's repositories"),
|
||||
mcp.WithString("username", mcp.Required(), mcp.Description("username")),
|
||||
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
|
||||
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
|
||||
)
|
||||
|
||||
ListMyStarredTool = mcp.NewTool(
|
||||
ListMyStarredToolName,
|
||||
mcp.WithDescription("List repositories starred by the authenticated user"),
|
||||
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
|
||||
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
|
||||
)
|
||||
|
||||
StarRepoTool = mcp.NewTool(
|
||||
StarRepoToolName,
|
||||
mcp.WithDescription("Star a repository"),
|
||||
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
|
||||
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
|
||||
)
|
||||
|
||||
UnstarRepoTool = mcp.NewTool(
|
||||
UnstarRepoToolName,
|
||||
mcp.WithDescription("Unstar a repository"),
|
||||
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
|
||||
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
|
||||
)
|
||||
|
||||
CheckStarredTool = mcp.NewTool(
|
||||
CheckStarredToolName,
|
||||
mcp.WithDescription("Check if the authenticated user has starred a repository"),
|
||||
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
|
||||
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
|
||||
)
|
||||
|
||||
ListMySubscriptionsTool = mcp.NewTool(
|
||||
ListMySubscriptionsToolName,
|
||||
mcp.WithDescription("List repositories watched by the authenticated user"),
|
||||
)
|
||||
|
||||
ListUserHeatmapTool = mcp.NewTool(
|
||||
ListUserHeatmapToolName,
|
||||
mcp.WithDescription("Get a user's contribution heatmap data"),
|
||||
mcp.WithString("username", mcp.Required(), mcp.Description("username")),
|
||||
)
|
||||
|
||||
ListUserActivityTool = mcp.NewTool(
|
||||
ListUserActivityToolName,
|
||||
mcp.WithDescription("List a user's activity feeds"),
|
||||
mcp.WithString("username", mcp.Required(), mcp.Description("username")),
|
||||
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
|
||||
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListUserReposTool, Handler: ListUserReposFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListMyStarredTool, Handler: ListMyStarredFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: CheckStarredTool, Handler: CheckStarredFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListMySubscriptionsTool, Handler: ListMySubscriptionsFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListUserHeatmapTool, Handler: ListUserHeatmapFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListUserActivityTool, Handler: ListUserActivityFn})
|
||||
Tool.RegisterWrite(server.ServerTool{Tool: StarRepoTool, Handler: StarRepoFn})
|
||||
Tool.RegisterWrite(server.ServerTool{Tool: UnstarRepoTool, Handler: UnstarRepoFn})
|
||||
}
|
||||
|
||||
func ListUserReposFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListUserReposFn")
|
||||
username, ok := req.GetArguments()["username"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("username is required"))
|
||||
}
|
||||
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))
|
||||
}
|
||||
repos, _, err := client.ListUserRepos(username, gitea_sdk.ListReposOptions{
|
||||
ListOptions: gitea_sdk.ListOptions{Page: int(page), PageSize: int(pageSize)},
|
||||
})
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("list %s repos err: %v", username, err))
|
||||
}
|
||||
return to.TextResult(repos)
|
||||
}
|
||||
|
||||
func ListMyStarredFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListMyStarredFn")
|
||||
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))
|
||||
}
|
||||
repos, _, err := client.GetMyStarredRepos()
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("list my starred repos err: %v", err))
|
||||
}
|
||||
// Manual pagination since SDK returns all
|
||||
start := (int(page) - 1) * int(pageSize)
|
||||
if start >= len(repos) {
|
||||
return to.TextResult([]*gitea_sdk.Repository{})
|
||||
}
|
||||
end := start + int(pageSize)
|
||||
if end > len(repos) {
|
||||
end = len(repos)
|
||||
}
|
||||
return to.TextResult(repos[start:end])
|
||||
}
|
||||
|
||||
func StarRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called StarRepoFn")
|
||||
owner, ok := req.GetArguments()["owner"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("owner is required"))
|
||||
}
|
||||
repo, ok := req.GetArguments()["repo"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("repo is required"))
|
||||
}
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
_, err = client.StarRepo(owner, repo)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("star %s/%s err: %v", owner, repo, err))
|
||||
}
|
||||
return to.TextResult(map[string]string{"status": "starred", "owner": owner, "repo": repo})
|
||||
}
|
||||
|
||||
func UnstarRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called UnstarRepoFn")
|
||||
owner, ok := req.GetArguments()["owner"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("owner is required"))
|
||||
}
|
||||
repo, ok := req.GetArguments()["repo"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("repo is required"))
|
||||
}
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
_, err = client.UnStarRepo(owner, repo)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("unstar %s/%s err: %v", owner, repo, err))
|
||||
}
|
||||
return to.TextResult(map[string]string{"status": "unstarred", "owner": owner, "repo": repo})
|
||||
}
|
||||
|
||||
func CheckStarredFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called CheckStarredFn")
|
||||
owner, ok := req.GetArguments()["owner"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("owner is required"))
|
||||
}
|
||||
repo, ok := req.GetArguments()["repo"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("repo is required"))
|
||||
}
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
isStarred, _, err := client.IsRepoStarring(owner, repo)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("check starred %s/%s err: %v", owner, repo, err))
|
||||
}
|
||||
return to.TextResult(map[string]any{"owner": owner, "repo": repo, "is_starred": isStarred})
|
||||
}
|
||||
|
||||
func ListMySubscriptionsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListMySubscriptionsFn")
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
repos, _, err := client.GetMyWatchedRepos()
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("list my subscriptions err: %v", err))
|
||||
}
|
||||
return to.TextResult(repos)
|
||||
}
|
||||
|
||||
func ListUserHeatmapFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListUserHeatmapFn")
|
||||
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))
|
||||
}
|
||||
heatmap, _, err := client.GetUserHeatmap(username)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get %s heatmap err: %v", username, err))
|
||||
}
|
||||
return to.TextResult(heatmap)
|
||||
}
|
||||
|
||||
func ListUserActivityFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListUserActivityFn")
|
||||
username, ok := req.GetArguments()["username"].(string)
|
||||
if !ok {
|
||||
return to.ErrorResult(errors.New("username is required"))
|
||||
}
|
||||
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))
|
||||
}
|
||||
feeds, _, err := client.ListUserActivityFeeds(username, gitea_sdk.ListUserActivityFeedsOptions{
|
||||
ListOptions: gitea_sdk.ListOptions{Page: int(page), PageSize: int(pageSize)},
|
||||
})
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("list %s activity err: %v", username, err))
|
||||
}
|
||||
return to.TextResult(feeds)
|
||||
}
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.com/gitea/gitea-mcp/pkg/gitea"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/log"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/params"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/to"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/tool"
|
||||
"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"
|
||||
"git.lethalbits.com/lethalbits/gitea-mcp/pkg/tool"
|
||||
|
||||
gitea_sdk "code.gitea.io/sdk/gitea"
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
|
||||
Reference in New Issue
Block a user