feat(mcp-server): expose polymorphic relations in describeCollection#1551
Open
feat(mcp-server): expose polymorphic relations in describeCollection#1551
Conversation
4 new issues
|
Detect polymorphic_referenced_models from forest-rails schema and expose isPolymorphic + polymorphicTargets in the describeCollection response. This allows LLMs to know they need to pass both _id and _type fields when creating/updating records with polymorphic relations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dcd311f to
062f4b8
Compare
|
Coverage Impact This PR will not change total coverage. Modified Files with Diff Coverage (3)
🛟 Help
|
…improve type safety - Filter actions without valid endpoints from describeCollection and getActionEndpoints to prevent 404 errors when the LLM tries to execute them - Fix "layout is not iterable" crash in agent-client when backend returns no layout in hook change responses - Add polymorphic-referenced-models to ForestSchemaField type, removing unsafe double cast - Make ResponseBody.layout optional to match runtime behavior - Add debug logging for schema loading and warn for actions without endpoints at startup Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Scra3
commented
Apr 14, 2026
| export type ResponseBody = { | ||
| fields: PlainField[]; | ||
| layout: ForestServerActionFormLayoutElement[]; | ||
| layout?: ForestServerActionFormLayoutElement[]; |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…getActionEndpoints Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…warning Actions without endpoints are now reported in describeCollection's _meta.skippedActions with name and reason, so the LLM can inform users. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…e-dangle) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…odels The Forest Admin server returns polymorphicReferencedModels in camelCase after JSON:API deserialization, not kebab-case. The previous key 'polymorphic-referenced-models' was always undefined in production, silently disabling polymorphic relation detection. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rom @@@ to : The filters description incorrectly told the LLM to use @@@ for relation fields, but the backend expects : (e.g. "relation:field"). The @@@ separator is only used internally by QuerySerializer for field projections. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…cription Warn the LLM not to filter via relation:field on polymorphic relations (returns 500) and explain the two-step approach using _type and _id. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace "returns 500" with "is not supported and will fail" since the error code varies depending on the backend agent. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
polymorphic-referenced-modelsfrom forest-rails schema indescribeCollectionisPolymorphic: trueandpolymorphicTargets: ['Post', 'Video']in the relation outputtargetCollection: nullfor polymorphic relations (since the reference name isn't a real collection)Why
When a Ruby agent has polymorphic relations (e.g.
commentableoncomments), the MCP server didn't expose this info. LLMs couldn't know they need to pass bothcommentable_idANDcommentable_typefor create/update, or thatlistRelatedwon't work on polymorphic BelongsTo relations.Example output
{ "relations": [ { "name": "commentable", "type": "many-to-one", "targetCollection": null, "isPolymorphic": true, "polymorphicTargets": ["Post", "Video"] } ] }Test plan
🤖 Generated with Claude Code
Note
Expose polymorphic relations in
describeCollectionMCP tool outputdescribeCollectionnow includeisPolymorphic: trueandpolymorphicTargetswhenpolymorphicReferencedModelsis present on a field;targetCollectionis set tonullfor these relations.actionsarray and surfaced in_meta.skippedActionswith reason'no endpoint configured';getActionEndpointsalso skips endpoint-less actions.FieldFormStateswhen a change-hook response omitslayout, by treating missing layout as an empty array.listtool are updated to explain the:separator for relation fields and limitations for polymorphic relations.Macroscope summarized 9c21c01.