{"record":{"id":"6cebf2347f38badd","repo":"vercel/ai","slug":"tool-parameters-must-be-a-json-schema-object-with","errorCode":null,"errorMessage":"tool parameters must be a JSON Schema object with type \"object\" for moonshotai (MFJS)","messagePattern":"tool parameters must be a JSON Schema object with type \"object\" for moonshotai \\(MFJS\\)","errorType":"validation","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/moonshotai/src/normalize-json-schema-for-mfjs.ts","lineNumber":35,"sourceCode":"  'if',\n  'then',\n  'else',\n] as const;\n\n/**\n * Normalizes a JSON Schema to the subset Moonshot's MFJS validator accepts:\n * `object` root required, tuple `items` become `prefixItems`, and `type` next\n * to `anyOf` moves into the branches. Everything else passes through. The\n * full original schema is still used for AI SDK result validation.\n */\nexport function normalizeJsonSchemaForMFJS(schema: unknown): unknown {\n  return normalizeDefinition(schema, true);\n}\n\nfunction normalizeDefinition(definition: unknown, isRoot: boolean): unknown {\n  if (typeof definition === 'boolean' || !isRecord(definition)) {\n    if (isRoot) {\n      throw new UnsupportedFunctionalityError({\n        functionality:\n          'tool parameters must be a JSON Schema object with type \"object\" for moonshotai (MFJS)',\n      });\n    }\n    return definition;\n  }\n\n  if (isRoot && definition.type !== 'object') {\n    throw new UnsupportedFunctionalityError({\n      functionality:\n        'tool parameters must be a JSON Schema object with type \"object\" for moonshotai (MFJS)',\n    });\n  }\n\n  const result: Record<string, unknown> = { ...definition };\n\n  // Existing prefixItems stay first (they are positional).\n  if (Array.isArray(result.items)) {","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/moonshotai/src/normalize-json-schema-for-mfjs.ts#L17-L53","documentation":"Moonshot's function calling (MFJS) requires tool parameters to be a JSON Schema object (a record), not a boolean schema. The MFJS normalizer throws UnsupportedFunctionalityError when the ROOT tool parameter schema is a boolean (true/false) or any non-object value, since there is no object to normalize.","triggerScenarios":"Defining a tool whose parameters resolve to a boolean JSON Schema (e.g. z.boolean()-like at top level, or a schema like `true`) and passing it to a Moonshot model, where normalizeJsonSchemaForMFJS is called on the root definition.","commonSituations":"Creating a no-argument tool with `parameters: true` or a bare boolean schema; using a validation library that emits boolean schemas for empty objects; hand-written JSON Schema with a boolean root.","solutions":["Make the root schema an object: { type: 'object', properties: {}, additionalProperties: false } for a no-arg tool.","Use z.object({}) in Zod so the generated root schema is an object.","Inspect the tool's JSON Schema output and confirm the root is a record with type 'object'."],"exampleFix":"// before\nparameters: true\n// after\nparameters: { type: 'object', properties: {}, additionalProperties: false }","handlingStrategy":"validation","validationCode":"function hasObjectRootSchema(tool: { parameters: unknown }): boolean {\n  const s = tool.parameters as any;\n  return typeof s === 'object' && s !== null && !Array.isArray(s);\n}\ntools.forEach(t => { if (!hasObjectRootSchema(t)) throw new Error(`tool ${t.name} needs an object root JSON Schema for Moonshot`); });","typeGuard":"function isRecordSchema(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null && !Array.isArray(v);\n}","tryCatchPattern":"import { UnsupportedFunctionalityError } from '@ai-sdk/provider';\ntry {\n  await generateText({ model: moonshot(id), tools });\n} catch (e) {\n  if (UnsupportedFunctionalityError.isInstance(e) && e.message.includes('MFJS')) {\n    // normalize/replace the offending tool schema\n  }\n  throw e;\n}","preventionTips":["Always define tool parameters with z.object({}) or an object-root JSON Schema.","Never use boolean schemas (true/false) as root tool parameters.","Log/inspect the serialized JSON Schema of tools during development.","Add a preflight validator that rejects non-object root schemas before calls."],"tags":["moonshotai","json-schema","tool-parameters","mfjs","unsupported-functionality"],"backgroundTag":"invalid-tool-schema","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}