Skip to content

fix(provider): expand $ref/$defs for DeepSeek compatibility#32955

Open
lexlian wants to merge 2 commits into
anomalyco:devfrom
lexlian:fix/deepseek-refs
Open

fix(provider): expand $ref/$defs for DeepSeek compatibility#32955
lexlian wants to merge 2 commits into
anomalyco:devfrom
lexlian:fix/deepseek-refs

Conversation

@lexlian

@lexlian lexlian commented Jun 19, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #32829
Closes #29220

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

DeepSeek API rejects JSON Schema 2020-12 $ref pointers in MCP tool schemas, causing AttributeError: 'NoneType' object has no attribute 'lookup' when using MCP servers with $defs references (Asana, Notion).

This PR adds expandRefs() to ProviderTransform.schema() that inlines $ref targets from $defs/definitions before sending schemas to DeepSeek. It handles nested $ref references, preserves override fields on referencing nodes (e.g. a description on the $ref node wins over the definition's description), and guards against circular references via a seen set.

The approach mirrors PR #12292 (closed, not merged) which proposed the same fix for Gemini.

How did you verify your code works?

  • bun typecheck — pass (full repo typecheck via turbo)
  • bun test test/provider/transform.test.ts — 255 pass, 0 fail (7 new tests added)

Tests added:

  • Expands simple $ref with $defs
  • Expands nested $ref references
  • Handles circular $ref
  • Preserves description when expanding $ref
  • Expands definitions (legacy format)
  • Does not expand $ref for non-DeepSeek providers
  • Expands $ref in array items

Screenshots / recordings

N/A — non-UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

DeepSeek API rejects JSON Schema 2020-12 \$ref pointers in MCP tool
schemas, causing AttributeError: 'NoneType' object has no attribute
'lookup' when using MCP servers with \$defs references (Asana, Notion).

Adds expandRefs() that inlines \$ref targets from \$defs/definitions
before sending schemas to DeepSeek. Handles nested \$refs, preserves
override fields on referencing nodes, and guards against circular
refs.

Closes anomalyco#32829
Closes anomalyco#29220 (duplicate)

fix: expand \$ref references in JSON Schema for DeepSeek compatibility
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 19, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Resolve conflict in transform.ts: keep both expandRefs (DeepSeek)
and sanitizeOpenAISchema (OpenAI) sanitization functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant