Skip to content

Commit cd16517

Browse files
committed
Bump version to 0.1.3, and fix file content handling.
Signed-off-by: edmondfrank
1 parent 085880c commit cd16517

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ profile.cov
1919
*.iml
2020

2121
.vscode/
22+
release/
2223

2324
.DS_Store
2425
*.log
2526
.env
26-
.env.local
27+
.env.local

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
GO = go
33

44
# Version information
5-
VERSION ?= 0.1.2
5+
VERSION ?= 0.1.3
66

77
# Repository information
88
GITEE_OWNER ?= "oschina"

operations/repository/get_file_content.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package repository
33
import (
44
"context"
55
"fmt"
6-
"gitee.com/oschina/mcp-gitee/operations/types"
76
"gitee.com/oschina/mcp-gitee/utils"
87
"github.com/mark3labs/mcp-go/mcp"
98
"net/url"
@@ -48,6 +47,6 @@ func GetFileContentHandler(ctx context.Context, request mcp.CallToolRequest) (*m
4847
}
4948
apiUrl := fmt.Sprintf("/repos/%s/%s/contents/%s", owner, repo, url.QueryEscape(path))
5049
giteeClient := utils.NewGiteeClient("GET", apiUrl, utils.WithQuery(map[string]interface{}{"ref": ref}))
51-
fileContent := &types.FileContent{}
52-
return giteeClient.HandleMCPResult(fileContent)
50+
var fileContents interface{}
51+
return giteeClient.HandleMCPResult(&fileContents)
5352
}

utils/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ package utils
22

33
var (
44
// Version gitee mcp server version
5-
Version = "0.1.2"
5+
Version = "0.1.3"
66
)

utils/gitee_client.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/base64"
66
"encoding/json"
7+
"errors"
78
"fmt"
89
"gitee.com/oschina/mcp-gitee/operations/types"
910
"io/ioutil"
@@ -223,19 +224,30 @@ func (g *GiteeClient) HandleMCPResult(object any) (*mcp.CallToolResult, error) {
223224
}
224225

225226
if err = json.Unmarshal(body, object); err != nil {
226-
return mcp.NewToolResultError(fmt.Sprintf("Failed to parse response: %s", err.Error())),
227-
NewInternalError(err)
227+
errorMessage := fmt.Sprintf("Failed to parse response: %v", err)
228+
return mcp.NewToolResultError(errorMessage), NewInternalError(errors.New(errorMessage))
228229
}
229230

230231
// decode file base64 content
231-
if fileContent, ok := object.(*types.FileContent); ok {
232-
content, err := base64.StdEncoding.DecodeString(fileContent.Content)
232+
switch v := object.(type) {
233+
case *[]types.FileContent:
234+
for i := range *v {
235+
content, err := base64.StdEncoding.DecodeString((*v)[i].Content)
236+
if err != nil {
237+
return mcp.NewToolResultError(fmt.Sprintf("Failed to decode base64 content: %s", err.Error())),
238+
NewInternalError(err)
239+
}
240+
(*v)[i].Content = string(content)
241+
}
242+
object = v
243+
case *types.FileContent:
244+
content, err := base64.StdEncoding.DecodeString(v.Content)
233245
if err != nil {
234246
return mcp.NewToolResultError(fmt.Sprintf("Failed to decode base64 content: %s", err.Error())),
235247
NewInternalError(err)
236248
}
237-
fileContent.Content = string(content)
238-
object = fileContent
249+
v.Content = string(content)
250+
object = v
239251
}
240252

241253
result, err := json.MarshalIndent(object, "", " ")

0 commit comments

Comments
 (0)