[Examples] Demo pre-built instance handlers + inspector coverage (#390)
* [Tests] Bump MCP Inspector to 0.22.0 for 2025-11-25 protocol 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> * [Examples] Demo pre-built instance handler in combined-registration 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> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d187002d87
commit
1fed089d71
1 changed files with 99 additions and 7 deletions
|
|
@ -217,14 +217,20 @@ npx @modelcontextprotocol/inspector http://localhost:8000
|
|||
**What it demonstrates:**
|
||||
- Mixing attribute discovery with manual registration
|
||||
- HTTP server with both discovered and manual capabilities
|
||||
- Flexible registration patterns
|
||||
- All three handler styles: discovered, `[Class::class, 'method']`, and a pre-built `[$instance, 'method']`
|
||||
- Pre-built instance handlers for classes the container cannot auto-wire (e.g. constructor scalars)
|
||||
|
||||
**Key Features:**
|
||||
```php
|
||||
// Built here so its constructor dependencies are injected before registration;
|
||||
// the SDK invokes this very instance instead of constructing one itself.
|
||||
$preconfiguredGreeter = new PreconfiguredGreeter('Willkommen', logger());
|
||||
|
||||
$server = Server::builder()
|
||||
->setDiscovery(__DIR__, ['.']) // Automatic discovery
|
||||
->addTool([ManualHandlers::class, 'manualGreeter']) // Manual registration
|
||||
->addResource([ManualHandlers::class, 'getPriorityConfig'], 'config://priority')
|
||||
->setDiscovery(__DIR__, ['.']) // Automatic discovery
|
||||
->addTool([ManualHandlers::class, 'manualGreeter']) // Manual class-string handler
|
||||
->addTool([$preconfiguredGreeter, 'greet'], 'instance_greeter') // Pre-built instance handler
|
||||
->addResource([ManualHandlers::class, 'getPriorityConfigManual'], 'config://priority')
|
||||
```
|
||||
|
||||
### Complex Tool Schema
|
||||
|
|
|
|||
Loading…
Reference in a new issue