mirror of
				https://gitea.com/gitea/gitea-mcp.git
				synced 2025-10-30 01:41:50 +00:00 
			
		
		
		
	| @@ -33,9 +33,11 @@ var ( | |||||||
| 		mcp.WithDescription("List repository pull requests"), | 		mcp.WithDescription("List repository pull requests"), | ||||||
| 		mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")), | 		mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")), | ||||||
| 		mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")), | 		mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")), | ||||||
| 		mcp.WithString("state", mcp.Description("state")), | 		mcp.WithString("state", mcp.Description("state"), mcp.Enum("open", "closed", "all"), mcp.DefaultString("all")), | ||||||
| 		mcp.WithString("sort", mcp.Description("sort")), | 		mcp.WithString("sort", mcp.Description("sort"), mcp.Enum("oldest", "recentupdate", "leastupdate", "mostcomment", "leastcomment", "priority"), mcp.DefaultString("recentupdate")), | ||||||
| 		mcp.WithNumber("milestone", mcp.Description("milestone")), | 		mcp.WithNumber("milestone", mcp.Description("milestone")), | ||||||
|  | 		mcp.WithNumber("page", mcp.Description("page number"), mcp.DefaultNumber(1)), | ||||||
|  | 		mcp.WithNumber("pageSize", mcp.Description("page size"), mcp.DefaultNumber(100)), | ||||||
| 	) | 	) | ||||||
|  |  | ||||||
| 	CreatePullRequestTool = mcp.NewTool( | 	CreatePullRequestTool = mcp.NewTool( | ||||||
| @@ -89,18 +91,29 @@ func ListRepoPullRequestsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp. | |||||||
| 		return to.ErrorResult(fmt.Errorf("repo is required")) | 		return to.ErrorResult(fmt.Errorf("repo is required")) | ||||||
| 	} | 	} | ||||||
| 	state, _ := req.Params.Arguments["state"].(string) | 	state, _ := req.Params.Arguments["state"].(string) | ||||||
| 	sort, _ := req.Params.Arguments["sort"].(string) | 	sort, ok := req.Params.Arguments["sort"].(string) | ||||||
|  | 	if !ok { | ||||||
|  | 		sort = "recentupdate" | ||||||
|  | 	} | ||||||
| 	milestone, _ := req.Params.Arguments["milestone"].(float64) | 	milestone, _ := req.Params.Arguments["milestone"].(float64) | ||||||
|  | 	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.ListPullRequestsOptions{ | 	opt := gitea_sdk.ListPullRequestsOptions{ | ||||||
| 		State:     gitea_sdk.StateType(state), | 		State:     gitea_sdk.StateType(state), | ||||||
| 		Sort:      sort, | 		Sort:      sort, | ||||||
| 		Milestone: int64(milestone), | 		Milestone: int64(milestone), | ||||||
| 		ListOptions: gitea_sdk.ListOptions{ | 		ListOptions: gitea_sdk.ListOptions{ | ||||||
| 			Page:     1, | 			Page:     int(page), | ||||||
| 			PageSize: 1000, | 			PageSize: int(pageSize), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	pullRequests, _, err := gitea.Client().ListRepoPullRequests("", "", opt) | 	pullRequests, _, err := gitea.Client().ListRepoPullRequests(owner, repo, opt) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return to.ErrorResult(fmt.Errorf("list %v/%v/pull_requests err: %v", owner, repo, err)) | 		return to.ErrorResult(fmt.Errorf("list %v/%v/pull_requests err: %v", owner, repo, err)) | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ package repo | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"encoding/base64" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
| 	"gitea.com/gitea/gitea-mcp/pkg/gitea" | 	"gitea.com/gitea/gitea-mcp/pkg/gitea" | ||||||
| @@ -105,7 +106,7 @@ func CreateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe | |||||||
| 	message, _ := req.Params.Arguments["message"].(string) | 	message, _ := req.Params.Arguments["message"].(string) | ||||||
| 	branchName, _ := req.Params.Arguments["branch_name"].(string) | 	branchName, _ := req.Params.Arguments["branch_name"].(string) | ||||||
| 	opt := gitea_sdk.CreateFileOptions{ | 	opt := gitea_sdk.CreateFileOptions{ | ||||||
| 		Content: content, | 		Content: base64.StdEncoding.EncodeToString([]byte(content)), | ||||||
| 		FileOptions: gitea_sdk.FileOptions{ | 		FileOptions: gitea_sdk.FileOptions{ | ||||||
| 			Message:    message, | 			Message:    message, | ||||||
| 			BranchName: branchName, | 			BranchName: branchName, | ||||||
| @@ -172,11 +173,16 @@ func DeleteFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe | |||||||
| 	} | 	} | ||||||
| 	message, _ := req.Params.Arguments["message"].(string) | 	message, _ := req.Params.Arguments["message"].(string) | ||||||
| 	branchName, _ := req.Params.Arguments["branch_name"].(string) | 	branchName, _ := req.Params.Arguments["branch_name"].(string) | ||||||
|  | 	sha, ok := req.Params.Arguments["sha"].(string) | ||||||
|  | 	if !ok { | ||||||
|  | 		return to.ErrorResult(fmt.Errorf("sha is required")) | ||||||
|  | 	} | ||||||
| 	opt := gitea_sdk.DeleteFileOptions{ | 	opt := gitea_sdk.DeleteFileOptions{ | ||||||
| 		FileOptions: gitea_sdk.FileOptions{ | 		FileOptions: gitea_sdk.FileOptions{ | ||||||
| 			Message:    message, | 			Message:    message, | ||||||
| 			BranchName: branchName, | 			BranchName: branchName, | ||||||
| 		}, | 		}, | ||||||
|  | 		SHA: sha, | ||||||
| 	} | 	} | ||||||
| 	_, err := gitea.Client().DeleteFile(owner, repo, filePath, opt) | 	_, err := gitea.Client().DeleteFile(owner, repo, filePath, opt) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user