php-sdk/examples/client
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Christopher Hertel 7fe88677ad
[Docs][Examples][CI] Document and gate the 2026-07-28 lifecycle (#457)
docs/stateless-lifecycle.md walks the revision end to end - per-request
_meta, server/discover, multi round-trip requests, caching and subscriptions
- and a runnable example on each side shows what that looks like in code.

CI matrixes both conformance roles over both revisions. --spec-version is
cumulative across the dated revisions, so 2025-11-25 covers the two before
it; 2026-07-28 is not cumulative with them and needs its own run against its
own baseline. The runner is pinned so a PR only goes red for reasons in the
PR, and conformance-weekly tracks the moving target instead - on both
revisions, since the draft scenarios ship only on the alpha dist-tag.

The Inspector cannot reach a modern-lifecycle server (it opens with
initialize), so the example is covered by integration tests instead: one
drives it with hand-built HTTP the way a conforming client would, one drives
it with this SDK's client, and one drives the single endpoint from both eras.
2026-08-19 03:24:17 +02:00
..
http_client_communication.php [Schema][Server] Harden sampling tools against the spec (#420) 2026-08-15 04:13:53 +02:00
http_discovery_calculator.php CS update after release of v3.95 (#282) 2026-04-26 12:39:27 +02:00
README.md [Docs][Examples][CI] Document and gate the 2026-07-28 lifecycle (#457) 2026-08-19 03:24:17 +02:00
stateless_lifecycle_client.php [Docs][Examples][CI] Document and gate the 2026-07-28 lifecycle (#457) 2026-08-19 03:24:17 +02:00
stdio_client_communication.php [Schema][Server] Harden sampling tools against the spec (#420) 2026-08-15 04:13:53 +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
stdio_roots.php [Client][Server] Add Roots support (#395) 2026-08-14 23:04:25 +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

Modern-era client (2026-07-28)

Speaks the stateless lifecycle: no initialize, a _meta envelope and SEP-2243 headers on every request, and multi round-trip calls answered by the client without the caller noticing.

# First, start the matching server
php -S 127.0.0.1:8000 examples/server/stateless-lifecycle/server.php

# Then run the client
php examples/client/stateless_lifecycle_client.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.