mirror of
				https://gitea.com/gitea/gitea-mcp.git
				synced 2025-10-30 09:51:50 +00:00 
			
		
		
		
	Adding more logs (#6)
Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/6 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: hiifong <i@hiif.ong> Co-committed-by: hiifong <i@hiif.ong>
This commit is contained in:
		| @@ -48,15 +48,15 @@ func CreateBranchFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTool | ||||
| 	log.Debugf("Called CreateBranchFn") | ||||
| 	owner, ok := req.Params.Arguments["owner"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("owner is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("owner is required")) | ||||
| 	} | ||||
| 	repo, ok := req.Params.Arguments["repo"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("repo is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("repo is required")) | ||||
| 	} | ||||
| 	branch, ok := req.Params.Arguments["branch"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("branch is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("branch is required")) | ||||
| 	} | ||||
| 	oldBranch, _ := req.Params.Arguments["old_branch"].(string) | ||||
|  | ||||
| @@ -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 to.ErrorResult(fmt.Errorf("create branch error: %v", err)) | ||||
| 	} | ||||
|  | ||||
| 	return mcp.NewToolResultText("Branch Created"), nil | ||||
| @@ -75,19 +75,19 @@ func DeleteBranchFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTool | ||||
| 	log.Debugf("Called DeleteBranchFn") | ||||
| 	owner, ok := req.Params.Arguments["owner"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("owner is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("owner is required")) | ||||
| 	} | ||||
| 	repo, ok := req.Params.Arguments["repo"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("repo is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("repo is required")) | ||||
| 	} | ||||
| 	branch, ok := req.Params.Arguments["branch"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("branch is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("branch is required")) | ||||
| 	} | ||||
| 	_, _, err := gitea.Client().DeleteRepoBranch(owner, repo, branch) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("delete branch error: %v", err) | ||||
| 		return to.ErrorResult(fmt.Errorf("delete branch error: %v", err)) | ||||
| 	} | ||||
|  | ||||
| 	return to.TextResult("Branch Deleted") | ||||
| @@ -97,11 +97,11 @@ func ListBranchesFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTool | ||||
| 	log.Debugf("Called ListBranchesFn") | ||||
| 	owner, ok := req.Params.Arguments["owner"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("owner is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("owner is required")) | ||||
| 	} | ||||
| 	repo, ok := req.Params.Arguments["repo"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("repo is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("repo is required")) | ||||
| 	} | ||||
| 	opt := gitea_sdk.ListRepoBranchesOptions{ | ||||
| 		ListOptions: gitea_sdk.ListOptions{ | ||||
| @@ -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 to.ErrorResult(fmt.Errorf("list branches error: %v", err)) | ||||
| 	} | ||||
|  | ||||
| 	return to.TextResult(branches) | ||||
|   | ||||
| @@ -33,19 +33,19 @@ func ListRepoCommitsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallT | ||||
| 	log.Debugf("Called ListRepoCommitsFn") | ||||
| 	owner, ok := req.Params.Arguments["owner"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("owner is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("owner is required")) | ||||
| 	} | ||||
| 	repo, ok := req.Params.Arguments["repo"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("repo is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("repo is required")) | ||||
| 	} | ||||
| 	page, ok := req.Params.Arguments["page"].(float64) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("page is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("page is required")) | ||||
| 	} | ||||
| 	pageSize, ok := req.Params.Arguments["page_size"].(float64) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("page_size is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("page_size is required")) | ||||
| 	} | ||||
| 	sha, _ := req.Params.Arguments["sha"].(string) | ||||
| 	path, _ := req.Params.Arguments["path"].(string) | ||||
| @@ -59,7 +59,7 @@ func ListRepoCommitsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallT | ||||
| 	} | ||||
| 	commits, _, err := gitea.Client().ListRepoCommits(owner, repo, opt) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("list repo commits err: %v", err) | ||||
| 		return to.ErrorResult(fmt.Errorf("list repo commits err: %v", err)) | ||||
| 	} | ||||
| 	return to.TextResult(commits) | ||||
| } | ||||
|   | ||||
| @@ -69,20 +69,20 @@ func GetFileContentFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTo | ||||
| 	log.Debugf("Called GetFileFn") | ||||
| 	owner, ok := req.Params.Arguments["owner"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("owner is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("owner is required")) | ||||
| 	} | ||||
| 	repo, ok := req.Params.Arguments["repo"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("repo is required") | ||||
| 		return to.ErrorResult(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") | ||||
| 		return to.ErrorResult(fmt.Errorf("filePath is required")) | ||||
| 	} | ||||
| 	content, _, err := gitea.Client().GetContents(owner, repo, ref, filePath) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("get file err: %v", err) | ||||
| 		return to.ErrorResult(fmt.Errorf("get file err: %v", err)) | ||||
| 	} | ||||
| 	return to.TextResult(content) | ||||
| } | ||||
| @@ -91,15 +91,15 @@ func CreateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe | ||||
| 	log.Debugf("Called CreateFileFn") | ||||
| 	owner, ok := req.Params.Arguments["owner"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("owner is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("owner is required")) | ||||
| 	} | ||||
| 	repo, ok := req.Params.Arguments["repo"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("repo is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("repo is required")) | ||||
| 	} | ||||
| 	filePath, ok := req.Params.Arguments["filePath"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("filePath is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("filePath is required")) | ||||
| 	} | ||||
| 	content, _ := req.Params.Arguments["content"].(string) | ||||
| 	message, _ := req.Params.Arguments["message"].(string) | ||||
| @@ -114,7 +114,7 @@ func CreateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe | ||||
|  | ||||
| 	_, _, err := gitea.Client().CreateFile(owner, repo, filePath, opt) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("create file err: %v", err) | ||||
| 		return to.ErrorResult(fmt.Errorf("create file err: %v", err)) | ||||
| 	} | ||||
| 	return to.TextResult("Create file success") | ||||
| } | ||||
| @@ -123,19 +123,19 @@ func UpdateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe | ||||
| 	log.Debugf("Called UpdateFileFn") | ||||
| 	owner, ok := req.Params.Arguments["owner"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("owner is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("owner is required")) | ||||
| 	} | ||||
| 	repo, ok := req.Params.Arguments["repo"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("repo is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("repo is required")) | ||||
| 	} | ||||
| 	filePath, ok := req.Params.Arguments["filePath"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("filePath is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("filePath is required")) | ||||
| 	} | ||||
| 	sha, ok := req.Params.Arguments["sha"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("sha is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("sha is required")) | ||||
| 	} | ||||
| 	content, _ := req.Params.Arguments["content"].(string) | ||||
| 	message, _ := req.Params.Arguments["message"].(string) | ||||
| @@ -151,7 +151,7 @@ func UpdateFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe | ||||
| 	} | ||||
| 	_, _, err := gitea.Client().UpdateFile(owner, repo, filePath, opt) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("update file err: %v", err) | ||||
| 		return to.ErrorResult(fmt.Errorf("update file err: %v", err)) | ||||
| 	} | ||||
| 	return to.TextResult("Update file success") | ||||
| } | ||||
| @@ -160,15 +160,15 @@ func DeleteFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe | ||||
| 	log.Debugf("Called DeleteFileFn") | ||||
| 	owner, ok := req.Params.Arguments["owner"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("owner is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("owner is required")) | ||||
| 	} | ||||
| 	repo, ok := req.Params.Arguments["repo"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("repo is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("repo is required")) | ||||
| 	} | ||||
| 	filePath, ok := req.Params.Arguments["filePath"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("filePath is required") | ||||
| 		return to.ErrorResult(fmt.Errorf("filePath is required")) | ||||
| 	} | ||||
| 	message, _ := req.Params.Arguments["message"].(string) | ||||
| 	branchName, _ := req.Params.Arguments["branch_name"].(string) | ||||
| @@ -180,7 +180,7 @@ func DeleteFileFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe | ||||
| 	} | ||||
| 	_, err := gitea.Client().DeleteFile(owner, repo, filePath, opt) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("delete file err: %v", err) | ||||
| 		return to.ErrorResult(fmt.Errorf("delete file err: %v", err)) | ||||
| 	} | ||||
| 	return to.TextResult("Delete file success") | ||||
| } | ||||
|   | ||||
| @@ -78,7 +78,7 @@ func CreateRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe | ||||
| 	log.Debugf("Called CreateRepoFn") | ||||
| 	name, ok := req.Params.Arguments["name"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, errors.New("repository name is required") | ||||
| 		return to.ErrorResult(errors.New("repository name is required")) | ||||
| 	} | ||||
| 	description, _ := req.Params.Arguments["description"].(string) | ||||
| 	private, _ := req.Params.Arguments["private"].(bool) | ||||
| @@ -104,7 +104,7 @@ func CreateRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe | ||||
| 	} | ||||
| 	repo, _, err := gitea.Client().CreateRepo(opt) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 		return to.ErrorResult(fmt.Errorf("create repo err: %v", err)) | ||||
| 	} | ||||
| 	return to.TextResult(repo) | ||||
| } | ||||
| @@ -113,11 +113,11 @@ func ForkRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResu | ||||
| 	log.Debugf("Called ForkRepoFn") | ||||
| 	user, ok := req.Params.Arguments["user"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, errors.New("user name is required") | ||||
| 		return to.ErrorResult(errors.New("user name is required")) | ||||
| 	} | ||||
| 	repo, ok := req.Params.Arguments["repo"].(string) | ||||
| 	if !ok { | ||||
| 		return nil, errors.New("repository name is required") | ||||
| 		return to.ErrorResult(errors.New("repository name is required")) | ||||
| 	} | ||||
| 	organization, _ := req.Params.Arguments["organization"].(string) | ||||
| 	name, _ := req.Params.Arguments["name"].(string) | ||||
| @@ -127,7 +127,7 @@ func ForkRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResu | ||||
| 	} | ||||
| 	_, _, err := gitea.Client().CreateFork(user, repo, opt) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("fork repository error %v", err) | ||||
| 		return to.ErrorResult(fmt.Errorf("fork repository error %v", err)) | ||||
| 	} | ||||
| 	return to.TextResult("Fork success") | ||||
| } | ||||
| @@ -136,21 +136,21 @@ func ListMyReposFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolR | ||||
| 	log.Debugf("Called ListMyReposFn") | ||||
| 	page, ok := req.Params.Arguments["page"].(float64) | ||||
| 	if !ok { | ||||
| 		return nil, errors.New("get page number error") | ||||
| 		page = 1 | ||||
| 	} | ||||
| 	size, ok := req.Params.Arguments["pageSize"].(float64) | ||||
| 	pageSize, ok := req.Params.Arguments["pageSize"].(float64) | ||||
| 	if !ok { | ||||
| 		return nil, errors.New("get page size number error") | ||||
| 		pageSize = 100 | ||||
| 	} | ||||
| 	opt := gitea_sdk.ListReposOptions{ | ||||
| 		ListOptions: gitea_sdk.ListOptions{ | ||||
| 			Page:     int(page), | ||||
| 			PageSize: int(size), | ||||
| 			PageSize: int(pageSize), | ||||
| 		}, | ||||
| 	} | ||||
| 	repos, _, err := gitea.Client().ListMyRepos(opt) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("list my repositories error %v", err) | ||||
| 		return to.ErrorResult(fmt.Errorf("list my repositories error: %v", err)) | ||||
| 	} | ||||
|  | ||||
| 	return to.TextResult(repos) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user