php-sdk/examples/client
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Johannes Wachter e4a8a224ff
[Client] Add client-side elicitation support (#371)
* [Client] Add client-side elicitation support

The SDK could send elicitation/create requests from a server tool via
ClientGateway::elicit(), but the client could not receive them: there was
no request handler, and ElicitRequest was not registered in MessageFactory,
so incoming elicitation/create messages failed to parse.

This adds the client half, mirroring the existing Sampling pattern:

- Register ElicitRequest in MessageFactory so elicitation/create parses.
- ElicitationRequestHandler wraps a user callback and returns an
  ElicitResult (accept/decline/cancel) or an Error.
- ElicitationCallbackInterface defines the callback contract.
- ElicitationException forwards a specific message to the server; any
  other throwable returns a generic error.

Includes unit tests, a runnable client example against the elicitation
demo server, and client docs/README updates.

* [Client] Simplify elicitation example labelFor() per review

Type the parameter as AbstractSchemaDefinition and read ->title directly
instead of matching on each concrete definition type. title is a required
non-null string on the base class, so the match and the $name fallback were
redundant.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-14 23:55:06 +02:00
..
http_client_communication.php CS update after release of v3.95 (#282) 2026-04-26 12:39:27 +02:00
http_discovery_calculator.php CS update after release of v3.95 (#282) 2026-04-26 12:39:27 +02:00
README.md [Client] Feat: Implement MCP client component (#192) 2026-03-10 17:22:40 +01:00
stdio_client_communication.php CS update after release of v3.95 (#282) 2026-04-26 12:39:27 +02:00
stdio_discovery_calculator.php CS update after release of v3.95 (#282) 2026-04-26 12:39:27 +02:00
stdio_elicitation.php [Client] Add client-side elicitation support (#371) 2026-07-14 23:55:06 +02:00

Client Examples

These examples demonstrate how to use the MCP PHP Client SDK.

STDIO Client

Connects to an MCP server running as a child process:

php examples/client/stdio_discovery_calculator.php

HTTP Client

Connects to an MCP server over HTTP:

# First, start an HTTP server
php -S localhost:8000 examples/server/discovery-calculator/server.php

# Then run the client
php examples/client/http_discovery_calculator.php

Requirements

All examples require the server examples to be available. The STDIO examples spawn the server process, while the HTTP examples connect to a running HTTP server.