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