test(schema): add test for setting tool schemas with no argument input
Some checks failed
CI / build-and-test (push) Failing after -30m38s
Some checks failed
CI / build-and-test (push) Failing after -30m38s
This commit is contained in:
@@ -221,12 +221,19 @@ func formatLogDuration(d time.Duration) string {
|
|||||||
return fmt.Sprintf("%02d:%02d:%03d", minutes, seconds, milliseconds)
|
return fmt.Sprintf("%02d:%02d:%03d", minutes, seconds, milliseconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func normalizeObjectSchema(schema *jsonschema.Schema) {
|
||||||
|
if schema != nil && schema.Type == "object" && schema.Properties == nil {
|
||||||
|
schema.Properties = map[string]*jsonschema.Schema{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func setToolSchemas[In any, Out any](tool *mcp.Tool) error {
|
func setToolSchemas[In any, Out any](tool *mcp.Tool) error {
|
||||||
if tool.InputSchema == nil {
|
if tool.InputSchema == nil {
|
||||||
inputSchema, err := jsonschema.For[In](toolSchemaOptions)
|
inputSchema, err := jsonschema.For[In](toolSchemaOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("infer input schema: %w", err)
|
return fmt.Errorf("infer input schema: %w", err)
|
||||||
}
|
}
|
||||||
|
normalizeObjectSchema(inputSchema)
|
||||||
tool.InputSchema = inputSchema
|
tool.InputSchema = inputSchema
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,24 @@ import (
|
|||||||
"git.warky.dev/wdevs/amcs/internal/tools"
|
"git.warky.dev/wdevs/amcs/internal/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestSetToolSchemasAddsEmptyPropertiesForNoArgInput(t *testing.T) {
|
||||||
|
type noArgInput struct{}
|
||||||
|
type anyOutput struct{}
|
||||||
|
|
||||||
|
tool := &mcp.Tool{Name: "no_args"}
|
||||||
|
if err := setToolSchemas[noArgInput, anyOutput](tool); err != nil {
|
||||||
|
t.Fatalf("set tool schemas: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
schema, ok := tool.InputSchema.(*jsonschema.Schema)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("input schema type = %T, want *jsonschema.Schema", tool.InputSchema)
|
||||||
|
}
|
||||||
|
if schema.Properties == nil {
|
||||||
|
t.Fatal("input schema missing properties: strict MCP clients require properties:{} on object schemas")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSetToolSchemasUsesStringUUIDsInListOutput(t *testing.T) {
|
func TestSetToolSchemasUsesStringUUIDsInListOutput(t *testing.T) {
|
||||||
tool := &mcp.Tool{Name: "list_thoughts"}
|
tool := &mcp.Tool{Name: "list_thoughts"}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user