This commit is contained in:
hiifong
2025-03-23 21:32:53 +08:00
parent 065f65ad2a
commit f4bbd5a09a
7 changed files with 415 additions and 189 deletions

View File

@@ -24,31 +24,36 @@ var (
GetIssueByIndexTool = mcp.NewTool( GetIssueByIndexTool = mcp.NewTool(
GetIssueByIndexToolName, GetIssueByIndexToolName,
mcp.WithDescription("get issue by index"), mcp.WithDescription("get issue by index"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithNumber("index", mcp.Required(), mcp.Description("repository issue index"), mcp.DefaultNumber(0)), mcp.WithNumber("index", mcp.Required(), mcp.Description("repository issue index")),
) )
ListRepoIssuesTool = mcp.NewTool( ListRepoIssuesTool = mcp.NewTool(
ListRepoIssuesToolName, ListRepoIssuesToolName,
mcp.WithDescription("List repository issues"), mcp.WithDescription("List repository issues"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithString("state", mcp.Description("issue state"), mcp.DefaultString("all")),
mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)),
mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)),
) )
CreateIssueTool = mcp.NewTool( CreateIssueTool = mcp.NewTool(
CreateIssueToolName, CreateIssueToolName,
mcp.WithDescription("create issue"), mcp.WithDescription("create issue"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithString("title", mcp.Required(), mcp.Description("issue title"), mcp.DefaultString("")), mcp.WithString("title", mcp.Required(), mcp.Description("issue title")),
mcp.WithString("body", mcp.Required(), mcp.Description("issue body"), mcp.DefaultString("")), mcp.WithString("body", mcp.Required(), mcp.Description("issue body")),
) )
CreateIssueCommentTool = mcp.NewTool( CreateIssueCommentTool = mcp.NewTool(
CreateIssueCommentToolName, CreateIssueCommentToolName,
mcp.WithDescription("create issue comment"), mcp.WithDescription("create issue comment"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithNumber("index", mcp.Required(), mcp.Description("repository issue index"), mcp.DefaultNumber(0)), mcp.WithNumber("index", mcp.Required(), mcp.Description("repository issue index")),
mcp.WithString("body", mcp.Required(), mcp.Description("issue comment body"), mcp.DefaultString("")), mcp.WithString("body", mcp.Required(), mcp.Description("issue comment body")),
) )
) )
@@ -61,9 +66,18 @@ func RegisterTool(s *server.MCPServer) {
func GetIssueByIndexFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func GetIssueByIndexFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called GetIssueByIndexFn") log.Debugf("Called GetIssueByIndexFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
index := req.Params.Arguments["index"].(float64) return nil, fmt.Errorf("owner is required")
}
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
index, ok := req.Params.Arguments["index"].(float64)
if !ok {
return nil, fmt.Errorf("index is required")
}
issue, _, err := gitea.Client().GetIssue(owner, repo, int64(index)) issue, _, err := gitea.Client().GetIssue(owner, repo, int64(index))
if err != nil { if err != nil {
return nil, fmt.Errorf("get %v/%v/issue/%v err", owner, repo, int64(index)) return nil, fmt.Errorf("get %v/%v/issue/%v err", owner, repo, int64(index))
@@ -74,9 +88,33 @@ func GetIssueByIndexFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallT
func ListRepoIssuesFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func ListRepoIssuesFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called ListIssuesFn") log.Debugf("Called ListIssuesFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
opt := gitea_sdk.ListIssueOption{} return nil, fmt.Errorf("owner is required")
}
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
state, ok := req.Params.Arguments["state"].(string)
if !ok {
state = "all"
}
page, ok := req.Params.Arguments["page"].(float64)
if !ok {
page = 1
}
pageSize, ok := req.Params.Arguments["pageSize"].(float64)
if !ok {
pageSize = 100
}
opt := gitea_sdk.ListIssueOption{
State: gitea_sdk.StateType(state),
ListOptions: gitea_sdk.ListOptions{
Page: int(page),
PageSize: int(pageSize),
},
}
issues, _, err := gitea.Client().ListRepoIssues(owner, repo, opt) issues, _, err := gitea.Client().ListRepoIssues(owner, repo, opt)
if err != nil { if err != nil {
return nil, fmt.Errorf("get %v/%v/issues err", owner, repo) return nil, fmt.Errorf("get %v/%v/issues err", owner, repo)
@@ -86,10 +124,22 @@ func ListRepoIssuesFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTo
func CreateIssueFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func CreateIssueFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called CreateIssueFn") log.Debugf("Called CreateIssueFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
title := req.Params.Arguments["title"].(string) return nil, fmt.Errorf("owner is required")
body := req.Params.Arguments["body"].(string) }
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
title, ok := req.Params.Arguments["title"].(string)
if !ok {
return nil, fmt.Errorf("title is required")
}
body, ok := req.Params.Arguments["body"].(string)
if !ok {
return nil, fmt.Errorf("body is required")
}
issue, _, err := gitea.Client().CreateIssue(owner, repo, gitea_sdk.CreateIssueOption{ issue, _, err := gitea.Client().CreateIssue(owner, repo, gitea_sdk.CreateIssueOption{
Title: title, Title: title,
Body: body, Body: body,
@@ -103,13 +153,26 @@ func CreateIssueFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolR
func CreateIssueCommentFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func CreateIssueCommentFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called CreateIssueCommentFn") log.Debugf("Called CreateIssueCommentFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
index := req.Params.Arguments["index"].(float64) return nil, fmt.Errorf("owner is required")
body := req.Params.Arguments["body"].(string) }
issueComment, _, err := gitea.Client().CreateIssueComment(owner, repo, int64(index), gitea_sdk.CreateIssueCommentOption{ repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
index, ok := req.Params.Arguments["index"].(float64)
if !ok {
return nil, fmt.Errorf("index is required")
}
body, ok := req.Params.Arguments["body"].(string)
if !ok {
return nil, fmt.Errorf("body is required")
}
opt := gitea_sdk.CreateIssueCommentOption{
Body: body, Body: body,
}) }
issueComment, _, err := gitea.Client().CreateIssueComment(owner, repo, int64(index), opt)
if err != nil { if err != nil {
return nil, fmt.Errorf("create %v/%v/issue/%v/comment err", owner, repo, int64(index)) return nil, fmt.Errorf("create %v/%v/issue/%v/comment err", owner, repo, int64(index))
} }

View File

@@ -23,30 +23,30 @@ var (
GetPullRequestByIndexTool = mcp.NewTool( GetPullRequestByIndexTool = mcp.NewTool(
GetPullRequestByIndexToolName, GetPullRequestByIndexToolName,
mcp.WithDescription("get pull request by index"), mcp.WithDescription("get pull request by index"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithNumber("index", mcp.Required(), mcp.Description("repository pull request index"), mcp.DefaultNumber(0)), mcp.WithNumber("index", mcp.Required(), mcp.Description("repository pull request index")),
) )
ListRepoPullRequestsTool = mcp.NewTool( ListRepoPullRequestsTool = mcp.NewTool(
ListRepoPullRequestsToolName, ListRepoPullRequestsToolName,
mcp.WithDescription("List repository pull requests"), mcp.WithDescription("List repository pull requests"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithString("state", mcp.Description("state"), mcp.DefaultString("")), mcp.WithString("state", mcp.Description("state")),
mcp.WithString("sort", mcp.Description("sort"), mcp.DefaultString("")), mcp.WithString("sort", mcp.Description("sort")),
mcp.WithNumber("milestone", mcp.Description("milestone"), mcp.DefaultNumber(0)), mcp.WithNumber("milestone", mcp.Description("milestone")),
) )
CreatePullRequestTool = mcp.NewTool( CreatePullRequestTool = mcp.NewTool(
CreatePullRequestToolName, CreatePullRequestToolName,
mcp.WithDescription("create pull request"), mcp.WithDescription("create pull request"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithString("title", mcp.Required(), mcp.Description("pull request title"), mcp.DefaultString("")), mcp.WithString("title", mcp.Required(), mcp.Description("pull request title")),
mcp.WithString("body", mcp.Required(), mcp.Description("pull request body"), mcp.DefaultString("")), mcp.WithString("body", mcp.Required(), mcp.Description("pull request body")),
mcp.WithString("head", mcp.Required(), mcp.Description("pull request head"), mcp.DefaultString("")), mcp.WithString("head", mcp.Required(), mcp.Description("pull request head")),
mcp.WithString("base", mcp.Required(), mcp.Description("pull request base"), mcp.DefaultString("")), mcp.WithString("base", mcp.Required(), mcp.Description("pull request base")),
) )
) )
@@ -58,9 +58,18 @@ func RegisterTool(s *server.MCPServer) {
func GetPullRequestByIndexFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func GetPullRequestByIndexFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called GetPullRequestByIndexFn") log.Debugf("Called GetPullRequestByIndexFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
index := req.Params.Arguments["index"].(float64) return nil, fmt.Errorf("owner is required")
}
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
index, ok := req.Params.Arguments["index"].(float64)
if !ok {
return nil, fmt.Errorf("index is required")
}
pr, _, err := gitea.Client().GetPullRequest(owner, repo, int64(index)) pr, _, err := gitea.Client().GetPullRequest(owner, repo, int64(index))
if err != nil { if err != nil {
return nil, fmt.Errorf("get %v/%v/pr/%v err", owner, repo, int64(index)) return nil, fmt.Errorf("get %v/%v/pr/%v err", owner, repo, int64(index))
@@ -71,12 +80,21 @@ func GetPullRequestByIndexFn(ctx context.Context, req mcp.CallToolRequest) (*mcp
func ListRepoPullRequestsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func ListRepoPullRequestsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called ListRepoPullRequests") log.Debugf("Called ListRepoPullRequests")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
return nil, fmt.Errorf("owner is required")
}
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
state, _ := req.Params.Arguments["state"].(string)
sort, _ := req.Params.Arguments["sort"].(string)
milestone, _ := req.Params.Arguments["milestone"].(float64)
opt := gitea_sdk.ListPullRequestsOptions{ opt := gitea_sdk.ListPullRequestsOptions{
State: gitea_sdk.StateType(req.Params.Arguments["state"].(string)), State: gitea_sdk.StateType(state),
Sort: req.Params.Arguments["sort"].(string), Sort: sort,
Milestone: req.Params.Arguments["milestone"].(int64), Milestone: int64(milestone),
ListOptions: gitea_sdk.ListOptions{ ListOptions: gitea_sdk.ListOptions{
Page: 1, Page: 1,
PageSize: 1000, PageSize: 1000,
@@ -92,12 +110,30 @@ func ListRepoPullRequestsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.
func CreatePullRequestFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func CreatePullRequestFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called CreatePullRequestFn") log.Debugf("Called CreatePullRequestFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
title := req.Params.Arguments["title"].(string) return nil, fmt.Errorf("owner is required")
body := req.Params.Arguments["body"].(string) }
head := req.Params.Arguments["head"].(string) repo, ok := req.Params.Arguments["repo"].(string)
base := req.Params.Arguments["base"].(string) if !ok {
return nil, fmt.Errorf("repo is required")
}
title, ok := req.Params.Arguments["title"].(string)
if !ok {
return nil, fmt.Errorf("title is required")
}
body, ok := req.Params.Arguments["body"].(string)
if !ok {
return nil, fmt.Errorf("body is required")
}
head, ok := req.Params.Arguments["head"].(string)
if !ok {
return nil, fmt.Errorf("head is required")
}
base, ok := req.Params.Arguments["base"].(string)
if !ok {
return nil, fmt.Errorf("base is required")
}
pr, _, err := gitea.Client().CreatePullRequest(owner, repo, gitea_sdk.CreatePullRequestOption{ pr, _, err := gitea.Client().CreatePullRequest(owner, repo, gitea_sdk.CreatePullRequestOption{
Title: title, Title: title,
Body: body, Body: body,

View File

@@ -22,34 +22,43 @@ var (
CreateBranchTool = mcp.NewTool( CreateBranchTool = mcp.NewTool(
CreateBranchToolName, CreateBranchToolName,
mcp.WithDescription("Create branch"), mcp.WithDescription("Create branch"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithString("branch", mcp.Required(), mcp.Description("Name of the branch to create"), mcp.DefaultString("")), mcp.WithString("branch", mcp.Required(), mcp.Description("Name of the branch to create")),
mcp.WithString("old_branch", mcp.Description("Name of the old branch to create from"), mcp.DefaultString("")), mcp.WithString("old_branch", mcp.Required(), mcp.Description("Name of the old branch to create from")),
) )
DeleteBranchTool = mcp.NewTool( DeleteBranchTool = mcp.NewTool(
DeleteBranchToolName, DeleteBranchToolName,
mcp.WithDescription("Delete branch"), mcp.WithDescription("Delete branch"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithString("branch", mcp.Required(), mcp.Description("Name of the branch to delete"), mcp.DefaultString("")), mcp.WithString("branch", mcp.Required(), mcp.Description("Name of the branch to delete")),
) )
ListBranchesTool = mcp.NewTool( ListBranchesTool = mcp.NewTool(
ListBranchesToolName, ListBranchesToolName,
mcp.WithDescription("List branches"), mcp.WithDescription("List branches"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
) )
) )
func CreateBranchFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func CreateBranchFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called CreateBranchFn") log.Debugf("Called CreateBranchFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
branch := req.Params.Arguments["branch"].(string) return nil, fmt.Errorf("owner is required")
oldBranch := req.Params.Arguments["old_branch"].(string) }
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
branch, ok := req.Params.Arguments["branch"].(string)
if !ok {
return nil, fmt.Errorf("branch is required")
}
oldBranch, _ := req.Params.Arguments["old_branch"].(string)
_, _, err := gitea.Client().CreateBranch(owner, repo, gitea_sdk.CreateBranchOption{ _, _, err := gitea.Client().CreateBranch(owner, repo, gitea_sdk.CreateBranchOption{
BranchName: branch, BranchName: branch,
@@ -64,9 +73,18 @@ func CreateBranchFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTool
func DeleteBranchFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func DeleteBranchFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called DeleteBranchFn") log.Debugf("Called DeleteBranchFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
branch := req.Params.Arguments["branch"].(string) return nil, fmt.Errorf("owner is required")
}
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
branch, ok := req.Params.Arguments["branch"].(string)
if !ok {
return nil, fmt.Errorf("branch is required")
}
_, _, err := gitea.Client().DeleteRepoBranch(owner, repo, branch) _, _, err := gitea.Client().DeleteRepoBranch(owner, repo, branch)
if err != nil { if err != nil {
return nil, fmt.Errorf("Delete Branch Error: %v", err) return nil, fmt.Errorf("Delete Branch Error: %v", err)
@@ -77,8 +95,14 @@ func DeleteBranchFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTool
func ListBranchesFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func ListBranchesFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called ListBranchesFn") log.Debugf("Called ListBranchesFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
return nil, fmt.Errorf("owner is required")
}
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
opt := gitea_sdk.ListRepoBranchesOptions{ opt := gitea_sdk.ListRepoBranchesOptions{
ListOptions: gitea_sdk.ListOptions{ ListOptions: gitea_sdk.ListOptions{
Page: 1, Page: 1,

View File

@@ -4,10 +4,11 @@ import (
"context" "context"
"fmt" "fmt"
gitea_sdk "code.gitea.io/sdk/gitea"
"gitea.com/gitea/gitea-mcp/pkg/gitea" "gitea.com/gitea/gitea-mcp/pkg/gitea"
"gitea.com/gitea/gitea-mcp/pkg/log" "gitea.com/gitea/gitea-mcp/pkg/log"
"gitea.com/gitea/gitea-mcp/pkg/to" "gitea.com/gitea/gitea-mcp/pkg/to"
gitea_sdk "code.gitea.io/sdk/gitea"
"github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/mcp"
) )
@@ -19,24 +20,32 @@ var (
ListRepoCommitsTool = mcp.NewTool( ListRepoCommitsTool = mcp.NewTool(
ListRepoCommitsToolName, ListRepoCommitsToolName,
mcp.WithDescription("List repository commits"), mcp.WithDescription("List repository commits"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithString("sha", mcp.Description("sha"), mcp.DefaultString("")), mcp.WithString("sha", mcp.Description("sha")),
mcp.WithString("path", mcp.Description("path"), mcp.DefaultString("")), mcp.WithString("path", mcp.Description("path")),
) )
) )
func ListRepoCommitsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func ListRepoCommitsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called ListRepoCommitsFn") log.Debugf("Called ListRepoCommitsFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
return nil, fmt.Errorf("owner is required")
}
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
sha, _ := req.Params.Arguments["sha"].(string)
path, _ := req.Params.Arguments["path"].(string)
opt := gitea_sdk.ListCommitOptions{ opt := gitea_sdk.ListCommitOptions{
ListOptions: gitea_sdk.ListOptions{ ListOptions: gitea_sdk.ListOptions{
Page: 1, Page: 1,
PageSize: 1000, PageSize: 1000,
}, },
SHA: req.Params.Arguments["sha"].(string), SHA: sha,
Path: req.Params.Arguments["path"].(string), Path: path,
} }
commits, _, err := gitea.Client().ListRepoCommits(owner, repo, opt) commits, _, err := gitea.Client().ListRepoCommits(owner, repo, opt)
if err != nil { if err != nil {

View File

@@ -23,56 +23,62 @@ var (
GetFileTool = mcp.NewTool( GetFileTool = mcp.NewTool(
GetFileToolName, GetFileToolName,
mcp.WithDescription("Get file"), mcp.WithDescription("Get file"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithString("ref", mcp.Required(), mcp.Description("ref"), mcp.DefaultString("")), mcp.WithString("ref", mcp.Required(), mcp.Description("ref")),
mcp.WithString("filePath", mcp.Required(), mcp.Description("file path"), mcp.DefaultString("")), mcp.WithString("filePath", mcp.Required(), mcp.Description("file path")),
) )
CreateFileTool = mcp.NewTool( CreateFileTool = mcp.NewTool(
CreateFileToolName, CreateFileToolName,
mcp.WithDescription("Create file"), mcp.WithDescription("Create file"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithString("filePath", mcp.Required(), mcp.Description("file path"), mcp.DefaultString("")), mcp.WithString("filePath", mcp.Required(), mcp.Description("file path")),
mcp.WithString("content", mcp.Required(), mcp.Description("file content"), mcp.DefaultString("")), mcp.WithString("content", mcp.Required(), mcp.Description("file content")),
mcp.WithString("message", mcp.Required(), mcp.Description("commit message"), mcp.DefaultString("")), mcp.WithString("message", mcp.Required(), mcp.Description("commit message")),
mcp.WithString("branch_name", mcp.Required(), mcp.Description("branch name"), mcp.DefaultString("")), mcp.WithString("branch_name", mcp.Required(), mcp.Description("branch name")),
mcp.WithString("new_branch_name", mcp.Description("new branch name"), mcp.DefaultString("")), mcp.WithString("new_branch_name", mcp.Description("new branch name")),
) )
UpdateFileTool = mcp.NewTool( UpdateFileTool = mcp.NewTool(
UpdateFileToolName, UpdateFileToolName,
mcp.WithDescription("Update file"), mcp.WithDescription("Update file"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithString("filePath", mcp.Required(), mcp.Description("file path"), mcp.DefaultString("")), mcp.WithString("filePath", mcp.Required(), mcp.Description("file path")),
mcp.WithString("content", mcp.Required(), mcp.Description("file content"), mcp.DefaultString("")), mcp.WithString("content", mcp.Required(), mcp.Description("file content")),
mcp.WithString("message", mcp.Required(), mcp.Description("commit message"), mcp.DefaultString("")), mcp.WithString("message", mcp.Required(), mcp.Description("commit message")),
mcp.WithString("branch_name", mcp.Required(), mcp.Description("branch name"), mcp.DefaultString("")), mcp.WithString("branch_name", mcp.Required(), mcp.Description("branch name")),
mcp.WithString("new_branch_name", mcp.Description("new branch name"), mcp.DefaultString("")),
mcp.WithString("from_path", mcp.Description("from path"), mcp.DefaultString("")),
mcp.WithString("sha", mcp.Description("sha"), mcp.DefaultString("")),
) )
DeleteFileTool = mcp.NewTool( DeleteFileTool = mcp.NewTool(
DeleteFileToolName, DeleteFileToolName,
mcp.WithDescription("Delete file"), mcp.WithDescription("Delete file"),
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")), mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")), mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
mcp.WithString("filePath", mcp.Required(), mcp.Description("file path"), mcp.DefaultString("")), mcp.WithString("filePath", mcp.Required(), mcp.Description("file path")),
mcp.WithString("message", mcp.Required(), mcp.Description("commit message"), mcp.DefaultString("")), mcp.WithString("message", mcp.Required(), mcp.Description("commit message")),
mcp.WithString("branch_name", mcp.Required(), mcp.Description("branch name"), mcp.DefaultString("")), mcp.WithString("branch_name", mcp.Required(), mcp.Description("branch name")),
mcp.WithString("sha", mcp.Description("sha"), mcp.DefaultString("")), mcp.WithString("sha", mcp.Description("sha")),
) )
) )
func GetFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func GetFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called GetFileFn") log.Debugf("Called GetFileFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
ref := req.Params.Arguments["ref"].(string) return nil, fmt.Errorf("owner is required")
filePath := req.Params.Arguments["filePath"].(string) }
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
ref, _ := req.Params.Arguments["ref"].(string)
filePath, ok := req.Params.Arguments["filePath"].(string)
if !ok {
return nil, fmt.Errorf("filePath is required")
}
file, _, err := gitea.Client().GetFile(owner, repo, ref, filePath) file, _, err := gitea.Client().GetFile(owner, repo, ref, filePath)
if err != nil { if err != nil {
return nil, fmt.Errorf("get file err: %v", err) return nil, fmt.Errorf("get file err: %v", err)
@@ -82,15 +88,26 @@ func GetFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResul
func CreateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func CreateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called CreateFileFn") log.Debugf("Called CreateFileFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
filePath := req.Params.Arguments["filePath"].(string) return nil, fmt.Errorf("owner is required")
}
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
filePath, ok := req.Params.Arguments["filePath"].(string)
if !ok {
return nil, fmt.Errorf("filePath is required")
}
content, _ := req.Params.Arguments["content"].(string)
message, _ := req.Params.Arguments["message"].(string)
branchName, _ := req.Params.Arguments["branch_name"].(string)
opt := gitea_sdk.CreateFileOptions{ opt := gitea_sdk.CreateFileOptions{
Content: req.Params.Arguments["content"].(string), Content: content,
FileOptions: gitea_sdk.FileOptions{ FileOptions: gitea_sdk.FileOptions{
Message: req.Params.Arguments["message"].(string), Message: message,
BranchName: req.Params.Arguments["branch_name"].(string), BranchName: branchName,
NewBranchName: req.Params.Arguments["new_branch_name"].(string),
}, },
} }
@@ -103,17 +120,26 @@ func CreateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe
func UpdateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func UpdateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called UpdateFileFn") log.Debugf("Called UpdateFileFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
filePath := req.Params.Arguments["filePath"].(string) return nil, fmt.Errorf("owner is required")
}
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
filePath, ok := req.Params.Arguments["filePath"].(string)
if !ok {
return nil, fmt.Errorf("filePath is required")
}
content, _ := req.Params.Arguments["content"].(string)
message, _ := req.Params.Arguments["message"].(string)
branchName, _ := req.Params.Arguments["branch_name"].(string)
opt := gitea_sdk.UpdateFileOptions{ opt := gitea_sdk.UpdateFileOptions{
Content: req.Params.Arguments["content"].(string), Content: content,
FromPath: req.Params.Arguments["from_path"].(string),
SHA: req.Params.Arguments["sha"].(string),
FileOptions: gitea_sdk.FileOptions{ FileOptions: gitea_sdk.FileOptions{
Message: req.Params.Arguments["message"].(string), Message: message,
BranchName: req.Params.Arguments["branch_name"].(string), BranchName: branchName,
NewBranchName: req.Params.Arguments["new_branch_name"].(string),
}, },
} }
_, _, err := gitea.Client().UpdateFile(owner, repo, filePath, opt) _, _, err := gitea.Client().UpdateFile(owner, repo, filePath, opt)
@@ -125,15 +151,25 @@ func UpdateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe
func DeleteFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func DeleteFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called DeleteFileFn") log.Debugf("Called DeleteFileFn")
owner := req.Params.Arguments["owner"].(string) owner, ok := req.Params.Arguments["owner"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
filePath := req.Params.Arguments["filePath"].(string) return nil, fmt.Errorf("owner is required")
}
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, fmt.Errorf("repo is required")
}
filePath, ok := req.Params.Arguments["filePath"].(string)
if !ok {
return nil, fmt.Errorf("filePath is required")
}
message, _ := req.Params.Arguments["message"].(string)
branchName, _ := req.Params.Arguments["branch_name"].(string)
opt := gitea_sdk.DeleteFileOptions{ opt := gitea_sdk.DeleteFileOptions{
FileOptions: gitea_sdk.FileOptions{ FileOptions: gitea_sdk.FileOptions{
Message: req.Params.Arguments["message"].(string), Message: message,
BranchName: req.Params.Arguments["branch_name"].(string), BranchName: branchName,
}, },
SHA: req.Params.Arguments["sha"].(string),
} }
_, err := gitea.Client().DeleteFile(owner, repo, filePath, opt) _, err := gitea.Client().DeleteFile(owner, repo, filePath, opt)
if err != nil { if err != nil {

View File

@@ -25,16 +25,16 @@ var (
CreateRepoTool = mcp.NewTool( CreateRepoTool = mcp.NewTool(
CreateRepoToolName, CreateRepoToolName,
mcp.WithDescription("Create repository"), mcp.WithDescription("Create repository"),
mcp.WithString("name", mcp.Required(), mcp.Description("Name of the repository to create"), mcp.DefaultString("test")), mcp.WithString("name", mcp.Required(), mcp.Description("Name of the repository to create")),
mcp.WithString("description", mcp.Description("Description of the repository to create"), mcp.DefaultString("")), mcp.WithString("description", mcp.Description("Description of the repository to create")),
mcp.WithBoolean("private", mcp.Description("Whether the repository is private"), mcp.DefaultBool(true)), mcp.WithBoolean("private", mcp.Description("Whether the repository is private")),
mcp.WithString("issue_labels", mcp.Description("Issue Label set to use"), mcp.DefaultString("")), mcp.WithString("issue_labels", mcp.Description("Issue Label set to use")),
mcp.WithBoolean("auto_init", mcp.Description("Whether the repository should be auto-intialized?"), mcp.DefaultBool(false)), mcp.WithBoolean("auto_init", mcp.Description("Whether the repository should be auto-intialized?")),
mcp.WithBoolean("template", mcp.Description("Whether the repository is template"), mcp.DefaultBool(false)), mcp.WithBoolean("template", mcp.Description("Whether the repository is template")),
mcp.WithString("gitignores", mcp.Description("Gitignores to use"), mcp.DefaultString("")), mcp.WithString("gitignores", mcp.Description("Gitignores to use")),
mcp.WithString("license", mcp.Description("License to use"), mcp.DefaultString("MIT")), mcp.WithString("license", mcp.Description("License to use")),
mcp.WithString("readme", mcp.Description("Readme of the repository to create"), mcp.DefaultString("")), mcp.WithString("readme", mcp.Description("Readme of the repository to create")),
mcp.WithString("default_branch", mcp.Description("DefaultBranch of the repository (used when initializes and in template)"), mcp.DefaultString("main")), mcp.WithString("default_branch", mcp.Description("DefaultBranch of the repository (used when initializes and in template)")),
) )
ForkRepoTool = mcp.NewTool( ForkRepoTool = mcp.NewTool(
@@ -50,7 +50,7 @@ var (
ListMyReposToolName, ListMyReposToolName,
mcp.WithDescription("List my repositories"), mcp.WithDescription("List my repositories"),
mcp.WithNumber("page", mcp.Required(), mcp.Description("Page number"), mcp.DefaultNumber(1), mcp.Min(1)), mcp.WithNumber("page", mcp.Required(), mcp.Description("Page number"), mcp.DefaultNumber(1), mcp.Min(1)),
mcp.WithNumber("pageSize", mcp.Required(), mcp.Description("Page size number"), mcp.DefaultNumber(10), mcp.Min(1)), mcp.WithNumber("pageSize", mcp.Required(), mcp.Description("Page size number"), mcp.DefaultNumber(100), mcp.Min(1)),
) )
) )
@@ -76,16 +76,19 @@ func RegisterTool(s *server.MCPServer) {
func CreateRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func CreateRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called CreateRepoFn") log.Debugf("Called CreateRepoFn")
name := req.Params.Arguments["name"].(string) name, ok := req.Params.Arguments["name"].(string)
description := req.Params.Arguments["description"].(string) if !ok {
private := req.Params.Arguments["private"].(bool) return nil, errors.New("repository name is required")
issueLabels := req.Params.Arguments["issue_labels"].(string) }
autoInit := req.Params.Arguments["auto_init"].(bool) description, _ := req.Params.Arguments["description"].(string)
template := req.Params.Arguments["template"].(bool) private, _ := req.Params.Arguments["private"].(bool)
gitignores := req.Params.Arguments["gitignores"].(string) issueLabels, _ := req.Params.Arguments["issue_labels"].(string)
license := req.Params.Arguments["license"].(string) autoInit, _ := req.Params.Arguments["auto_init"].(bool)
readme := req.Params.Arguments["readme"].(string) template, _ := req.Params.Arguments["template"].(bool)
defaultBranch := req.Params.Arguments["default_branch"].(string) gitignores, _ := req.Params.Arguments["gitignores"].(string)
license, _ := req.Params.Arguments["license"].(string)
readme, _ := req.Params.Arguments["readme"].(string)
defaultBranch, _ := req.Params.Arguments["default_branch"].(string)
opt := gitea_sdk.CreateRepoOption{ opt := gitea_sdk.CreateRepoOption{
Name: name, Name: name,
@@ -108,11 +111,19 @@ func CreateRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe
func ForkRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func ForkRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called ForkRepoFn") log.Debugf("Called ForkRepoFn")
user := req.Params.Arguments["user"].(string) user, ok := req.Params.Arguments["user"].(string)
repo := req.Params.Arguments["repo"].(string) if !ok {
return nil, errors.New("user name is required")
}
repo, ok := req.Params.Arguments["repo"].(string)
if !ok {
return nil, errors.New("repository name is required")
}
organization, _ := req.Params.Arguments["organization"].(string)
name, _ := req.Params.Arguments["name"].(string)
opt := gitea_sdk.CreateForkOption{ opt := gitea_sdk.CreateForkOption{
Organization: ptr.To(req.Params.Arguments["organization"].(string)), Organization: ptr.To(organization),
Name: ptr.To(req.Params.Arguments["name"].(string)), Name: ptr.To(name),
} }
_, _, err := gitea.Client().CreateFork(user, repo, opt) _, _, err := gitea.Client().CreateFork(user, repo, opt)
if err != nil { if err != nil {

View File

@@ -24,7 +24,7 @@ var (
SearchUsersTool = mcp.NewTool( SearchUsersTool = mcp.NewTool(
SearchUsersToolName, SearchUsersToolName,
mcp.WithDescription("search users"), mcp.WithDescription("search users"),
mcp.WithString("keyword", mcp.Description("Keyword"), mcp.DefaultString("")), mcp.WithString("keyword", mcp.Description("Keyword")),
mcp.WithNumber("page", mcp.Description("Page"), mcp.DefaultNumber(1)), mcp.WithNumber("page", mcp.Description("Page"), mcp.DefaultNumber(1)),
mcp.WithNumber("pageSize", mcp.Description("PageSize"), mcp.DefaultNumber(100)), mcp.WithNumber("pageSize", mcp.Description("PageSize"), mcp.DefaultNumber(100)),
) )
@@ -32,9 +32,9 @@ var (
SearOrgTeamsTool = mcp.NewTool( SearOrgTeamsTool = mcp.NewTool(
SearchOrgTeamsToolName, SearchOrgTeamsToolName,
mcp.WithDescription("search organization teams"), mcp.WithDescription("search organization teams"),
mcp.WithString("org", mcp.Description("organization name"), mcp.DefaultString("")), mcp.WithString("org", mcp.Description("organization name")),
mcp.WithString("query", mcp.Description("search organization teams"), mcp.DefaultString("")), mcp.WithString("query", mcp.Description("search organization teams")),
mcp.WithBoolean("includeDescription", mcp.Description("include description?"), mcp.DefaultBool(true)), mcp.WithBoolean("includeDescription", mcp.Description("include description?")),
mcp.WithNumber("page", mcp.Description("Page"), mcp.DefaultNumber(1)), mcp.WithNumber("page", mcp.Description("Page"), mcp.DefaultNumber(1)),
mcp.WithNumber("pageSize", mcp.Description("PageSize"), mcp.DefaultNumber(100)), mcp.WithNumber("pageSize", mcp.Description("PageSize"), mcp.DefaultNumber(100)),
) )
@@ -42,14 +42,14 @@ var (
SearchReposTool = mcp.NewTool( SearchReposTool = mcp.NewTool(
SearchReposToolName, SearchReposToolName,
mcp.WithDescription("search repos"), mcp.WithDescription("search repos"),
mcp.WithString("keyword", mcp.Description("Keyword"), mcp.DefaultString("")), mcp.WithString("keyword", mcp.Description("Keyword")),
mcp.WithBoolean("keywordIsTopic", mcp.Description("KeywordIsTopic"), mcp.DefaultBool(false)), mcp.WithBoolean("keywordIsTopic", mcp.Description("KeywordIsTopic")),
mcp.WithBoolean("keywordInDescription", mcp.Description("KeywordInDescription"), mcp.DefaultBool(false)), mcp.WithBoolean("keywordInDescription", mcp.Description("KeywordInDescription")),
mcp.WithNumber("ownerID", mcp.Description("OwnerID"), mcp.DefaultNumber(0)), mcp.WithNumber("ownerID", mcp.Description("OwnerID")),
mcp.WithBoolean("isPrivate", mcp.Description("IsPrivate"), mcp.DefaultBool(false)), mcp.WithBoolean("isPrivate", mcp.Description("IsPrivate")),
mcp.WithBoolean("isArchived", mcp.Description("IsArchived"), mcp.DefaultBool(false)), mcp.WithBoolean("isArchived", mcp.Description("IsArchived")),
mcp.WithString("sort", mcp.Description("Sort"), mcp.DefaultString(""), mcp.Enum("")), mcp.WithString("sort", mcp.Description("Sort")),
mcp.WithString("order", mcp.Description("Order"), mcp.DefaultString(""), mcp.Enum("")), mcp.WithString("order", mcp.Description("Order")),
mcp.WithNumber("page", mcp.Description("Page"), mcp.DefaultNumber(1)), mcp.WithNumber("page", mcp.Description("Page"), mcp.DefaultNumber(1)),
mcp.WithNumber("pageSize", mcp.Description("PageSize"), mcp.DefaultNumber(100)), mcp.WithNumber("pageSize", mcp.Description("PageSize"), mcp.DefaultNumber(100)),
) )
@@ -63,11 +63,23 @@ func RegisterTool(s *server.MCPServer) {
func SearchUsersFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func SearchUsersFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called SearchUsersFn") log.Debugf("Called SearchUsersFn")
keyword, ok := req.Params.Arguments["keyword"].(string)
if !ok {
return nil, fmt.Errorf("keyword is required")
}
page, ok := req.Params.Arguments["page"].(float64)
if !ok {
page = 1
}
pageSize, ok := req.Params.Arguments["pageSize"].(float64)
if !ok {
pageSize = 100
}
opt := gitea_sdk.SearchUsersOption{ opt := gitea_sdk.SearchUsersOption{
KeyWord: req.Params.Arguments["keyword"].(string), KeyWord: keyword,
ListOptions: gitea_sdk.ListOptions{ ListOptions: gitea_sdk.ListOptions{
Page: req.Params.Arguments["page"].(int), Page: int(page),
PageSize: req.Params.Arguments["pageSize"].(int), PageSize: int(pageSize),
}, },
} }
users, _, err := gitea.Client().SearchUsers(opt) users, _, err := gitea.Client().SearchUsers(opt)
@@ -79,13 +91,29 @@ func SearchUsersFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolR
func SearchOrgTeamsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func SearchOrgTeamsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called SearchOrgTeamsFn") log.Debugf("Called SearchOrgTeamsFn")
org := req.Params.Arguments["org"].(string) org, ok := req.Params.Arguments["org"].(string)
if !ok {
return nil, fmt.Errorf("organization is required")
}
query, ok := req.Params.Arguments["query"].(string)
if !ok {
return nil, fmt.Errorf("query is required")
}
includeDescription, _ := req.Params.Arguments["includeDescription"].(bool)
page, ok := req.Params.Arguments["page"].(float64)
if !ok {
page = 1
}
pageSize, ok := req.Params.Arguments["pageSize"].(float64)
if !ok {
pageSize = 100
}
opt := gitea_sdk.SearchTeamsOptions{ opt := gitea_sdk.SearchTeamsOptions{
Query: req.Params.Arguments["query"].(string), Query: query,
IncludeDescription: req.Params.Arguments["includeDescription"].(bool), IncludeDescription: includeDescription,
ListOptions: gitea_sdk.ListOptions{ ListOptions: gitea_sdk.ListOptions{
Page: req.Params.Arguments["page"].(int), Page: int(page),
PageSize: req.Params.Arguments["pageSize"].(int), PageSize: int(pageSize),
}, },
} }
teams, _, err := gitea.Client().SearchOrgTeams(org, &opt) teams, _, err := gitea.Client().SearchOrgTeams(org, &opt)
@@ -97,18 +125,37 @@ func SearchOrgTeamsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTo
func SearchReposFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { func SearchReposFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
log.Debugf("Called SearchReposFn") log.Debugf("Called SearchReposFn")
keyword, ok := req.Params.Arguments["keyword"].(string)
if !ok {
return nil, fmt.Errorf("keyword is required")
}
keywordIsTopic, _ := req.Params.Arguments["keywordIsTopic"].(bool)
keywordInDescription, _ := req.Params.Arguments["keywordInDescription"].(bool)
ownerID, _ := req.Params.Arguments["ownerID"].(float64)
isPrivate, _ := req.Params.Arguments["isPrivate"].(bool)
isArchived, _ := req.Params.Arguments["isArchived"].(bool)
sort, _ := req.Params.Arguments["sort"].(string)
order, _ := req.Params.Arguments["order"].(string)
page, ok := req.Params.Arguments["page"].(float64)
if !ok {
page = 1
}
pageSize, ok := req.Params.Arguments["pageSize"].(float64)
if !ok {
pageSize = 100
}
opt := gitea_sdk.SearchRepoOptions{ opt := gitea_sdk.SearchRepoOptions{
Keyword: req.Params.Arguments["keyword"].(string), Keyword: keyword,
KeywordIsTopic: req.Params.Arguments["keywordIsTopic"].(bool), KeywordIsTopic: keywordIsTopic,
KeywordInDescription: req.Params.Arguments["keywordInDescription"].(bool), KeywordInDescription: keywordInDescription,
OwnerID: req.Params.Arguments["ownerID"].(int64), OwnerID: int64(ownerID),
IsPrivate: ptr.To(req.Params.Arguments["isPrivate"].(bool)), IsPrivate: ptr.To(isPrivate),
IsArchived: ptr.To(req.Params.Arguments["isArchived"].(bool)), IsArchived: ptr.To(isArchived),
Sort: req.Params.Arguments["sort"].(string), Sort: sort,
Order: req.Params.Arguments["order"].(string), Order: order,
ListOptions: gitea_sdk.ListOptions{ ListOptions: gitea_sdk.ListOptions{
Page: req.Params.Arguments["page"].(int), Page: int(page),
PageSize: req.Params.Arguments["pageSize"].(int), PageSize: int(pageSize),
}, },
} }
repos, _, err := gitea.Client().SearchRepos(opt) repos, _, err := gitea.Client().SearchRepos(opt)