Ai
28 Star 261 Fork 75

开源中国/mcp-gitee

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
get_file_content.go 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
JJ-H 提交于 2025-06-16 16:10 +08:00 . feat: Support streamable http
package repository
import (
"context"
"fmt"
"net/url"
"gitee.com/oschina/mcp-gitee/utils"
"github.com/mark3labs/mcp-go/mcp"
)
const (
// GetFileContentToolName is the tool name for getting file content
GetFileContentToolName = "get_file_content"
)
var GetFileContentTool = mcp.NewTool(
GetFileContentToolName,
mcp.WithDescription("Get the content of the specified file in the repository"),
mcp.WithString(
"owner",
mcp.Description("The space address to which the repository belongs (the address path of the enterprise, organization or individual)"),
mcp.Required(),
),
mcp.WithString(
"repo",
mcp.Description("The path of the repository"),
mcp.Required(),
),
mcp.WithString(
"path",
mcp.Description("The path of the file"),
mcp.Required(),
),
mcp.WithString(
"ref",
mcp.Description("The branch name or commit ID"),
),
)
func GetFileContentHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
args, _ := utils.ConvertArgumentsToMap(request.Params.Arguments)
owner := args["owner"].(string)
repo := args["repo"].(string)
path := args["path"].(string)
ref, ok := args["ref"].(string)
if !ok {
ref = ""
}
apiUrl := fmt.Sprintf("/repos/%s/%s/contents/%s", owner, repo, url.QueryEscape(path))
giteeClient := utils.NewGiteeClient("GET", apiUrl, utils.WithContext(ctx), utils.WithQuery(map[string]interface{}{"ref": ref}))
var fileContents interface{}
return giteeClient.HandleMCPResult(&fileContents)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/oschina/mcp-gitee.git
git@gitee.com:oschina/mcp-gitee.git
oschina
mcp-gitee
mcp-gitee
v0.1.13

搜索帮助