mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-02-27 09:05:12 +00:00
feat: accept string values for all numeric input parameters (#138)
## Summary - MCP clients may send numbers as strings. This adds `ToInt64` and `GetOptionalInt` helpers to `pkg/params` and replaces all raw `.(float64)` type assertions across operation handlers to accept both `float64` and string inputs. ## Test plan - [x] Verify `go test ./...` passes - [x] Test with an MCP client that sends numeric parameters as strings *Created by Claude on behalf of @silverwind* Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/138 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-committed-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"gitea.com/gitea/gitea-mcp/pkg/gitea"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/log"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/params"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/to"
|
||||
"gitea.com/gitea/gitea-mcp/pkg/tool"
|
||||
|
||||
@@ -68,11 +69,11 @@ func registerTools() {
|
||||
// getIntArg parses an integer argument from the MCP request arguments map.
|
||||
// Returns def if missing, not a number, or less than 1. Used for pagination arguments.
|
||||
func getIntArg(req mcp.CallToolRequest, name string, def int) int {
|
||||
val, ok := req.GetArguments()[name].(float64)
|
||||
if !ok || val < 1 {
|
||||
v := params.GetOptionalInt(req.GetArguments(), name, int64(def))
|
||||
if v < 1 {
|
||||
return def
|
||||
}
|
||||
return int(val)
|
||||
return int(v)
|
||||
}
|
||||
|
||||
// GetUserInfoFn is the handler for "get_my_user_info" MCP tool requests.
|
||||
|
||||
Reference in New Issue
Block a user