mirror of
				https://gitea.com/gitea/gitea-mcp.git
				synced 2025-11-03 20:01:50 +00:00 
			
		
		
		
	Add edit issue comment and list issue comments tools (#48)
- Add tools: - `edit_issue_comment` for edit issue comments - `get_issue_comments_by_index` for getting issue's comment by its index Co-authored-by: hiifong <i@hiif.ong> Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/48 Co-authored-by: natchanonnn <natchanon.w@loolootech.com> Co-committed-by: natchanonnn <natchanon.w@loolootech.com>
This commit is contained in:
		@@ -203,6 +203,8 @@ The Gitea MCP Server supports the following tools:
 | 
			
		||||
|         create_issue         |    Issue     |                    Create a new issue                    |
 | 
			
		||||
|     create_issue_comment     |    Issue     |               Create a comment on an issue               |
 | 
			
		||||
|          edit_issue          |    Issue     |                       Edit a issue                       |
 | 
			
		||||
|      edit_issue_comment      |    Issue     |                Edit a comment on an issue                |
 | 
			
		||||
| get_issue_comments_by_index  |    Issue     |          Get comments of an issue by its index           |
 | 
			
		||||
|  get_pull_request_by_index   | Pull Request |             Get a pull request by its index              |
 | 
			
		||||
|   list_repo_pull_requests    | Pull Request |          List all pull requests in a repository          |
 | 
			
		||||
|     create_pull_request      | Pull Request |                Create a new pull request                 |
 | 
			
		||||
 
 | 
			
		||||
@@ -203,6 +203,8 @@ Gitea MCP 服务器支持以下工具:
 | 
			
		||||
|         create_issue         |   问题   |        创建一个新问题        |
 | 
			
		||||
|     create_issue_comment     |   问题   |       在问题上创建评论       |
 | 
			
		||||
|          edit_issue          |   问题   |         编辑一个问题         |
 | 
			
		||||
|      edit_issue_comment      |   问题   |      在问题上编辑评论         |
 | 
			
		||||
| get_issue_comments_by_index  |   问题   |     根据索引获取问题的评论     |
 | 
			
		||||
|  get_pull_request_by_index   | 拉取请求 |     根据索引获取拉取请求     |
 | 
			
		||||
|   list_repo_pull_requests    | 拉取请求 |   列出仓库中的所有拉取请求   |
 | 
			
		||||
|     create_pull_request      | 拉取请求 |      创建一个新拉取请求      |
 | 
			
		||||
 
 | 
			
		||||
@@ -203,6 +203,8 @@ Gitea MCP 伺服器支持以下工具:
 | 
			
		||||
|         create_issue         |   問題   |        創建一個新問題        |
 | 
			
		||||
|     create_issue_comment     |   問題   |       在問題上創建評論       |
 | 
			
		||||
|          edit_issue          |   問題   |         編輯一個問題         |
 | 
			
		||||
|      edit_issue_comment      |   問題   |      在問題上編輯評論         |
 | 
			
		||||
| get_issue_comments_by_index  |   问题   |     根據索引獲取問題的評論     |
 | 
			
		||||
|  get_pull_request_by_index   | 拉取請求 |     根據索引獲取拉取請求     |
 | 
			
		||||
|   list_repo_pull_requests    | 拉取請求 |   列出倉庫中的所有拉取請求   |
 | 
			
		||||
|     create_pull_request      | 拉取請求 |      創建一個新拉取請求      |
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,9 @@ const (
 | 
			
		||||
	CreateIssueToolName        = "create_issue"
 | 
			
		||||
	CreateIssueCommentToolName = "create_issue_comment"
 | 
			
		||||
	EditIssueToolName          = "edit_issue"
 | 
			
		||||
	EditIssueCommentToolName   = "edit_issue_comment"
 | 
			
		||||
	GetIssueCommentsByIndexToolName    = "get_issue_comments_by_index"
 | 
			
		||||
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
@@ -52,6 +55,7 @@ var (
 | 
			
		||||
		mcp.WithString("title", mcp.Required(), mcp.Description("issue title")),
 | 
			
		||||
		mcp.WithString("body", mcp.Required(), mcp.Description("issue body")),
 | 
			
		||||
	)
 | 
			
		||||
	
 | 
			
		||||
	CreateIssueCommentTool = mcp.NewTool(
 | 
			
		||||
		CreateIssueCommentToolName,
 | 
			
		||||
		mcp.WithDescription("create issue comment"),
 | 
			
		||||
@@ -60,6 +64,7 @@ var (
 | 
			
		||||
		mcp.WithNumber("index", mcp.Required(), mcp.Description("repository issue index")),
 | 
			
		||||
		mcp.WithString("body", mcp.Required(), mcp.Description("issue comment body")),
 | 
			
		||||
	)
 | 
			
		||||
	
 | 
			
		||||
	EditIssueTool = mcp.NewTool(
 | 
			
		||||
		EditIssueToolName,
 | 
			
		||||
		mcp.WithDescription("edit issue"),
 | 
			
		||||
@@ -72,6 +77,23 @@ var (
 | 
			
		||||
		mcp.WithNumber("milestone", mcp.Description("milestone number")),
 | 
			
		||||
		mcp.WithString("state", mcp.Description("issue state, one of open, closed, all")),
 | 
			
		||||
	)
 | 
			
		||||
	
 | 
			
		||||
	EditIssueCommentTool = mcp.NewTool(
 | 
			
		||||
		EditIssueCommentToolName,
 | 
			
		||||
		mcp.WithDescription("edit issue comment"),
 | 
			
		||||
		mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
 | 
			
		||||
		mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
 | 
			
		||||
		mcp.WithNumber("commentID", mcp.Required(), mcp.Description("id of issue comment")),
 | 
			
		||||
		mcp.WithString("body", mcp.Required(), mcp.Description("issue comment body")),
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	GetIssueCommentsByIndexTool = mcp.NewTool(
 | 
			
		||||
		GetIssueCommentsByIndexToolName,
 | 
			
		||||
		mcp.WithDescription("get issue comment by index"),
 | 
			
		||||
		mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
 | 
			
		||||
		mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
 | 
			
		||||
		mcp.WithNumber("index", mcp.Required(), mcp.Description("repository issue index")),
 | 
			
		||||
	)
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
@@ -95,6 +117,14 @@ func init() {
 | 
			
		||||
		Tool:    EditIssueTool,
 | 
			
		||||
		Handler: EditIssueFn,
 | 
			
		||||
	})
 | 
			
		||||
	Tool.RegisterWrite(server.ServerTool{
 | 
			
		||||
		Tool: 	 EditIssueCommentTool,
 | 
			
		||||
		Handler: EditIssueCommentFn,
 | 
			
		||||
	})
 | 
			
		||||
	Tool.RegisterRead(server.ServerTool{
 | 
			
		||||
		Tool: 	 GetIssueCommentsByIndexTool,
 | 
			
		||||
		Handler: GetIssueCommentsByIndexFn,
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetIssueByIndexFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
 | 
			
		||||
@@ -258,3 +288,57 @@ func EditIssueFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRes
 | 
			
		||||
 | 
			
		||||
	return to.TextResult(issue)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func EditIssueCommentFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
 | 
			
		||||
	log.Debugf("Called EditIssueCommentFn")
 | 
			
		||||
	owner, ok := req.GetArguments()["owner"].(string)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return to.ErrorResult(fmt.Errorf("owner is required"))
 | 
			
		||||
	}
 | 
			
		||||
	repo, ok := req.GetArguments()["repo"].(string)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return to.ErrorResult(fmt.Errorf("repo is required"))
 | 
			
		||||
	}
 | 
			
		||||
	commentID, ok := req.GetArguments()["commentID"].(float64)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return to.ErrorResult(fmt.Errorf("comment ID is required"))
 | 
			
		||||
	}
 | 
			
		||||
	body, ok := req.GetArguments()["body"].(string)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return to.ErrorResult(fmt.Errorf("body is required"))
 | 
			
		||||
	}
 | 
			
		||||
	opt := gitea_sdk.EditIssueCommentOption{
 | 
			
		||||
		Body: body,
 | 
			
		||||
	}
 | 
			
		||||
	issueComment, _, err := gitea.Client().EditIssueComment(owner, repo, int64(commentID), opt)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return to.ErrorResult(fmt.Errorf("edit %v/%v/issues/comments/%v err: %v", owner, repo, int64(commentID), err))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return to.TextResult(issueComment)
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetIssueCommentsByIndexFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
 | 
			
		||||
	log.Debugf("Called GetIssueCommentsByIndexFn")
 | 
			
		||||
	owner, ok := req.GetArguments()["owner"].(string)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return to.ErrorResult(fmt.Errorf("owner is required"))
 | 
			
		||||
	}
 | 
			
		||||
	repo, ok := req.GetArguments()["repo"].(string)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return to.ErrorResult(fmt.Errorf("repo is required"))
 | 
			
		||||
	}
 | 
			
		||||
	index, ok := req.GetArguments()["index"].(float64)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return to.ErrorResult(fmt.Errorf("index is required"))
 | 
			
		||||
	}
 | 
			
		||||
	opt := gitea_sdk.ListIssueCommentOptions{}
 | 
			
		||||
	issue, _, err := gitea.Client().ListIssueComments(owner, repo, int64(index), opt)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return to.ErrorResult(fmt.Errorf("get %v/%v/issues/%v/comments err: %v", owner, repo, int64(index), err))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return to.TextResult(issue)
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user