feat: expand MCP tool coverage from 93 to 299 tools
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:
Andrew Miller
2026-03-05 11:03:20 -05:00
parent 9ce5604e4c
commit df25d328d1
66 changed files with 6976 additions and 122 deletions

View File

@@ -0,0 +1,145 @@
package organization
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 (
ListOrgBlocksToolName = "list_org_blocks"
CheckOrgBlockToolName = "check_org_block"
BlockOrgUserToolName = "block_org_user"
UnblockOrgUserToolName = "unblock_org_user"
)
var (
ListOrgBlocksTool = mcp.NewTool(
ListOrgBlocksToolName,
mcp.WithDescription("List users blocked by an organization"),
mcp.WithString("org", mcp.Required(), mcp.Description("organization name")),
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
)
CheckOrgBlockTool = mcp.NewTool(
CheckOrgBlockToolName,
mcp.WithDescription("Check if a user is blocked by an organization"),
mcp.WithString("org", mcp.Required(), mcp.Description("organization name")),
mcp.WithString("username", mcp.Required(), mcp.Description("username to check")),
)
BlockOrgUserTool = mcp.NewTool(
BlockOrgUserToolName,
mcp.WithDescription("Block a user from an organization"),
mcp.WithString("org", mcp.Required(), mcp.Description("organization name")),
mcp.WithString("username", mcp.Required(), mcp.Description("username to block")),
)
UnblockOrgUserTool = mcp.NewTool(
UnblockOrgUserToolName,
mcp.WithDescription("Unblock a user from an organization"),
mcp.WithString("org", mcp.Required(), mcp.Description("organization name")),
mcp.WithString("username", mcp.Required(), mcp.Description("username to unblock")),
)
)
func init() {
Tool.RegisterRead(server.ServerTool{Tool: ListOrgBlocksTool, Handler: ListOrgBlocksFn})
Tool.RegisterRead(server.ServerTool{Tool: CheckOrgBlockTool, Handler: CheckOrgBlockFn})
Tool.RegisterWrite(server.ServerTool{Tool: BlockOrgUserTool, Handler: BlockOrgUserFn})
Tool.RegisterWrite(server.ServerTool{Tool: UnblockOrgUserTool, Handler: UnblockOrgUserFn})
}
func ListOrgBlocksFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called ListOrgBlocksFn")
org, ok := req.GetArguments()["org"].(string)
if !ok {
return to.ErrorResult(errors.New("org 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))
}
users, _, err := client.ListOrgBlocks(org, gitea_sdk.ListOrgBlocksOptions{
ListOptions: gitea_sdk.ListOptions{Page: int(page), PageSize: int(pageSize)},
})
if err != nil {
return to.ErrorResult(fmt.Errorf("list org %s blocks err: %v", org, err))
}
return to.TextResult(users)
}
func CheckOrgBlockFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called CheckOrgBlockFn")
org, ok := req.GetArguments()["org"].(string)
if !ok {
return to.ErrorResult(errors.New("org is required"))
}
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.CheckOrgBlock(org, username)
if err != nil {
return to.ErrorResult(fmt.Errorf("check org %s block for %s err: %v", org, username, err))
}
return to.TextResult(map[string]any{"org": org, "username": username, "is_blocked": isBlocked})
}
func BlockOrgUserFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called BlockOrgUserFn")
org, ok := req.GetArguments()["org"].(string)
if !ok {
return to.ErrorResult(errors.New("org is required"))
}
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.BlockOrgUser(org, username)
if err != nil {
return to.ErrorResult(fmt.Errorf("block user %s from org %s err: %v", username, org, err))
}
return to.TextResult(map[string]string{"status": "blocked", "org": org, "username": username})
}
func UnblockOrgUserFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called UnblockOrgUserFn")
org, ok := req.GetArguments()["org"].(string)
if !ok {
return to.ErrorResult(errors.New("org is required"))
}
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.UnblockOrgUser(org, username)
if err != nil {
return to.ErrorResult(fmt.Errorf("unblock user %s from org %s err: %v", username, org, err))
}
return to.TextResult(map[string]string{"status": "unblocked", "org": org, "username": username})
}