Add PropertyDescriberInterface extension point for SchemaGenerator#314
Open
peter-si wants to merge 1 commit into
Open
Add PropertyDescriberInterface extension point for SchemaGenerator#314peter-si wants to merge 1 commit into
peter-si wants to merge 1 commit into
Conversation
3f148f3 to
cd2ef84
Compare
Lets callers teach SchemaGenerator how to render specific value-object
types (DateTime, Uuid, Money, ...) as more useful JSON Schema fragments
than the generic `{type: "object"}` fallback. Describers are consulted,
in order, for class-typed parameters before generic class inspection.
The first non-null result wins; description / default / nullable are
layered onto the described schema without overwriting it.
Ships two default describers in `Mcp\Capability\Discovery\PropertyDescriber\`:
- DateTimePropertyDescriber → {type: "string", format: "date-time"}
- UuidPropertyDescriber → {type: "string", format: "uuid"}
The new constructor parameter defaults to an empty iterable, so existing
callers stay unaffected.
cd2ef84 to
972bb42
Compare
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
Adds a
PropertyDescriberInterfaceextension point toSchemaGeneratorso callers can teach it how to render specific class types (DateTime,Uuid, domain value objects) as targeted JSON Schema fragments rather than the generic{type: "object"}fallback.Describers are consulted, in order, for class-typed parameters before generic class inspection. The first non-null result wins; parameter-level metadata (description, default, nullable) is layered onto the described schema without overwriting fields the describer already set.
Ships two default describers:
Mcp\Capability\Discovery\PropertyDescriber\DateTimePropertyDescriber— any\DateTimeInterfaceimplementation →{type: "string", format: "date-time"}Mcp\Capability\Discovery\PropertyDescriber\UuidPropertyDescriber—Symfony\Component\Uid\Uuidand subclasses →{type: "string", format: "uuid"}Why
If an MCP tool method takes e.g.
\DateTimeInterface \$until, the generator currently falls back to{type: "object"}, which tells the LLM nothing about the expected shape and forces ad-hoc workarounds in every tool. The describer chain gives a clean extension point for the long tail of value-object types every project has, without needing to subclass or fork `SchemaGenerator`.Downstream we extend the chain further with app-specific types (Money, PhoneNumber, ...), but the two shipped here are general enough that they feel like they belong upstream.
Backwards compatibility
Tests
🤖 Generated with Claude Code