Skip to content

experimental.ts uses zodToJsonSchema which is broken with Zod v4 #20807

@jbmml

Description

@jbmml

Description

server/routes/experimental.ts line 87 uses zodToJsonSchema() from zod-to-json-schema@3.24.5 to convert tool parameter schemas for the HTTP API. This library is incompatible with Zod v4 — it returns garbage output for object schemas.

Example: a Zod v4 object schema with two string properties produces {"type": "string", "$schema": "http://json-schema.org/draft-07/schema#"} instead of the correct object schema. All property definitions, descriptions, and required fields are lost.

The prompt path (session/prompt.ts line 440) correctly uses z.toJSONSchema() which works with Zod v4. The experimental API endpoint should use the same method.

Related: #4357 (original report about lost descriptions, now fixed in the prompt path by Zod v4)

Steps to reproduce

  1. Define a custom tool with described parameters
  2. Query the experimental tools endpoint (GET /experimental/tools?provider=...&model=...)
  3. Observe the returned parameter schemas are incorrect

Environment

  • OpenCode: latest dev (8daeacc98)
  • OS: macOS 15.4 (arm64)
  • Zod: v4, zod-to-json-schema: 3.24.5

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions