mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2025-08-23 22:33:05 +00:00
Update
This commit is contained in:
@@ -2,20 +2,44 @@ package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
giteaPkg "gitea.com/gitea/gitea-mcp/pkg/gitea"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/to"
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
)
|
||||
|
||||
const (
|
||||
CreateRepoToolName = "create_repo"
|
||||
ListMyReposToolName = "list_my_repos"
|
||||
)
|
||||
|
||||
var (
|
||||
CreateRepoTool = mcp.NewTool(
|
||||
CreateRepoToolName,
|
||||
CreateRepoOpt...,
|
||||
)
|
||||
|
||||
CreateRepoOpt = []mcp.ToolOption{
|
||||
mcp.WithDescription("Create repository"),
|
||||
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")),
|
||||
mcp.WithString("issue_labels", mcp.Description("Issue Label set to use")),
|
||||
mcp.WithBoolean("auto_init", mcp.Description("Whether the repository should be auto-intialized?")),
|
||||
mcp.WithBoolean("template", mcp.Description("Whether the repository is template")),
|
||||
mcp.WithString("gitignores", mcp.Description("Gitignores to use")),
|
||||
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)")),
|
||||
}
|
||||
|
||||
ListMyReposTool = mcp.NewTool(
|
||||
ListMyReposToolName,
|
||||
ListMyReposOpt...,
|
||||
)
|
||||
|
||||
ListMyReposOpt = []mcp.ToolOption{
|
||||
mcp.WithDescription("List my repositories"),
|
||||
mcp.WithNumber(
|
||||
"page",
|
||||
@@ -29,15 +53,46 @@ var (
|
||||
mcp.DefaultNumber(10),
|
||||
mcp.Min(1),
|
||||
),
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
func ListMyReposFn(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
page, ok := request.Params.Arguments["page"].(float64)
|
||||
func CreateRepoFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
name := req.Params.Arguments["name"].(string)
|
||||
description := req.Params.Arguments["description"].(string)
|
||||
private := req.Params.Arguments["private"].(bool)
|
||||
issueLabels := req.Params.Arguments["issue_labels"].(string)
|
||||
autoInit := req.Params.Arguments["auto_init"].(bool)
|
||||
template := req.Params.Arguments["template"].(bool)
|
||||
gitignores := req.Params.Arguments["gitignores"].(string)
|
||||
license := req.Params.Arguments["license"].(string)
|
||||
readme := req.Params.Arguments["readme"].(string)
|
||||
defaultBranch := req.Params.Arguments["default_branch"].(string)
|
||||
|
||||
opt := gitea.CreateRepoOption{
|
||||
Name: name,
|
||||
Description: description,
|
||||
Private: private,
|
||||
IssueLabels: issueLabels,
|
||||
AutoInit: autoInit,
|
||||
Template: template,
|
||||
Gitignores: gitignores,
|
||||
License: license,
|
||||
Readme: readme,
|
||||
DefaultBranch: defaultBranch,
|
||||
}
|
||||
repo, _, err := giteaPkg.Client().CreateRepo(opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return to.TextResult(repo)
|
||||
}
|
||||
|
||||
func ListMyReposFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
page, ok := req.Params.Arguments["page"].(float64)
|
||||
if !ok {
|
||||
return mcp.NewToolResultError("get page number error"), nil
|
||||
}
|
||||
size, ok := request.Params.Arguments["pageSize"].(float64)
|
||||
size, ok := req.Params.Arguments["pageSize"].(float64)
|
||||
if !ok {
|
||||
return mcp.NewToolResultError("get page size number error"), nil
|
||||
}
|
||||
@@ -52,9 +107,5 @@ func ListMyReposFn(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallT
|
||||
return mcp.NewToolResultError("List my repositories error"), err
|
||||
}
|
||||
|
||||
result, err := json.Marshal(repos)
|
||||
if err != nil {
|
||||
return mcp.NewToolResultError("marshal repository list error"), err
|
||||
}
|
||||
return mcp.NewToolResultText(string(result)), nil
|
||||
return to.TextResult(repos)
|
||||
}
|
||||
|
Reference in New Issue
Block a user