{"record":{"id":"8cf948b1097c4872","repo":"flipped-aurora/gin-vue-admin","slug":"tool-schema-w","errorCode":null,"errorMessage":"序列化 tool schema 失败: %w","messagePattern":"序列化 tool schema 失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/dynamic_schema.go","lineNumber":65,"sourceCode":"\t\t\tprop[\"items\"] = map[string]any{\"type\": arrayItemJSONType(p.Type)}\n\t\t}\n\t\tproperties[p.Name] = prop\n\t\tif p.Required {\n\t\t\trequired = append(required, p.Name)\n\t\t}\n\t}\n\n\tschema := map[string]any{\n\t\t\"type\":       \"object\",\n\t\t\"properties\": properties,\n\t}\n\tif len(required) > 0 {\n\t\tschema[\"required\"] = required\n\t}\n\n\trawSchema, err := json.Marshal(schema)\n\tif err != nil {\n\t\treturn mcp.Tool{}, fmt.Errorf(\"序列化 tool schema 失败: %w\", err)\n\t}\n\n\tdescription := cmd.Description\n\tif description == \"\" {\n\t\tdescription = cmd.Summary\n\t}\n\tif description == \"\" {\n\t\tdescription = fmt.Sprintf(\"%s %s\", strings.ToUpper(cmd.Method), cmd.Path)\n\t}\n\n\ttool := mcp.NewToolWithRawSchema(cmd.Name, description, rawSchema)\n\treturn tool, nil\n}\n\n// manifestTypeToJSONType 把 CLI manifest 的参数类型映射到 JSON Schema 类型。\nfunc manifestTypeToJSONType(t string) string {\n\tswitch strings.ToLower(strings.TrimSpace(t)) {\n\tcase \"int\", \"int8\", \"int16\", \"int32\", \"int64\", \"uint\", \"uint8\", \"uint16\", \"uint32\", \"uint64\", \"integer\":","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/dynamic_schema.go#L47-L83","documentation":"In manifestCommandToTool (server/mcp/dynamic_schema.go:65), the CLI manifest command's parameter definitions are converted into a JSON Schema map which is serialized with json.Marshal before being registered as an MCP tool. If marshaling fails, the tool cannot be registered and this error wraps the underlying json error. In practice the schema is built from simple maps/strings/bools, so this is nearly impossible to hit unless a parameter name or description carries unsupported data.","triggerScenarios":"Calling registerDynamicTools during MCP server startup when a manifest command (autoRes.SysCliManifestCommand) produces a schema map that json.Marshal cannot serialize — e.g. a parameter Name/Description containing invalid state, or a future change introducing a non-serializable value (channel, func, cyclic map) into properties/required.","commonSituations":"Custom or hand-edited CLI manifest files with exotic field content; code modifications adding dynamic values (e.g. funcs) to the schema map; corrupted manifest data loaded from the CLI pipeline.","solutions":["Check the wrapped %w error to identify which value failed to marshal; json.Marshal errors name the unsupported type.","Inspect the manifest command's Parameters (names, descriptions, types) for invalid or unexpected data and fix the manifest source.","Verify no recent code change inserted non-JSON-serializable values (func, channel, cycle) into the schema map in manifestCommandToTool.","If a single command is bad, fix or remove it so registerDynamicTools can register the remaining tools."],"exampleFix":"// before: schema built with possibly non-serializable value\nproperties[p.Name] = prop\n// after: sanitize fields to plain strings before building the map\nprop := map[string]any{\n\t\"type\":        jsonType,\n\t\"description\": fmt.Sprintf(\"%v\", p.Description),\n}","handlingStrategy":"validation","validationCode":"// before registering, sanity-check the manifest command\nfunc validManifestCommand(cmd autoRes.SysCliManifestCommand) bool {\n\tif cmd.Name == \"\" || cmd.Path == \"\" || cmd.Method == \"\" {\n\t\treturn false\n\t}\n\tfor _, p := range cmd.Parameters {\n\t\tif p.Name == \"\" || p.Field == \"\" {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}","typeGuard":"func isJSONSerializable(v any) bool {\n\t_, err := json.Marshal(v)\n\treturn err == nil\n}","tryCatchPattern":"tool, err := manifestCommandToTool(cmd)\nif err != nil {\n\tlogger.Warn(\"skip unregistrable command %s: %v\", cmd.Name, err)\n\tcontinue\n}","preventionTips":["Keep the schema map limited to strings, bools and plain maps.","Validate manifest files after hand-editing them.","Log and skip bad commands instead of aborting the whole registration loop."],"tags":["mcp","json-serialization","tool-registration","go"],"backgroundTag":"json-marshal-unsupported-type","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}