Skip to content

Conversation

@chr-hertel
Copy link
Member

@chr-hertel chr-hertel commented Aug 1, 2025

Moving over php-mcp/schema which is based on 2025-03-26/schema.ts

Would still apply changes:

  • using library specific exception classes instead of native base classes
  • switching to readonly classes
  • adding phpstan types for array structures
  • [still questionable] - do we need always need all five? construct, make, toArray, fromArray and jsonSerialize
    my2cents: the array structure is needed for json_encode and therefore the jsonSerialize that's the main use case for converting into array - and we have three different ways of constructing those value objects, why?
    my proposal would be to reduce the amount of methods per class to three:
    • __construct(...) for developers to instantiate
    • make(array $data): static for creation from array data
    • jsonSerialize(): array (this would reduce the need to array_map/toArray calls on subobjects since jsonSerialize works recursively)

WDYT @CodeWithKyrian - am I missing something?

Still WIP

@chr-hertel chr-hertel force-pushed the schema branch 3 times, most recently from e79a9d8 to 477cdb1 Compare August 3, 2025 20:14
@CodeWithKyrian
Copy link
Contributor

Yep, I agree with this direction. toArray is mostly just serving jsonSerialize so no point keeping both.

On make(array $data), I’d lean toward sticking with fromArray() as the static factory for array data. make() works better as a convenient constructor alias for devs who prefer Response::make(...) over new Response(...). Of course, with PHP 8.4 now supporting new Response()->method() without the extra parentheses, that pattern is slowly becoming less necessary.

I’m fine with keeping make() if we see it as syntactic sugar, but I’m happy to drop it too if we want to slim things down.

@chr-hertel chr-hertel force-pushed the kicking-off branch 6 times, most recently from ff9c82c to 88c8067 Compare August 4, 2025 22:21
@chr-hertel
Copy link
Member Author

chr-hertel commented Aug 4, 2025

When thinking about updates over time, I feel keeping in sync __construct and make is a bit annoying - also because we're only downstream to that official schema here.

If you give me a 👍 I would update the PR like this:

  • Lib specific exceptions
  • Drop toArray in favor of jsonSerialize
  • No changes to fromArray
  • Drop make in favor of slimming down
  • Add PHPStan array shapes

@chr-hertel chr-hertel force-pushed the schema branch 2 times, most recently from a5bc2a5 to 91bc19c Compare August 5, 2025 20:42
@chr-hertel chr-hertel marked this pull request as ready for review August 5, 2025 20:42
@chr-hertel chr-hertel force-pushed the schema branch 3 times, most recently from 6dd3786 to f7bf9a7 Compare August 5, 2025 21:20
/**
* @author Kyrian Obikwelu <[email protected]>
*/
class Parser
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have this twice still, and also the method string is handled in multiple places, but that's to sort with #3

Base automatically changed from kicking-off to main August 29, 2025 09:10
@chr-hertel chr-hertel closed this Aug 29, 2025
@chr-hertel
Copy link
Member Author

Got merged into main with 6025f89

@chr-hertel chr-hertel deleted the schema branch August 29, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants