|
1 | 1 | # Changelog |
2 | 2 |
|
3 | 3 | All notable changes to `php-mcp/client` will be documented in this file. |
| 4 | + |
| 5 | +## v1.0.0 - 2025-05-06 |
| 6 | + |
| 7 | +### v1.0.0 - Initial Release |
| 8 | + |
| 9 | +🚀 **Introducing `php-mcp/client` v1.0.0!** |
| 10 | + |
| 11 | +I'm thrilled to announce the first stable release of the PHP client library for the Model Context Protocol (MCP). Following the release of [`php-mcp/server`](https://github.com/php-mcp/server), this package provides the other essential piece, enabling your PHP applications to easily connect to and interact with any MCP-compliant server. |
| 12 | + |
| 13 | +It offers a robust, flexible, and developer-friendly solution designed specifically for the PHP ecosystem. |
| 14 | + |
| 15 | +#### ✨ Key Features |
| 16 | + |
| 17 | +* **Client-per-Server Architecture:** Aligns with the MCP specification's core model where each `Client` instance manages a dedicated, stateful connection to a single configured MCP server. |
| 18 | +* **Fluent Configuration Builder:** Set up client instances easily using the `Client::make()->with...()->build()` pattern, configuring client identity, capabilities, and the specific server connection details (`ServerConfig`). |
| 19 | +* **Dual API for Flexibility:** |
| 20 | + * **Synchronous Facade:** Interact with MCP servers using straightforward, blocking methods (e.g., `$client->initialize()`, `$client->listTools()`, `$client->callTool(...)`) for simple integration into traditional PHP scripts and frameworks. The underlying asynchronous complexity is handled internally. |
| 21 | + * **Asynchronous API:** Access Promise-based methods (e.g., `$client->initializeAsync()`, `$client->listToolsAsync()`, `$client->callToolAsync(...)`) for advanced use cases, concurrent operations using `React\Promise\all`, or integration into asynchronous PHP applications (ReactPHP, Amp, Swoole). |
| 22 | + |
| 23 | +* **Multiple Transport Support:** |
| 24 | + * **`stdio`:** Seamlessly connect to and manage local MCP server processes via standard input/output, ideal for command-line tools or embedded servers. Uses `react/child-process` internally. |
| 25 | + * **`http`:** Connect to remote or local MCP servers over HTTP, handling POST requests for client messages and Server-Sent Events (SSE) for server messages and notifications. Uses `react/http` internally. |
| 26 | + |
| 27 | +* **Explicit Connection Lifecycle:** Clear methods (`initialize`/`initializeAsync`, `disconnect`/`disconnectAsync`) to manage the stateful connection and MCP handshake process. |
| 28 | +* **Full MCP Core Feature Support:** Implements core MCP operations: |
| 29 | + * Capability Negotiation (`initialize`) |
| 30 | + * Listing Tools, Resources, Prompts, Resource Templates |
| 31 | + * Calling Tools (`tools/call`) |
| 32 | + * Reading Resources (`resources/read`) |
| 33 | + * Getting Prompts (`prompts/get`) |
| 34 | + * Resource Subscriptions (`resources/subscribe`, `resources/unsubscribe`) *(Requires server capability)* |
| 35 | + * Server Log Level Control (`logging/setLevel`) *(Requires server capability)* |
| 36 | + * Connectivity Check (`ping`) |
| 37 | + |
| 38 | +* **PSR Compliance:** |
| 39 | + * Integrates with `PSR-3 (LoggerInterface)` for flexible logging. |
| 40 | + * Supports optional `PSR-16 (SimpleCacheInterface)` for caching server definitions (tools, resources, etc.) via `DefinitionCache`. |
| 41 | + * Supports optional `PSR-14 (EventDispatcherInterface)` for handling server-sent notifications (e.g., `ResourceChanged`, `ToolsListChanged`) asynchronously. |
| 42 | + |
| 43 | +* **Robust Error Handling:** Provides a hierarchy of specific exceptions (`ConfigurationException`, `ConnectionException`, `HandshakeException`, `RequestException`, `TimeoutException`, `TransportException`, `UnsupportedCapabilityException`, etc.) for predictable error management. |
| 44 | +* **Asynchronous Core:** Built on ReactPHP's event loop and promises for efficient, non-blocking I/O handling crucial for `stdio` and `http+sse` transports. |
| 45 | + |
| 46 | +#### 🚀 Getting Started |
| 47 | + |
| 48 | +1. **Install:** |
| 49 | + |
| 50 | + ```bash |
| 51 | + composer require php-mcp/client |
| 52 | + |
| 53 | + ``` |
| 54 | +2. **Configure:** Define your server connection using `ServerConfig` and build a client instance. |
| 55 | + |
| 56 | + ```php |
| 57 | + use PhpMcp\Client\Client; |
| 58 | + use PhpMcp\Client\Enum\TransportType; |
| 59 | + use PhpMcp\Client\Model\ClientInfo; |
| 60 | + use PhpMcp\Client\ServerConfig; |
| 61 | + |
| 62 | + $serverConfig = new ServerConfig( |
| 63 | + name: 'my_stdio_server', |
| 64 | + transport: TransportType::Stdio, |
| 65 | + command: ['php', '/path/to/your/mcp_server.php'], |
| 66 | + timeout: 15 |
| 67 | + ); |
| 68 | + |
| 69 | + $clientInfo = new ClientInfo('MyPHPApp', '1.0'); |
| 70 | + |
| 71 | + $client = Client::make() |
| 72 | + ->withClientName($clientInfo->name) // Pass name/version directly |
| 73 | + ->withClientVersion($clientInfo->version) |
| 74 | + ->withServerConfig($serverConfig) |
| 75 | + // ->withLogger(new MyLogger()) // Optional |
| 76 | + ->build(); |
| 77 | + |
| 78 | + ``` |
| 79 | +3. **Initialize & Interact (Sync Example):** |
| 80 | + |
| 81 | + ```php |
| 82 | + try { |
| 83 | + $client->initialize(); // Connect & Handshake (blocks) |
| 84 | + $tools = $client->listTools(); // Make request (blocks) |
| 85 | + print_r($tools); |
| 86 | + // ... other interactions ... |
| 87 | + } catch (\Throwable $e) { |
| 88 | + echo "Error: " . $e->getMessage(); |
| 89 | + } finally { |
| 90 | + $client->disconnect(); // Disconnect (blocks) |
| 91 | + } |
| 92 | + |
| 93 | + ``` |
| 94 | +
|
| 95 | +#### Documentation & Examples |
| 96 | +
|
| 97 | +Please refer to the [README.md](README.md) for detailed usage instructions, configuration options, explanations of the sync vs. async APIs, error handling, and more. |
| 98 | +
|
| 99 | +Working examples can be found in the [`examples/`](./examples/) directory, covering: |
| 100 | +
|
| 101 | +* Basic synchronous stdio (`01-simple-stdio-sync.php`) |
| 102 | +* Basic synchronous http (`02-simple-http-sync.php`) |
| 103 | +* Using multiple client instances (`03-multiple-servers-sync.php`) |
| 104 | +* Asynchronous operations with promises (`04-multiple-servers-async.php`) |
| 105 | +* Integration with `openai-php` for tool usage (`05-openai-php-integration-sync`) |
| 106 | +
|
| 107 | +### Looking Ahead |
| 108 | +
|
| 109 | +This initial release provides a solid foundation for MCP client interactions in PHP. Future development may include: |
| 110 | +
|
| 111 | +* Adding support for more advanced MCP capabilities (e.g., richer client-side `roots` declaration). |
| 112 | +* Enhanced session management helpers for the HTTP transport. |
| 113 | +* A shared `php-mcp/core` package for common definitions. |
| 114 | +
|
| 115 | +Feedback, bug reports, and contributions are duly welcomed! Thank you for trying `php-mcp/client`. |
0 commit comments