mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2025-08-23 22:33:05 +00:00
Update
This commit is contained in:
@@ -23,56 +23,62 @@ var (
|
||||
GetFileTool = mcp.NewTool(
|
||||
GetFileToolName,
|
||||
mcp.WithDescription("Get file"),
|
||||
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")),
|
||||
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")),
|
||||
mcp.WithString("ref", mcp.Required(), mcp.Description("ref"), mcp.DefaultString("")),
|
||||
mcp.WithString("filePath", mcp.Required(), mcp.Description("file path"), mcp.DefaultString("")),
|
||||
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")),
|
||||
mcp.WithString("filePath", mcp.Required(), mcp.Description("file path")),
|
||||
)
|
||||
|
||||
CreateFileTool = mcp.NewTool(
|
||||
CreateFileToolName,
|
||||
mcp.WithDescription("Create file"),
|
||||
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")),
|
||||
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")),
|
||||
mcp.WithString("filePath", mcp.Required(), mcp.Description("file path"), mcp.DefaultString("")),
|
||||
mcp.WithString("content", mcp.Required(), mcp.Description("file content"), mcp.DefaultString("")),
|
||||
mcp.WithString("message", mcp.Required(), mcp.Description("commit message"), mcp.DefaultString("")),
|
||||
mcp.WithString("branch_name", mcp.Required(), mcp.Description("branch name"), mcp.DefaultString("")),
|
||||
mcp.WithString("new_branch_name", mcp.Description("new branch name"), mcp.DefaultString("")),
|
||||
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
|
||||
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
|
||||
mcp.WithString("filePath", mcp.Required(), mcp.Description("file path")),
|
||||
mcp.WithString("content", mcp.Required(), mcp.Description("file content")),
|
||||
mcp.WithString("message", mcp.Required(), mcp.Description("commit message")),
|
||||
mcp.WithString("branch_name", mcp.Required(), mcp.Description("branch name")),
|
||||
mcp.WithString("new_branch_name", mcp.Description("new branch name")),
|
||||
)
|
||||
|
||||
UpdateFileTool = mcp.NewTool(
|
||||
UpdateFileToolName,
|
||||
mcp.WithDescription("Update file"),
|
||||
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")),
|
||||
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")),
|
||||
mcp.WithString("filePath", mcp.Required(), mcp.Description("file path"), mcp.DefaultString("")),
|
||||
mcp.WithString("content", mcp.Required(), mcp.Description("file content"), mcp.DefaultString("")),
|
||||
mcp.WithString("message", mcp.Required(), mcp.Description("commit message"), mcp.DefaultString("")),
|
||||
mcp.WithString("branch_name", mcp.Required(), mcp.Description("branch name"), mcp.DefaultString("")),
|
||||
mcp.WithString("new_branch_name", mcp.Description("new branch name"), mcp.DefaultString("")),
|
||||
mcp.WithString("from_path", mcp.Description("from path"), mcp.DefaultString("")),
|
||||
mcp.WithString("sha", mcp.Description("sha"), mcp.DefaultString("")),
|
||||
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
|
||||
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
|
||||
mcp.WithString("filePath", mcp.Required(), mcp.Description("file path")),
|
||||
mcp.WithString("content", mcp.Required(), mcp.Description("file content")),
|
||||
mcp.WithString("message", mcp.Required(), mcp.Description("commit message")),
|
||||
mcp.WithString("branch_name", mcp.Required(), mcp.Description("branch name")),
|
||||
)
|
||||
|
||||
DeleteFileTool = mcp.NewTool(
|
||||
DeleteFileToolName,
|
||||
mcp.WithDescription("Delete file"),
|
||||
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner"), mcp.DefaultString("")),
|
||||
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name"), mcp.DefaultString("")),
|
||||
mcp.WithString("filePath", mcp.Required(), mcp.Description("file path"), mcp.DefaultString("")),
|
||||
mcp.WithString("message", mcp.Required(), mcp.Description("commit message"), mcp.DefaultString("")),
|
||||
mcp.WithString("branch_name", mcp.Required(), mcp.Description("branch name"), mcp.DefaultString("")),
|
||||
mcp.WithString("sha", mcp.Description("sha"), mcp.DefaultString("")),
|
||||
mcp.WithString("owner", mcp.Required(), mcp.Description("repository owner")),
|
||||
mcp.WithString("repo", mcp.Required(), mcp.Description("repository name")),
|
||||
mcp.WithString("filePath", mcp.Required(), mcp.Description("file path")),
|
||||
mcp.WithString("message", mcp.Required(), mcp.Description("commit message")),
|
||||
mcp.WithString("branch_name", mcp.Required(), mcp.Description("branch name")),
|
||||
mcp.WithString("sha", mcp.Description("sha")),
|
||||
)
|
||||
)
|
||||
|
||||
func GetFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called GetFileFn")
|
||||
owner := req.Params.Arguments["owner"].(string)
|
||||
repo := req.Params.Arguments["repo"].(string)
|
||||
ref := req.Params.Arguments["ref"].(string)
|
||||
filePath := req.Params.Arguments["filePath"].(string)
|
||||
owner, ok := req.Params.Arguments["owner"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("owner is required")
|
||||
}
|
||||
repo, ok := req.Params.Arguments["repo"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("repo is required")
|
||||
}
|
||||
ref, _ := req.Params.Arguments["ref"].(string)
|
||||
filePath, ok := req.Params.Arguments["filePath"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("filePath is required")
|
||||
}
|
||||
file, _, err := gitea.Client().GetFile(owner, repo, ref, filePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get file err: %v", err)
|
||||
@@ -82,15 +88,26 @@ func GetFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResul
|
||||
|
||||
func CreateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called CreateFileFn")
|
||||
owner := req.Params.Arguments["owner"].(string)
|
||||
repo := req.Params.Arguments["repo"].(string)
|
||||
filePath := req.Params.Arguments["filePath"].(string)
|
||||
owner, ok := req.Params.Arguments["owner"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("owner is required")
|
||||
}
|
||||
repo, ok := req.Params.Arguments["repo"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("repo is required")
|
||||
}
|
||||
filePath, ok := req.Params.Arguments["filePath"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("filePath is required")
|
||||
}
|
||||
content, _ := req.Params.Arguments["content"].(string)
|
||||
message, _ := req.Params.Arguments["message"].(string)
|
||||
branchName, _ := req.Params.Arguments["branch_name"].(string)
|
||||
opt := gitea_sdk.CreateFileOptions{
|
||||
Content: req.Params.Arguments["content"].(string),
|
||||
Content: content,
|
||||
FileOptions: gitea_sdk.FileOptions{
|
||||
Message: req.Params.Arguments["message"].(string),
|
||||
BranchName: req.Params.Arguments["branch_name"].(string),
|
||||
NewBranchName: req.Params.Arguments["new_branch_name"].(string),
|
||||
Message: message,
|
||||
BranchName: branchName,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -103,17 +120,26 @@ func CreateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe
|
||||
|
||||
func UpdateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called UpdateFileFn")
|
||||
owner := req.Params.Arguments["owner"].(string)
|
||||
repo := req.Params.Arguments["repo"].(string)
|
||||
filePath := req.Params.Arguments["filePath"].(string)
|
||||
owner, ok := req.Params.Arguments["owner"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("owner is required")
|
||||
}
|
||||
repo, ok := req.Params.Arguments["repo"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("repo is required")
|
||||
}
|
||||
filePath, ok := req.Params.Arguments["filePath"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("filePath is required")
|
||||
}
|
||||
content, _ := req.Params.Arguments["content"].(string)
|
||||
message, _ := req.Params.Arguments["message"].(string)
|
||||
branchName, _ := req.Params.Arguments["branch_name"].(string)
|
||||
opt := gitea_sdk.UpdateFileOptions{
|
||||
Content: req.Params.Arguments["content"].(string),
|
||||
FromPath: req.Params.Arguments["from_path"].(string),
|
||||
SHA: req.Params.Arguments["sha"].(string),
|
||||
Content: content,
|
||||
FileOptions: gitea_sdk.FileOptions{
|
||||
Message: req.Params.Arguments["message"].(string),
|
||||
BranchName: req.Params.Arguments["branch_name"].(string),
|
||||
NewBranchName: req.Params.Arguments["new_branch_name"].(string),
|
||||
Message: message,
|
||||
BranchName: branchName,
|
||||
},
|
||||
}
|
||||
_, _, err := gitea.Client().UpdateFile(owner, repo, filePath, opt)
|
||||
@@ -125,15 +151,25 @@ func UpdateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe
|
||||
|
||||
func DeleteFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
log.Debugf("Called DeleteFileFn")
|
||||
owner := req.Params.Arguments["owner"].(string)
|
||||
repo := req.Params.Arguments["repo"].(string)
|
||||
filePath := req.Params.Arguments["filePath"].(string)
|
||||
owner, ok := req.Params.Arguments["owner"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("owner is required")
|
||||
}
|
||||
repo, ok := req.Params.Arguments["repo"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("repo is required")
|
||||
}
|
||||
filePath, ok := req.Params.Arguments["filePath"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("filePath is required")
|
||||
}
|
||||
message, _ := req.Params.Arguments["message"].(string)
|
||||
branchName, _ := req.Params.Arguments["branch_name"].(string)
|
||||
opt := gitea_sdk.DeleteFileOptions{
|
||||
FileOptions: gitea_sdk.FileOptions{
|
||||
Message: req.Params.Arguments["message"].(string),
|
||||
BranchName: req.Params.Arguments["branch_name"].(string),
|
||||
Message: message,
|
||||
BranchName: branchName,
|
||||
},
|
||||
SHA: req.Params.Arguments["sha"].(string),
|
||||
}
|
||||
_, err := gitea.Client().DeleteFile(owner, repo, filePath, opt)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user