-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Describe the bug
When registering a tool using an empty Zod object as inputSchema, the generated JSON schema does not include the required field.
While this is valid JSON Schema, it is incompatible with OpenAI strict JSON schema mode, which requires the required field to always be present (even if empty). As a result, tools without input parameters cannot be defined cleanly using z.object({}).strict().
To Reproduce
Steps to reproduce the behavior:
- Register a tool with an empty Zod object as the input schema:
server.registerTool(
"example-tool",
{
description: "Example tool without input",
inputSchema: z.object({}).strict(),
outputSchema: z.object({
success: z.boolean()
})
},
async () => {
return { success: true };
}
);
- Inspect the generated JSON schema.
- The resulting schema is:
{
"type": "object",
"properties": {},
"additionalProperties": false
}
- When used with OpenAI strict tool schema validation, the schema fails.
Expected behavior
The generated schema should include an empty required array:
{
"type": "object",
"properties": {},
"required": [],
"additionalProperties": false
}
This ensures compatibility with OpenAI strict JSON schema mode.
Logs
OpenAI validation error:
Schema validation failed
The schema has structural issues:
root: Schema must have the following keys: required
Additional context
This affects tools that intentionally have no input parameters.
Currently, developers need to introduce artificial fields (e.g. noop parameters) to force generation of a required field, which is undesirable.
It would be helpful if the SDK ensured that required is always present (even as an empty array) when generating object schemas from Zod.