From f33b04a3df742376b1277768617c7dfc5b299a03 Mon Sep 17 00:00:00 2001 From: marcluer Date: Fri, 29 Aug 2025 05:37:19 +0000 Subject: [PATCH] feat: added parameter 'organization' to tool 'create_repo' (#88) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using the Gitea-mcp server I was missing the ability to create repositories in other organizations. e.g.: * I was only able to create `https://gitea.domain.com/myuser/repo` ✅ * I was not able to create `https://gitea.domain.com/organization/repo` ❌ This feature was planned, implemented and compiled by Claude Code. I have no clue about Golang. I then took the resulting `gitea-mcp` file and sucessfully tested it on my self-hosted gitea instance: * Creating `https://gitea.domain.com/myuser/repo` ✅ * Creating `https://gitea.domain.com/organization/repo` ✅ Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/88 Reviewed-by: Lunny Xiao Co-authored-by: marcluer Co-committed-by: marcluer --- operation/repo/repo.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/operation/repo/repo.go b/operation/repo/repo.go index d9a1831..b6c633a 100644 --- a/operation/repo/repo.go +++ b/operation/repo/repo.go @@ -27,7 +27,7 @@ const ( var ( CreateRepoTool = mcp.NewTool( CreateRepoToolName, - mcp.WithDescription("Create repository"), + mcp.WithDescription("Create repository in personal account or organization"), mcp.WithString("name", mcp.Required(), mcp.Description("Name of the repository to create")), mcp.WithString("description", mcp.Description("Description of the repository to create")), mcp.WithBoolean("private", mcp.Description("Whether the repository is private")), @@ -38,6 +38,7 @@ var ( mcp.WithString("license", mcp.Description("License to use")), mcp.WithString("readme", mcp.Description("Readme of the repository to create")), mcp.WithString("default_branch", mcp.Description("DefaultBranch of the repository (used when initializes and in template)")), + mcp.WithString("organization", mcp.Description("Organization name to create repository in (optional - defaults to personal account)")), ) ForkRepoTool = mcp.NewTool( @@ -120,6 +121,7 @@ func CreateRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe license, _ := req.GetArguments()["license"].(string) readme, _ := req.GetArguments()["readme"].(string) defaultBranch, _ := req.GetArguments()["default_branch"].(string) + organization, _ := req.GetArguments()["organization"].(string) opt := gitea_sdk.CreateRepoOption{ Name: name, @@ -133,9 +135,19 @@ func CreateRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolRe Readme: readme, DefaultBranch: defaultBranch, } - repo, _, err := gitea.Client().CreateRepo(opt) - if err != nil { - return to.ErrorResult(fmt.Errorf("create repo err: %v", err)) + + var repo *gitea_sdk.Repository + var err error + if organization != "" { + repo, _, err = gitea.Client().CreateOrgRepo(organization, opt) + if err != nil { + return to.ErrorResult(fmt.Errorf("create organization repository '%s' in '%s' err: %v", name, organization, err)) + } + } else { + repo, _, err = gitea.Client().CreateRepo(opt) + if err != nil { + return to.ErrorResult(fmt.Errorf("create repository '%s' err: %v", name, err)) + } } return to.TextResult(repo) }