php-sdk/tests/Unit/Capability/Discovery
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Valery Gutu 55f7884368
[Server] Allow pre-built instance handlers in element registration (#375)
* Allow pre-built instance handlers in element registration

`HandlerResolver::resolve()` rejected `[$instance, 'methodName']` array
handlers even though the `Handler` type alias and the runtime invoker
already support them, so `Server::builder()->addTool(handler: [$obj, 'bar'])`
threw "Invalid array handler format" at build time.

Relax the array-shape guard to accept an object in slot 0 and normalize it
to its class name for reflection (the same idiom getHandlerDescription()
already uses). This unblocks dependency-injected handler objects that the
container-less `new $className()` fallback cannot build.

Fixes #369

* Use 0.6.1 changelog heading and test instance handler end-to-end

This is a bugfix with no new public API or BC break, so the changelog
entry belongs under 0.6.1 rather than a new 0.7.0 section.

Add an end-to-end test that registers a pre-built instance handler with a
constructor dependency the container-less new $className() fallback cannot
satisfy, then drives a real tools/call through CallToolHandler and asserts
the injected instance is the one invoked.

* Address review: reject Closure array handlers, fix abstract-method message

- HandlerResolver: extract the array-handler guard into a readable
  $hasValidTarget check that accepts strings and objects but excludes
  \Closure, so [$closure, 'method'] falls through to the format error
  instead of the misleading "method not found in class Closure".
- Fix the abstract-method rejection message ("must be abstract" ->
  "must not be abstract"), a pre-existing typo in the same branch.
- Tighten the CHANGELOG entry wording.
- Cover Closure rejection with a regression test.

* Move instance-handler entry under 0.7.0 changelog heading

Per review: registering pre-built instance handlers is a feature, not a
patch, so it belongs in a minor release heading.
2026-07-06 01:13:41 +02:00
..
Fixtures [Server] Allow overriding the default file name pattern for Discovery (#292) 2026-05-08 09:48:29 +02:00
CachedDiscovererTest.php fix: because the cached discoveryState does not use ->setDiscoveryState(), it is found that the discoveryState cannot be used (#120) 2025-10-26 23:25:09 +01:00
DiscovererToolTitleTest.php [Schema][Server] Add top-level title to Tool (#288) 2026-04-26 15:37:40 +02:00
DiscoveryStateTest.php [Server] Allow runtime-resolved element handlers (#294) 2026-05-29 07:16:12 +02:00
DiscoveryTest.php [Server] Untangle origin tracking from Registry (#302) 2026-05-17 14:03:31 +02:00
DocBlockParserTest.php style: apply php-cs-fixer and PHPStan fixes (#289) 2026-04-20 20:49:15 +02:00
DocBlockTestFixture.php feat: Add output schema support to MCP tools (#153) 2026-01-11 21:14:48 +01:00
HandlerResolverTest.php [Server] Allow pre-built instance handlers in element registration (#375) 2026-07-06 01:13:41 +02:00
SchemaGeneratorFixture.php feat: Add output schema support to MCP tools (#153) 2026-01-11 21:14:48 +01:00
SchemaGeneratorTest.php fix: Cannot pass null to nullable enum parameters (#299) 2026-05-08 10:15:14 +02:00
SchemaValidatorTest.php style: apply php-cs-fixer and PHPStan fixes (#289) 2026-04-20 20:49:15 +02:00