UNPKG

@h1deya/langchain-mcp-tools

Version:
27 lines (26 loc) 1.38 kB
/** * Transforms a JSON Schema to be compatible with OpenAI's function calling requirements * Used for converting MCP tool schemas to OpenAI function declarations * * OpenAI requires that optional fields must be nullable (.optional() + .nullable()) * for function calling to avoid API errors (based on Structured Outputs API requirements, * strict enforcement coming in future SDK versions). * * This adapter specifically fixes the Zod-related error: * "Zod field uses `.optional()` without `.nullable()` which is not supported by the API" * * This function processes the raw JSON schema before converting it to Zod * to ensure OpenAI compatibility by making all non-required fields nullable. * * The official OpenAI documentation states that in Structured Outputs, * all fields must be required OR if optional, they must also be nullable. * * For OpenAI function calling requirements: * see: https://platform.openai.com/docs/guides/function-calling * For OpenAI structured outputs (where this constraint is documented): * see: https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#all-fields-must-be-required */ import { JsonSchemaDraft7, TransformResult } from "./schema-adapter-types.js"; type JsonSchema = JsonSchemaDraft7; export declare function makeJsonSchemaOpenAICompatible(schema: JsonSchema): TransformResult; export {};