mirror of
				https://gitea.com/gitea/gitea-mcp.git
				synced 2025-11-04 04:11:50 +00:00 
			
		
		
		
	feat: add get issue by index
This commit is contained in:
		
							
								
								
									
										52
									
								
								operation/issue/issue.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								operation/issue/issue.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
			
		||||
package issue
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"gitea.com/gitea/gitea-mcp/pkg/gitea"
 | 
			
		||||
	"github.com/mark3labs/mcp-go/mcp"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	GetIssueByIndexToolName = "get_issue_by_index"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	GetIssueByIndexTool = mcp.NewTool(
 | 
			
		||||
		GetIssueByIndexToolName,
 | 
			
		||||
		mcp.WithDescription("get issue 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 GetIssueByIndexFn(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
 | 
			
		||||
	owner := request.Params.Arguments["owner"].(string)
 | 
			
		||||
	repo := request.Params.Arguments["repo"].(string)
 | 
			
		||||
	index := request.Params.Arguments["index"].(float64)
 | 
			
		||||
	issue, _, err := gitea.Client().GetIssue(owner, repo, int64(index))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return mcp.NewToolResultError(fmt.Sprintf("get %v/%v/issue/%v err", owner, repo, int64(index))), err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	result, err := json.Marshal(issue)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return mcp.NewToolResultError("marshal issue err"), err
 | 
			
		||||
	}
 | 
			
		||||
	return mcp.NewToolResultText(string(result)), nil
 | 
			
		||||
}
 | 
			
		||||
@@ -3,6 +3,7 @@ package operation
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"gitea.com/gitea/gitea-mcp/operation/issue"
 | 
			
		||||
	"gitea.com/gitea/gitea-mcp/operation/repo"
 | 
			
		||||
	"gitea.com/gitea/gitea-mcp/operation/user"
 | 
			
		||||
	"gitea.com/gitea/gitea-mcp/operation/version"
 | 
			
		||||
@@ -22,6 +23,9 @@ func RegisterTool(s *server.MCPServer) {
 | 
			
		||||
	// Repo Tool
 | 
			
		||||
	s.AddTool(repo.ListMyReposTool, repo.ListMyReposFn)
 | 
			
		||||
 | 
			
		||||
	// Issue Tool
 | 
			
		||||
	s.AddTool(issue.GetIssueByIndexTool, issue.GetIssueByIndexFn)
 | 
			
		||||
 | 
			
		||||
	// Version Tool
 | 
			
		||||
	s.AddTool(version.GetGiteaMCPServerVersionTool, version.GetGiteaMCPServerVersionFn)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -16,25 +16,45 @@ const (
 | 
			
		||||
var (
 | 
			
		||||
	ListMyReposTool = mcp.NewTool(
 | 
			
		||||
		ListMyReposToolName,
 | 
			
		||||
		mcp.WithDescription("List My Repositories"),
 | 
			
		||||
		mcp.WithDescription("List my repositories"),
 | 
			
		||||
		mcp.WithNumber(
 | 
			
		||||
			"page",
 | 
			
		||||
			mcp.Description("Page number"),
 | 
			
		||||
			mcp.DefaultNumber(1),
 | 
			
		||||
			mcp.Min(1),
 | 
			
		||||
		),
 | 
			
		||||
		mcp.WithNumber(
 | 
			
		||||
			"pageSize",
 | 
			
		||||
			mcp.Description("Page size number"),
 | 
			
		||||
			mcp.DefaultNumber(10),
 | 
			
		||||
			mcp.Min(1),
 | 
			
		||||
		),
 | 
			
		||||
	)
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func ListMyReposFn(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
 | 
			
		||||
	page, ok := request.Params.Arguments["page"].(float64)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return mcp.NewToolResultError("get page number error"), nil
 | 
			
		||||
	}
 | 
			
		||||
	size, ok := request.Params.Arguments["pageSize"].(float64)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return mcp.NewToolResultError("get page size number error"), nil
 | 
			
		||||
	}
 | 
			
		||||
	opts := gitea.ListReposOptions{
 | 
			
		||||
		ListOptions: gitea.ListOptions{
 | 
			
		||||
			Page:     1,
 | 
			
		||||
			PageSize: 100,
 | 
			
		||||
			Page:     int(page),
 | 
			
		||||
			PageSize: int(size),
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	repos, _, err := giteaPkg.Client().ListMyRepos(opts)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return mcp.NewToolResultError("Get My User Info Error"), err
 | 
			
		||||
		return mcp.NewToolResultError("List my repositories error"), err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	result, err := json.Marshal(repos)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return mcp.NewToolResultError("Get My User Info Error"), err
 | 
			
		||||
		return mcp.NewToolResultError("marshal repository list error"), err
 | 
			
		||||
	}
 | 
			
		||||
	return mcp.NewToolResultText(string(result)), nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,7 @@ const (
 | 
			
		||||
var (
 | 
			
		||||
	GetMyUserInfoTool = mcp.NewTool(
 | 
			
		||||
		GetMyUserInfoToolName,
 | 
			
		||||
		mcp.WithDescription("Get My User Info"),
 | 
			
		||||
		mcp.WithDescription("Get my user info"),
 | 
			
		||||
	)
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -28,7 +28,7 @@ func GetUserInfoFn(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallT
 | 
			
		||||
 | 
			
		||||
	result, err := json.Marshal(user)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return mcp.NewToolResultError("Get My User Info Error"), err
 | 
			
		||||
		return mcp.NewToolResultError("marshal my user info error"), err
 | 
			
		||||
	}
 | 
			
		||||
	return mcp.NewToolResultText(string(result)), nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user