Skip to content

Commit a4b31b8

Browse files
refactor string conversion helpers
1 parent 4d6a90a commit a4b31b8

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

pkg/github/server.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7+
"strconv"
78

89
"github.com/google/go-github/v77/github"
910
"github.com/mark3labs/mcp-go/mcp"
@@ -202,18 +203,20 @@ func OptionalStringArrayParam(r mcp.CallToolRequest, p string) ([]string, error)
202203
}
203204
}
204205

205-
func convertStringSliceToInt64Slice(s []string) []int64 {
206+
func convertStringSliceToBigIntSlice(s []string) []int64 {
206207
int64Slice := make([]int64, len(s))
207208
for i, str := range s {
208-
int64Slice[i] = convertStringToInt64(str)
209+
int64Slice[i] = convertStringToBigInt(str, 0)
209210
}
210211
return int64Slice
211212
}
212213

213-
func convertStringToInt64(s string) int64 {
214-
var i int64
215-
fmt.Sscan(s, &i)
216-
return i
214+
func convertStringToBigInt(s string, def int64) int64 {
215+
v, err := strconv.ParseInt(s, 10, 64)
216+
if err != nil {
217+
return def
218+
}
219+
return v
217220
}
218221

219222
// OptionalStringArrayParam is a helper function that can be used to fetch a requested parameter from the request.
@@ -230,15 +233,15 @@ func OptionalBigIntArrayParam(r mcp.CallToolRequest, p string) ([]int64, error)
230233
case nil:
231234
return []int64{}, nil
232235
case []string:
233-
return convertStringSliceToInt64Slice(v), nil
236+
return convertStringSliceToBigIntSlice(v), nil
234237
case []any:
235238
int64Slice := make([]int64, len(v))
236239
for i, v := range v {
237240
s, ok := v.(string)
238241
if !ok {
239242
return []int64{}, fmt.Errorf("parameter %s is not of type string, is %T", p, v)
240243
}
241-
int64Slice[i] = convertStringToInt64(s)
244+
int64Slice[i] = convertStringToBigInt(s)
242245
}
243246
return int64Slice, nil
244247
default:

0 commit comments

Comments
 (0)