#5013·hindsight

MCP tool schemas are recursive, and a provider that rejects recursive JSON Schema fails the whole turn

Author: gutocarolloCreated Oct 1, 2026Updated Oct 1, 2026

Summary

Four MCP tools advertise a recursive inputSchema (a $ref that closes a cycle). Valid JSON Schema — but some consumers reject it, and the rejection is not per-tool: it fails the whole request. The Meta model API answers

400 Recursive JSON schemas are not currently supported (invalid_request_error)

failure_retryable=false, so the agent's entire turn dies the moment it discovers one of these tools (tool_search / tools/list). This makes the mental-model and knowledge-page tools unusable from any MCP client that forwards tool schemas to such a provider.

Affected tools

On the lessons//mcp server (hindsight-api-slim), exactly 4 of 36 tools carry the recursion. All four take MentalModelTriggerInput:

  • create_mental_model
  • update_mental_model
  • create_knowledge_page
  • update_knowledge_node

The other 32 tools — and all tools of the other transports in the same deployment — are clean. No tool has a recursive outputSchema.

Evidence chain

1. The cycle in the wire schema

Captured from a live server (initialize + tools/list):

create_mental_model
└─ .trigger → { "$ref": "#/$defs/MentalModelTriggerInput" }
   └─ .tag_groups.items → anyOf[1] → { "$ref": "#/$defs/TagGroupAnd" }
      └─ .and.items.anyOf[1] → { "$ref": "#/$defs/TagGroupAnd" }   ← self-reference

TagGroupOr and TagGroupNot close the same loop (or → TagGroupOr, not → TagGroupNot).

2. Where it comes from

hindsight_api/mcp_tools.py:

python
class MentalModelTriggerInput(BaseModel):
    ...
    tag_groups: list[TagGroup] | None = Field(default=None, ...)

hindsight_api/engine/search/tags.py — TagGroup is a recursive union:

python
class TagGroupAnd(BaseModel):
    filters: list[TagGroup] = Field(alias="and")
class TagGroupOr(BaseModel):
    filters: list[TagGroup] = Field(alias="or")
class TagGroupNot(BaseModel):
    filter: TagGroup = Field(alias="not")

TagGroup = Annotated[TagGroupLeaf | TagGroupAnd | TagGroupOr | TagGroupNot, Field(union_mode="left_to_right")]

Pydantic serialises that as $defs plus a $ref that points back into itself. FastMCP publishes it verbatim as the tool's inputSchema.

3. Minimal reproduction

Any MCP client that reads the tool list and forwards schemas to a provider with a recursive-schema restriction reproduces it. The schema alone reproduces it:

python
import asyncio, json
from typing import Annotated, Literal
from fastmcp import FastMCP
from pydantic import BaseModel, ConfigDict, Field

class TagGroupLeaf(BaseModel):
    tags: list[str]
    match: Literal["any", "all", "any_strict", "all_strict", "exact"] = "any_strict"

class TagGroupAnd(BaseModel):
    model_config = ConfigDict(populate_by_name=True, serialize_by_alias=True)
    filters: list["TagGroup"] = Field(alias="and")

class TagGroupOr(BaseModel):
    model_config = ConfigDict(populate_by_name=True, serialize_by_alias=True)
    filters: list["TagGroup"] = Field(alias="or")

class TagGroupNot(BaseModel):
    model_config = ConfigDict(populate_by_name=True, serialize_by_alias=True)
    filter: "TagGroup" = Field(alias="not")

TagGroup = Annotated[TagGroupLeaf | TagGroupAnd | TagGroupOr | TagGroupNot, Field(union_mode="left_to_right")]
TagGroupAnd.model_rebuild(); TagGroupOr.model_rebuild(); TagGroupNot.model_rebuild()

class MentalModelTriggerInput(BaseModel):
    mode: Literal["full", "delta"] | None = None
    tag_groups: list[TagGroup] | None = None

mcp = FastMCP("repro")

@mcp.tool
def create_mental_model(name: str, trigger: MentalModelTriggerInput | None = None) -> dict:
    """Create."""
    return {}

tool = next(v for k, v in mcp._local_provider._components.items() if "create_mental_model" in k)
schema = tool.parameters
print(sorted(schema["$defs"]))
# ['MentalModelTriggerInput', 'TagGroupAnd', 'TagGroupLeaf', 'TagGroupNot', 'TagGroupOr']
# MentalModelTriggerInput.tag_groups -> $ref TagGroupAnd -> $ref TagGroupAnd  (cycle)

4. Observed impact (real client)

In a harvested session log, the turn that loaded the tools is the turn that dies:

tool_search returned 50 tool(s)          # includes the 4 above
...
API error 400 [request_id=...]: Recursive JSON schemas are not currently supported (invalid_request_error)

Versions

  • Affected: 0.9.2? No — the trigger parameter does not exist there. 0.10.0 onward, including 0.10.1, 0.10.2, and current main.
  • hindsight-api-slim 0.10.2, fastmcp 3.2.0.

Expected vs actual

  • Expected: tools/list returns a schema every client can read; discovering a tool never fails a request.
  • Actual: 4 tools carry a recursive schema, and a consumer that rejects recursive schemas rejects the entire request.

Proposed fix

A PR follows immediately: dereference the tool schemas at registration so recursion is cut with a permissive (empty) schema at the point a cycle would close. Result is acyclic by construction, still describes every finite instance, and only the 4 affected tools change (~1.9x each; the other 35 are byte-identical).