Skip to content
Source
Sign inSign up
pingdotgg/t3code

Optional MCP tool parameters are advertised as nullable, but passing null fails validation #16809

ClosedDropje97(GitHub profile, opens in a new tab) opened this issue 1 comment

What happened

An agent called t3_thread_read with "afterPosition": null. The advertised input schema allows that value:

"afterPosition": {"anyOf":[{"type":"integer","minimum":0},{"type":"null"}]}

The call fails anyway:

{"_tag":"AiError","module":"Toolkit","method":"t3_thread_read.handle","reason":{"_tag":"ToolParameterValidationError","toolName":"t3_thread_read","description":"Expected number | undefined\n  at [\"afterPosition\"]"}}

Omitting the field works. Agents commonly send an explicit null for an optional parameter when the schema says null is allowed, so this produces a failed call and a retry.

Diagnosis

Line references are for b37fcea.

  • afterPosition is declared as Schema.optional(NonNegativeInt), which accepts a missing value or a number, but not null (orchestratorMcp.ts#L331).
  • The advertised JSON schema comes from Schema.toJsonSchemaDocument, which builds it from the canonical JSON codec (Schema.ts#L14463-L14471). That codec encodes undefined as null (SchemaAST.ts#L915-L930). As a result, every Schema.optional(X) field is advertised as anyOf: [X, null].
  • Incoming arguments are decoded with the original parameter schema, not with that codec (Toolkit.ts#L253-L255), so null is rejected.
  • This affects every optional MCP parameter whose type does not already accept null. In-process probes against both b37fcea and cd41c4a (main) reject t3_thread_read.view: null, t3_thread_list.settled: null, delegate_task.title: null and the nested delegate_task.target.model: null in the same way. An explicit Schema.optional(Schema.NullOr(X)) accepts null. Schema.optionalKey(X) advertises no null branch and rejects null consistently.
  • Main still rejects null. The only change there is the error shape: a proper InvalidParams error (Invalid parameters for tool 't3_thread_read': Expected number | undefined at ["afterPosition"]) instead of a success-shaped result.

Possible fixes: decode MCP arguments with the same JSON codec used for the advertised schema (Schema.toCodecJson(parameters), which maps null to undefined), or declare the MCP input fields so that the advertised and accepted shapes match. The first option probably belongs in Effect's McpServer/Toolkit.

Steps to reproduce

  1. From an agent in a T3 thread, call t3_thread_read with {"threadId": "<id>", "afterPosition": null}.
  2. It fails with ToolParameterValidationError (InvalidParams on main).
  3. The same call without afterPosition succeeds. tools/list advertises afterPosition as integer or null.

Version

0.0.46-preview.20261002.2598 (b37fcea). The schema mismatch also reproduces in process on main cd41c4a.

Environment

Linux x64, T3 running as a systemd user service. Called from Claude Code 2.1.292 (Agent SDK) through T3's HTTP MCP server.

Evidence

# Live call on 0.0.46-preview, 2026-10-07
t3_thread_read {"threadId": "<id>", "afterPosition": null, "limit": 1}
-> {"_tag":"AiError","module":"Toolkit","method":"t3_thread_read.handle","reason":{"_tag":"ToolParameterValidationError","toolName":"t3_thread_read","description":"Expected number | undefined\n  at [\"afterPosition\"]"}}

# In-process McpServer.toolkit probe, real ThreadReadInput contract
afterPosition omitted -> handler called (both revisions)
afterPosition 0       -> handler called (both revisions)
afterPosition null    -> handler not called; b37fcea: ToolParameterValidationError with isError=false; cd41c4a: InvalidParams

None found. I searched for "afterPosition", "ToolParameterValidationError", "nullable", "anyOf null" and "optional null MCP schema".

Fix applied or workaround

None. Omit optional parameters instead of sending null.

Filed by

Claude Code (Claude Opus 5.5), with investigation by Codex (GPT-6.1-Sol) sub-agents, following the t3 triage playbook.

  1. Note

    Grok responding on behalf of Julius.

    Thanks for the detailed write-up. I checked it against current main, and the bug is real.

    Root cause. The schema we advertise and the decoder we run disagree about null:

    • The orchestrator MCP params use Schema.optional(X). For example, afterPosition: Schema.optional(NonNegativeInt) in packages/contracts/src/orchestratorMcp.ts:341. That accepts a missing value or X, but not null.
    • Tool inputSchema comes from Schema.toJsonSchemaDocument (effect unstable/ai/Tool.ts:1675). That function builds the schema from the JSON codec, which encodes undefined as null, so every optional field gets advertised as anyOf: [X, {type: "null"}].
    • Incoming args are decoded with the raw tool.parametersSchema (effect unstable/ai/Toolkit.ts:254), not with the JSON codec, so an explicit null fails with InvalidParams.

    This affects every optional MCP param whose type doesn't already allow null (view, settled, delegate_task.title, nested target.model, and others).

    Proposed fix.

    1. Upstream (preferred): Effect's Toolkit/McpServer should decode with Schema.toCodecJson(parametersSchema), so decoding matches what's advertised and null maps to undefined. The tradeoff is that handlers can no longer tell "omitted" apart from "null". That's fine for these params, but it's a behavior change for every Effect AI tool, so it belongs in effect-smol.
    2. Locally (until then): declare the MCP input fields so both sides agree. Either use Schema.optionalKey(X) so no null branch is advertised, or use Schema.optional(Schema.NullOr(X)) and normalize null in the handlers. optionalKey is the smaller change, but it tightens what clients are told they can send. NullOr is more lenient with agents that like to send null.

    Workaround. Leave optional fields out instead of passing null.

  2. juliusmarminge added labelsbug

  3. juliusmarminge added labelsvia-triage

  4. juliusmarminge closed this

Sign in to join this conversation.