Skip to content

Inline $ref in tool inputSchema for LLM consumption (parity with typescript-sdk) #2384

@felixweinberger

Description

@felixweinberger

tools/base.py:76 uses raw model_json_schema() which emits $ref/$defs for nested Pydantic models. LLM clients consuming tools/list often can't resolve $ref, leading to params being passed as stringified JSON instead of structured objects.

Repro / demand: anthropics/claude-code#18260 (Notion MCP server, $ref params get stringified by the model).

typescript-sdk addresses this in modelcontextprotocol/typescript-sdk#1563 by adding a dereferenceLocalRefs() step that inlines local $ref and throws on cycles (matching go-sdk precedent). Python should do the equivalent in the tool schema pipeline so all SDKs emit LLM-consumable schemas.

Relevant file: src/mcp/server/mcpserver/tools/base.py:76

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions