mirror of
				https://gitea.com/gitea/gitea-mcp.git
				synced 2025-11-04 04:11:50 +00:00 
			
		
		
		
	fix
This commit is contained in:
		@@ -65,7 +65,7 @@ func CreateBranchFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTool
 | 
			
		||||
		OldBranchName: oldBranch,
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("Create Branch Error: %v", err)
 | 
			
		||||
		return nil, fmt.Errorf("create branch error: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return mcp.NewToolResultText("Branch Created"), nil
 | 
			
		||||
@@ -87,7 +87,7 @@ func DeleteBranchFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTool
 | 
			
		||||
	}
 | 
			
		||||
	_, _, err := gitea.Client().DeleteRepoBranch(owner, repo, branch)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("Delete Branch Error: %v", err)
 | 
			
		||||
		return nil, fmt.Errorf("delete branch error: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return to.TextResult("Branch Deleted")
 | 
			
		||||
@@ -111,7 +111,7 @@ func ListBranchesFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTool
 | 
			
		||||
	}
 | 
			
		||||
	branches, _, err := gitea.Client().ListRepoBranches(owner, repo, opt)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("List Branches Error: %v", err)
 | 
			
		||||
		return nil, fmt.Errorf("list branches error: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return to.TextResult(branches)
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,6 @@ package repo
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"encoding/base64"
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"gitea.com/gitea/gitea-mcp/pkg/gitea"
 | 
			
		||||
@@ -14,16 +13,16 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	GetFileToolName    = "get_file"
 | 
			
		||||
	GetFileToolName    = "get_file_content"
 | 
			
		||||
	CreateFileToolName = "create_file"
 | 
			
		||||
	UpdateFileToolName = "update_file"
 | 
			
		||||
	DeleteFileToolName = "delete_file"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	GetFileTool = mcp.NewTool(
 | 
			
		||||
	GetFileContentTool = mcp.NewTool(
 | 
			
		||||
		GetFileToolName,
 | 
			
		||||
		mcp.WithDescription("Get file"),
 | 
			
		||||
		mcp.WithDescription("Get file Content and Metadata"),
 | 
			
		||||
		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("ref can be branch/tag/commit")),
 | 
			
		||||
@@ -49,7 +48,7 @@ var (
 | 
			
		||||
		mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
 | 
			
		||||
		mcp.WithString("filePath", mcp.Required(), mcp.Description("file path")),
 | 
			
		||||
		mcp.WithString("sha", mcp.Required(), mcp.Description("sha is the SHA for the file that already exists")),
 | 
			
		||||
		mcp.WithString("content", mcp.Required(), mcp.Description("raw file content")),
 | 
			
		||||
		mcp.WithString("content", mcp.Required(), mcp.Description("file content, base64 encoded")),
 | 
			
		||||
		mcp.WithString("message", mcp.Required(), mcp.Description("commit message")),
 | 
			
		||||
		mcp.WithString("branch_name", mcp.Required(), mcp.Description("branch name")),
 | 
			
		||||
	)
 | 
			
		||||
@@ -66,7 +65,7 @@ var (
 | 
			
		||||
	)
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func GetFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
 | 
			
		||||
func GetFileContentFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
 | 
			
		||||
	log.Debugf("Called GetFileFn")
 | 
			
		||||
	owner, ok := req.Params.Arguments["owner"].(string)
 | 
			
		||||
	if !ok {
 | 
			
		||||
@@ -81,11 +80,11 @@ func GetFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResul
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return nil, fmt.Errorf("filePath is required")
 | 
			
		||||
	}
 | 
			
		||||
	file, _, err := gitea.Client().GetFile(owner, repo, ref, filePath)
 | 
			
		||||
	content, _, err := gitea.Client().GetContents(owner, repo, ref, filePath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("get file err: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
	return to.TextResult(file)
 | 
			
		||||
	return to.TextResult(content)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CreateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
 | 
			
		||||
@@ -144,7 +143,7 @@ func UpdateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe
 | 
			
		||||
 | 
			
		||||
	opt := gitea_sdk.UpdateFileOptions{
 | 
			
		||||
		SHA:     sha,
 | 
			
		||||
		Content: base64.StdEncoding.EncodeToString([]byte(content)),
 | 
			
		||||
		Content: content,
 | 
			
		||||
		FileOptions: gitea_sdk.FileOptions{
 | 
			
		||||
			Message:    message,
 | 
			
		||||
			BranchName: branchName,
 | 
			
		||||
 
 | 
			
		||||
@@ -60,7 +60,7 @@ func RegisterTool(s *server.MCPServer) {
 | 
			
		||||
	s.AddTool(ListMyReposTool, ListMyReposFn)
 | 
			
		||||
 | 
			
		||||
	// File
 | 
			
		||||
	s.AddTool(GetFileTool, GetFileFn)
 | 
			
		||||
	s.AddTool(GetFileContentTool, GetFileContentFn)
 | 
			
		||||
	s.AddTool(CreateFileTool, CreateFileFn)
 | 
			
		||||
	s.AddTool(UpdateFileTool, UpdateFileFn)
 | 
			
		||||
	s.AddTool(DeleteFileTool, DeleteFileFn)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user