32 Star 310 Fork 86

开源中国/mcp-gitee

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
get_file_content.go 1.45 KB
Copy Edit Raw Blame History
JJ-H authored 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.14

Search