Skip to content

Commit 641b3ab

Browse files
improves implementation for RequiredBigInt
1 parent e3db2d1 commit 641b3ab

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pkg/github/server.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,21 @@ func RequiredInt(r mcp.CallToolRequest, p string) (int, error) {
103103
// RequiredBigInt is a helper function that can be used to fetch a requested parameter from the request.
104104
// It does the following checks:
105105
// 1. Checks if the parameter is present in the request.
106-
// 2. Checks if the parameter is of the expected type.
107-
// 3. Checks if the parameter is not empty, i.e: non-zero value
106+
// 2. Checks if the parameter is of the expected type (float64).
107+
// 3. Checks if the parameter is not empty, i.e: non-zero value.
108+
// 4. Validates that the float64 value can be safely converted to int64 without truncation.
108109
func RequiredBigInt(r mcp.CallToolRequest, p string) (int64, error) {
109110
v, err := RequiredParam[float64](r, p)
110111
if err != nil {
111112
return 0, err
112113
}
113-
return int64(v), nil
114+
115+
result := int64(v)
116+
// Check if converting back produces the same value to avoid silent truncation
117+
if float64(result) != v {
118+
return 0, fmt.Errorf("parameter %s value %f is too large to fit in int64", p, v)
119+
}
120+
return result, nil
114121
}
115122

116123
// OptionalParam is a helper function that can be used to fetch a requested parameter from the request.

0 commit comments

Comments
 (0)