Skip to content

output schema has unnecessary restriction type=object #1149

@spacewander

Description

@spacewander

Describe the bug
A clear and concise description of what the bug is.

The typescript SDK requires that the outputSchema be in type: "object".

typescript-sdk/src/types.ts

Lines 1013 to 1018 in 0c1cbf0

outputSchema: z
.object({
type: z.literal('object'),
properties: z.record(z.string(), AssertObjectSchema).optional(),
required: z.optional(z.array(z.string())),
additionalProperties: z.optional(z.boolean())

The current constraint prevents describing the response for list and batch requests.
This is noteworthy as the specification does not strictly mandate that the outputSchema must be an object (see: https://modelcontextprotocol.io/specification/draft/server/tools#output-schema).
Consequently, the Python SDK does not enforce this schema constraint on the output.

To Reproduce
Steps to reproduce the behavior:

Let the MCP server return an outputSchema in this format:

         {
            type: "array",
            properties: {
              foo: { type: "string" }
            }
          }

Then an error is thrown:

ZodError: [
  {
    "received": "array",
    "code": "invalid_literal",
    "expected": "object",
    "path": [
      "tools",
      0,
      "outputSchema",
      "type"
    ],
    "message": "Invalid literal value, expected \"object\""
  }
]

Expected behavior
A clear and concise description of what you expected to happen.

Should accept any valid JSONSchema, at least the array one.

Metadata

Metadata

Assignees

Labels

P2Moderate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingfix proposedBot has a verified fix diff in the commentready for workEnough information for someone to start working onv2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions