Skip to content

inputSchema generated from empty Zod object is incompatible with OpenAI strict JSON schema mode #1659

@tomboe311

Description

@tomboe311

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:

  1. 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 };
  }
);
  1. Inspect the generated JSON schema.
  2. The resulting schema is:
{
  "type": "object",
  "properties": {},
  "additionalProperties": false
}
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions