Skip to content

Commit 1b2fdde

Browse files
CodeWithKyriangithub-actions[bot]
authored andcommitted
Update CHANGELOG
1 parent 0e031f7 commit 1b2fdde

File tree

1 file changed

+133
-8
lines changed

1 file changed

+133
-8
lines changed

CHANGELOG.md

Lines changed: 133 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,123 @@
22

33
All notable changes to `php-mcp/server` will be documented in this file.
44

5+
## PHP MCP Server v2.0.0 - 2025-05-11
6+
7+
This release marks a significant architectural refactoring of the package, aimed at improving modularity, testability, flexibility, and aligning its structure more closely with the `php-mcp/client` library. The core functionality remains, but the way servers are configured, run, and integrated has fundamentally changed.
8+
9+
### What's Changed
10+
11+
#### Core Architecture Overhaul
12+
13+
* **Decoupled Design:** The server core logic is now separated from the transport (network/IO) layer.
14+
* **`ServerBuilder`:** A new fluent builder (`Server::make()`) is the primary way to configure server identity, dependencies (Logger, Cache, Container, Loop), capabilities, and manually registered elements.
15+
* **`Server` Object:** The main `Server` class, created by the builder, now holds the configured core components (`Registry`, `Processor`, `ClientStateManager`, `Configuration`) but is transport-agnostic itself.
16+
* **`ServerTransportInterface`:** A new event-driven interface defines the contract for server-side transports (Stdio, Http). Transports are now responsible solely for listening and raw data transfer, emitting events for lifecycle and messages.
17+
* **`Protocol`:** A new internal class acts as a bridge, listening to events from a bound `ServerTransportInterface` and coordinating interactions with the `Processor` and `ClientStateManager`.
18+
19+
* **Explicit Server Execution:**
20+
* The old `$server->run(?string)` method is **removed**.
21+
* **`$server->listen(ServerTransportInterface $transport)`:** Introduced as the primary way to start a *standalone* server. It binds the `Protocol` to the provided transport, starts the listener, and runs the event loop (making it a blocking call).
22+
23+
24+
#### Discovery and Caching Refinements
25+
26+
* **Explicit Discovery:** Attribute discovery is no longer triggered automatically during `build()`. You must now explicitly call `$server->discover(basePath: ..., scanDirs: ...)` *after* building the server instance if you want to find elements via attributes.
27+
* **Caching Behavior:**
28+
* Only *discovered* elements are eligible for caching. Manually registered elements (via `ServerBuilder->with*` methods) are **never cached**.
29+
* The `Registry` attempts to load discovered elements from cache upon instantiation (during `ServerBuilder::build()`).
30+
* Calling `$server->discover()` will first clear any previously discovered/cached elements from the registry before scanning. It then saves the *newly discovered* results to the cache if enabled (`saveToCache: true`).
31+
* `Registry` cache methods renamed for clarity: `saveDiscoveredElementsToCache()` and `clearDiscoveredElements()`.
32+
* `Registry::isLoaded()` renamed to `discoveryRanOrCached()` for better clarity.
33+
34+
* **Manual vs. Discovered Precedence:** If an element is registered both manually and found via discovery/cache with the same identifier (name/URI), the **manually registered version always takes precedence**.
35+
36+
#### Dependency Injection and Configuration
37+
38+
* **`ConfigurationRepositoryInterface` Removed:** This interface and its default implementation (`ArrayConfigurationRepository`) have been removed.
39+
* **`Configuration` Value Object:** A new `PhpMcp\Server\Configuration` readonly value object bundles core dependencies (Logger, Loop, Cache, Container, Server Info, Capabilities, TTLs) assembled by the `ServerBuilder`.
40+
* **Simplified Dependencies:** Core components (`Registry`, `Processor`, `ClientStateManager`, `DocBlockParser`, `Discoverer`) now have simpler constructors, accepting direct dependencies.
41+
* **PSR-11 Container Role:** The container provided via `ServerBuilder->withContainer()` (or the default `BasicContainer`) is now primarily used by the `Processor` to resolve *user-defined handler classes* and their dependencies.
42+
* **Improved `BasicContainer`:** The default DI container (`PhpMcp\Server\Defaults\BasicContainer`) now supports simple constructor auto-wiring.
43+
* **`ClientStateManager` Default Cache:** If no `CacheInterface` is provided to the `ClientStateManager`, it now defaults to an in-memory `PhpMcp\Server\Defaults\ArrayCache`.
44+
45+
#### Schema Generation and Validation
46+
47+
* **Removed Optimistic String Format Inference:** The `SchemaGenerator` no longer automatically infers JSON Schema `format` keywords (like "date-time", "email") for string parameters. This makes default schemas less strict, avoiding validation issues for users with simpler string formats. Specific format validation should now be handled within tool/resource methods or via future explicit schema annotation features.
48+
* **Improved Tool Call Validation Error Messages:** When `tools/call` parameters fail schema validation, the JSON-RPC error response now includes a more informative summary message detailing the specific validation failures, in addition to the structured error data.
49+
50+
#### Transports
51+
52+
* **New Implementations:** Introduced `PhpMcp\Server\Transports\StdioServerTransport` and `PhpMcp\Server\Transports\HttpServerTransport`, both implementing `ServerTransportInterface`.
53+
* `StdioServerTransport` constructor now accepts custom input/output stream resources, improving testability and flexibility (defaults to `STDIN`/`STDOUT`).
54+
* `HttpServerTransport` constructor now accepts an array of request interceptor callables for custom request pre-processing (e.g., authentication), and also takes `host`, `port`, `mcpPathPrefix`, and `sslContext` for server configuration.
55+
56+
* **Windows `stdio` Limitation:** `StdioServerTransport` now throws a `TransportException` if instantiated with default `STDIN`/`STDOUT` on Windows, due to PHP's limitations with non-blocking pipes, guiding users to `WSL` or `HttpServerTransport`.
57+
* **Aware Interfaces:** Transports can implement `LoggerAwareInterface` and `LoopAwareInterface` to receive the configured Logger and Loop instances when `$server->listen()` is called.
58+
* **Removed:** The old `StdioTransportHandler`, `HttpTransportHandler`, and `ReactPhpHttpTransportHandler` classes.
59+
60+
#### Capabilities Configuration
61+
62+
* **`Model\Capabilities` Class:** Introduced a new `PhpMcp\Server\Model\Capabilities` value object (created via `Capabilities::forServer(...)`) to explicitly configure and represent server capabilities.
63+
64+
#### Exception Handling
65+
66+
* **`McpServerException`:** Renamed the base exception from `McpException` to `PhpMcp\Server\Exception\McpServerException`.
67+
* **New Exception Types:** Added more specific exceptions: `ConfigurationException`, `DiscoveryException`, `DefinitionException`, `TransportException`, `ProtocolException`.
68+
69+
#### Fixes
70+
71+
* Fixed `StdioServerTransport` not cleanly exiting on `Ctrl+C` due to event loop handling.
72+
* Fixed `TypeError` in `JsonRpc\Response` for parse errors with `null` ID.
73+
* Corrected discovery caching logic for explicit `discover()` calls.
74+
* Improved `HttpServerTransport` robustness for initial SSE event delivery and POST body handling.
75+
* Ensured manual registrations correctly take precedence over discovered/cached elements with the same identifier.
76+
77+
#### Internal Changes
78+
79+
* Introduced `LoggerAwareInterface` and `LoopAwareInterface` for dependency injection into transports.
80+
* Refined internal event handling between transport implementations and the `Protocol`.
81+
* Renamed `TransportState` to `ClientStateManager` and introduced a `ClientState` Value Object.
82+
83+
#### Documentation and Examples
84+
85+
* Significantly revised `README.md` to reflect the new architecture, API, discovery flow, transport usage, and configuration.
86+
* Added new and updated examples for standalone `stdio` and `http` servers, demonstrating discovery, manual registration, custom dependency injection, complex schemas, and environment variable usage.
87+
88+
### Breaking Changes
89+
90+
This is a major refactoring with significant breaking changes:
91+
92+
1. **`Server->run()` Method Removed:** Replace calls to `$server->run('stdio')` with:
93+
```php
94+
$transport = new StdioServerTransport();
95+
// Optionally call $server->discover(...) first
96+
$server->listen($transport);
97+
98+
```
99+
The `http` and `reactphp` options for `run()` were already invalid and are fully removed.
100+
2. **Configuration (`ConfigurationRepositoryInterface` Removed):** Configuration is now handled via the `Configuration` VO assembled by `ServerBuilder`. Remove any usage of the old `ConfigurationRepositoryInterface`. Core settings like server name/version are set via `withServerInfo`, capabilities via `withCapabilities`.
101+
3. **Dependency Injection:**
102+
* If using `ServerBuilder->withContainer()` with a custom PSR-11 container, that container is now only responsible for resolving *your application's handler classes* and their dependencies.
103+
* Core server dependencies (Logger, Cache, Loop) **must** be provided explicitly to the `ServerBuilder` using `withLogger()`, `withCache()`, `withLoop()` or rely on the builder's defaults.
104+
105+
4. **Transport Handlers Replaced:**
106+
* `StdioTransportHandler`, `HttpTransportHandler`, `ReactPhpHttpTransportHandler` are **removed**.
107+
* Use `new StdioServerTransport()` or `new HttpServerTransport(...)` and pass them to `$server->listen()`.
108+
* Constructor signatures and interaction patterns have changed.
109+
110+
5. **`Registry` Cache Methods Renamed:** `saveElementsToCache` is now `saveDiscoveredElementsToCache`, and `clearCache` is now `clearDiscoveredElements`. Their behavior is also changed to only affect discovered elements.
111+
6. **Core Component Constructors:** The constructors for `Registry`, `Processor`, `ClientStateManager` (previously `TransportState`), `Discoverer`, `DocBlockParser` have changed. Update any direct instantiations (though typically these are managed internally).
112+
7. **Exception Renaming:** `McpException` is now `McpServerException`. Update `catch` blocks accordingly.
113+
8. **Default Null Logger:** Logging is effectively disabled by default. Provide a logger via `ServerBuilder->withLogger()` to enable it.
114+
9. **Schema Generation:** Automatic string `format` inference (e.g., "date-time") removed from `SchemaGenerator`. String parameters are now plain strings in the schema unless a more advanced format definition mechanism is used in the future.
115+
116+
### Deprecations
117+
118+
* (None introduced in this refactoring, as major breaking changes were made directly).
119+
120+
**Full Changelog**: https://github.com/php-mcp/server/compare/1.1.0...2.0.0
121+
5122
## PHP MCP Server v1.1.0 - 2025-05-01
6123

7124
### Added
@@ -41,21 +158,29 @@ This release introduces the core implementation of the Model Context Protocol (M
41158
### ✨ Key Features:
42159

43160
* **Attribute-Based Definitions:** Easily define MCP Tools (`#[McpTool]`), Resources (`#[McpResource]`, `#[McpResourceTemplate]`), and Prompts (`#[McpPrompt]`) using PHP 8 attributes directly on your methods.
161+
44162
* **Automatic Metadata Inference:** Leverages method signatures (parameters, type hints) and DocBlocks (`@param`, `@return`, summaries) to automatically generate MCP schemas and descriptions, minimizing boilerplate.
163+
45164
* **PSR Compliance:** Integrates seamlessly with standard PHP interfaces:
46-
* `PSR-3` (LoggerInterface) for flexible logging.
47-
* `PSR-11` (ContainerInterface) for dependency injection and class resolution.
48-
* `PSR-16` (SimpleCacheInterface) for caching discovered elements and transport state.
49-
165+
166+
* `PSR-3` (LoggerInterface) for flexible logging.
167+
* `PSR-11` (ContainerInterface) for dependency injection and class resolution.
168+
* `PSR-16` (SimpleCacheInterface) for caching discovered elements and transport state.
169+
50170
* **Automatic Discovery:** Scans configured directories to find and register your annotated MCP elements.
171+
51172
* **Flexible Configuration:** Uses a configuration repository (`ConfigurationRepositoryInterface`) for fine-grained control over server behaviour, capabilities, and caching.
173+
52174
* **Multiple Transports:**
53-
* Built-in support for the `stdio` transport, ideal for command-line driven clients.
54-
* Includes `HttpTransportHandler` components for building standard `http` (HTTP+SSE) transports (requires integration into an HTTP server).
55-
* Provides `ReactPhpHttpTransportHandler` for seamless integration with asynchronous ReactPHP applications.
56-
175+
176+
* Built-in support for the `stdio` transport, ideal for command-line driven clients.
177+
* Includes `HttpTransportHandler` components for building standard `http` (HTTP+SSE) transports (requires integration into an HTTP server).
178+
* Provides `ReactPhpHttpTransportHandler` for seamless integration with asynchronous ReactPHP applications.
179+
57180
* **Protocol Support:** Implements the `2024-11-05` version of the Model Context Protocol.
181+
58182
* **Framework Agnostic:** Designed to work in vanilla PHP projects or integrated into any framework.
183+
59184

60185
### 🚀 Getting Started
61186

0 commit comments

Comments
 (0)