Skip to content

[Examples] Demo pre-built instance handlers + inspector coverage#390

Merged
chr-hertel merged 2 commits into
mainfrom
demo/instance-handler-example
Jul 14, 2026
Merged

[Examples] Demo pre-built instance handlers + inspector coverage#390
chr-hertel merged 2 commits into
mainfrom
demo/instance-handler-example

Conversation

@chr-hertel

@chr-hertel chr-hertel commented Jul 5, 2026

Copy link
Copy Markdown
Member

Follow-up to #375 (now merged): demonstrates the pre-built instance handler form it added, and gives it functional (inspector snapshot) coverage.

What & why

#375 makes ->addTool([$instance, 'method']) work — a handler registered as an already-constructed object. This PR gives that feature a home in the examples and a functional test.

The combined-registration example was the natural fit: it already showcases discovered and manual class-string handlers, so adding the pre-built instance form completes the trio.

Changes

  • examples/server/combined-registration/PreconfiguredGreeter.php — a handler whose constructor takes a scalar string $greeting. Neither the container-less new $className() fallback nor the SDK's auto-wiring Container can build it (built-in types are explicitly unresolvable), so it can only be registered as a pre-built instance — a crisp demonstration of exactly why the feature exists.
  • server.php — registers it via ->addTool([$preconfiguredGreeter, 'greet'], 'instance_greeter').
  • Inspector test + snapshots — new tools/call instance_greeter case in HttpCombinedRegistrationTest, plus updated tools/list snapshot.
  • Docs — updated the Combined Registration walkthrough in docs/examples.md and clarified the instance-handler form's purpose in docs/server-builder.md.

Separate infra fix (commit [Tests] Bump MCP Inspector to 0.22.0)

The pinned MCP Inspector 0.17.2 predates the 2025-11-25 protocol bump (v0.6.0) and rejects the handshake (Server's protocol version is not supported) — this currently errors every inspector snapshot test. Bumped to 0.22.0, which negotiates the current protocol. Happy to split this into a standalone PR if preferred.

Verification

  • Full inspector suite against 0.22.0: 95 tests, 7 pre-existing skips, 0 failures.
  • php-cs-fixer clean, PHPStan clean.

🤖 Generated with Claude Code

chr-hertel and others added 2 commits July 6, 2026 01:14
The pinned inspector 0.17.2 predates the protocol version bump to
2025-11-25 (v0.6.0) and rejects the handshake with "Server's protocol
version is not supported", failing every inspector snapshot test. 0.22.0
negotiates the current protocol; the full inspector suite passes against
it (95 tests, 7 pre-existing skips).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Extends the combined-registration example with a third handler style:
a pre-built object instance `[$instance, 'method']`, alongside the
existing discovered and manual class-string handlers. PreconfiguredGreeter
takes a scalar constructor argument neither the container-less
`new $className()` fallback nor the auto-wiring container can build, so it
can only be registered as an already-constructed instance — exercising the
resolver path added in the parent branch.

Adds an inspector snapshot case (tools/call instance_greeter) and updates
the tools/list snapshot.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chr-hertel chr-hertel force-pushed the demo/instance-handler-example branch from 959e0e1 to d237769 Compare July 5, 2026 23:15
@chr-hertel chr-hertel added this to the 0.7.0 milestone Jul 5, 2026
@chr-hertel chr-hertel merged commit 1fed089 into main Jul 14, 2026
20 checks passed
@chr-hertel chr-hertel deleted the demo/instance-handler-example branch July 14, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Examples Issues & PRs related to examples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant