fix: replace 'float' with 'number' in McpManifest (#985)

According to the json schema spec:There are two numeric types in JSON
Schema: integer and number So 'float' is not with mcpcurl and mcphost

Fixes #984, #797

---------

Co-authored-by: Yuan Teoh <45984206+Yuan325@users.noreply.github.com>
This commit is contained in:
bitsark
2025-07-25 02:03:34 +08:00
committed by GitHub
parent 74dbd6124d
commit 59e23e1725
2 changed files with 13 additions and 2 deletions

View File

@@ -790,6 +790,15 @@ func (p *FloatParameter) Manifest() ParameterManifest {
}
}
// McpManifest returns the MCP manifest for the FloatParameter.
// json schema only allow numeric types of 'integer' and 'number'.
func (p *FloatParameter) McpManifest() ParameterMcpManifest {
return ParameterMcpManifest{
Type: "number",
Description: p.Desc,
}
}
// NewBooleanParameter is a convenience function for initializing a BooleanParameter.
func NewBooleanParameter(name string, desc string) *BooleanParameter {
return &BooleanParameter{

View File

@@ -1327,7 +1327,7 @@ func TestParamMcpManifest(t *testing.T) {
{
name: "float",
in: tools.NewFloatParameter("foo-float", "bar"),
want: tools.ParameterMcpManifest{Type: "float", Description: "bar"},
want: tools.ParameterMcpManifest{Type: "number", Description: "bar"},
},
{
name: "boolean",
@@ -1385,6 +1385,7 @@ func TestMcpManifest(t *testing.T) {
tools.NewStringParameterWithDefault("foo-string", "foo", "bar"),
tools.NewStringParameter("foo-string2", "bar"),
tools.NewIntParameter("foo-int2", "bar"),
tools.NewFloatParameter("foo-float", "bar"),
tools.NewArrayParameter("foo-array2", "bar", tools.NewStringParameter("foo-string", "bar")),
tools.NewMapParameter("foo-map-int", "a map of ints", "integer"),
tools.NewMapParameter("foo-map-any", "a map of any", ""),
@@ -1395,6 +1396,7 @@ func TestMcpManifest(t *testing.T) {
"foo-string": {Type: "string", Description: "bar"},
"foo-string2": {Type: "string", Description: "bar"},
"foo-int2": {Type: "integer", Description: "bar"},
"foo-float": {Type: "number", Description: "bar"},
"foo-array2": {
Type: "array",
Description: "bar",
@@ -1411,7 +1413,7 @@ func TestMcpManifest(t *testing.T) {
AdditionalProperties: true,
},
},
Required: []string{"foo-string2", "foo-int2", "foo-array2", "foo-map-int", "foo-map-any"},
Required: []string{"foo-string2", "foo-int2", "foo-float", "foo-array2", "foo-map-int", "foo-map-any"},
},
},
}