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:
134
operation/repo/status.go
Normal file
134
operation/repo/status.go
Normal file
@@ -0,0 +1,134 @@
|
||||
package repo
|
||||
|
||||
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 (
|
||||
CreateStatusToolName = "create_commit_status"
|
||||
ListStatusesToolName = "list_commit_statuses"
|
||||
GetCombinedStatusToolName = "get_combined_status"
|
||||
)
|
||||
|
||||
var (
|
||||
CreateStatusTool = mcp.NewTool(
|
||||
CreateStatusToolName,
|
||||
mcp.WithDescription("Create a commit status"),
|
||||
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
|
||||
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
|
||||
mcp.WithString("sha", mcp.Required(), mcp.Description("commit SHA")),
|
||||
mcp.WithString("state", mcp.Required(), mcp.Description("status state: pending, success, error, failure, warning")),
|
||||
mcp.WithString("target_url", mcp.Description("URL for status details")),
|
||||
mcp.WithString("description", mcp.Description("status description")),
|
||||
mcp.WithString("context", mcp.Description("status context (e.g., ci/build)")),
|
||||
)
|
||||
|
||||
ListStatusesTool = mcp.NewTool(
|
||||
ListStatusesToolName,
|
||||
mcp.WithDescription("List commit statuses for a ref"),
|
||||
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
|
||||
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
|
||||
mcp.WithString("ref", mcp.Required(), mcp.Description("commit SHA, branch, or tag")),
|
||||
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
|
||||
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
|
||||
)
|
||||
|
||||
GetCombinedStatusTool = mcp.NewTool(
|
||||
GetCombinedStatusToolName,
|
||||
mcp.WithDescription("Get the combined status for a ref"),
|
||||
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
|
||||
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
|
||||
mcp.WithString("ref", mcp.Required(), mcp.Description("commit SHA, branch, or tag")),
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
Tool.RegisterRead(server.ServerTool{Tool: ListStatusesTool, Handler: ListStatusesFn})
|
||||
Tool.RegisterRead(server.ServerTool{Tool: GetCombinedStatusTool, Handler: GetCombinedStatusFn})
|
||||
Tool.RegisterWrite(server.ServerTool{Tool: CreateStatusTool, Handler: CreateStatusFn})
|
||||
}
|
||||
|
||||
func CreateStatusFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called CreateStatusFn")
|
||||
owner, _ := req.GetArguments()["owner"].(string)
|
||||
repo, _ := req.GetArguments()["repo"].(string)
|
||||
sha, _ := req.GetArguments()["sha"].(string)
|
||||
state, _ := req.GetArguments()["state"].(string)
|
||||
if owner == "" || repo == "" || sha == "" || state == "" {
|
||||
return to.ErrorResult(errors.New("owner, repo, sha, and state are required"))
|
||||
}
|
||||
opt := gitea_sdk.CreateStatusOption{
|
||||
State: gitea_sdk.StatusState(state),
|
||||
}
|
||||
if v, ok := req.GetArguments()["target_url"].(string); ok {
|
||||
opt.TargetURL = v
|
||||
}
|
||||
if v, ok := req.GetArguments()["description"].(string); ok {
|
||||
opt.Description = v
|
||||
}
|
||||
if v, ok := req.GetArguments()["context"].(string); ok {
|
||||
opt.Context = v
|
||||
}
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
status, _, err := client.CreateStatus(owner, repo, sha, opt)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("create status err: %v", err))
|
||||
}
|
||||
return to.TextResult(status)
|
||||
}
|
||||
|
||||
func ListStatusesFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called ListStatusesFn")
|
||||
owner, _ := req.GetArguments()["owner"].(string)
|
||||
repo, _ := req.GetArguments()["repo"].(string)
|
||||
ref, _ := req.GetArguments()["ref"].(string)
|
||||
if owner == "" || repo == "" || ref == "" {
|
||||
return to.ErrorResult(errors.New("owner, repo, and ref are 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))
|
||||
}
|
||||
statuses, _, err := client.ListStatuses(owner, repo, ref, gitea_sdk.ListStatusesOption{
|
||||
ListOptions: gitea_sdk.ListOptions{Page: int(page), PageSize: int(pageSize)},
|
||||
})
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("list statuses err: %v", err))
|
||||
}
|
||||
return to.TextResult(statuses)
|
||||
}
|
||||
|
||||
func GetCombinedStatusFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called GetCombinedStatusFn")
|
||||
owner, _ := req.GetArguments()["owner"].(string)
|
||||
repo, _ := req.GetArguments()["repo"].(string)
|
||||
ref, _ := req.GetArguments()["ref"].(string)
|
||||
if owner == "" || repo == "" || ref == "" {
|
||||
return to.ErrorResult(errors.New("owner, repo, and ref are required"))
|
||||
}
|
||||
client, err := gitea.ClientFromContext(ctx)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get gitea client err: %v", err))
|
||||
}
|
||||
combined, _, err := client.GetCombinedStatus(owner, repo, ref)
|
||||
if err != nil {
|
||||
return to.ErrorResult(fmt.Errorf("get combined status err: %v", err))
|
||||
}
|
||||
return to.TextResult(combined)
|
||||
}
|
||||
Reference in New Issue
Block a user