Skip to content

Conversation

@CodeWithKyrian
Copy link
Contributor

This PR implements a comprehensive architectural refactoring of the package, establishing the foundation for v2.0.0. The primary goals achieved are:

  1. Decoupled Core & Transport: Separated Server logic from network/IO via ServerTransportInterface.
  2. Improved API & Explicitness: Introduced ServerBuilder, explicit $server->listen(Transport), $server->getProtocol(), and on-demand $server->discover(...).
  3. Refined Configuration & Dependencies: Replaced ConfigurationRepositoryInterface with Configuration and Model\Capabilities VOs. Simplified component dependencies and improved default BasicContainer. ClientStateManager (was TransportState) now defaults to ArrayCache.
  4. Enhanced Caching: Registry caching now applies only to discovered elements, prioritizing manual registrations.
  5. Robust Transports: Updated StdioServerTransport (custom streams, Windows STDIN/STDOUT fix) and HttpServerTransport (constructor for server params).
  6. Schema Generation: Removed optimistic string format inference from SchemaGenerator for more predictable default schemas.
  7. Improved Error Reporting: Tool call validation failures now provide more detailed messages in the JSON-RPC error.

Key Changes:

  • New core classes/interfaces: ServerBuilder, Configuration, Model\Capabilities, ServerTransportInterface, Protocol.
  • Refactored/Replaced: Server, Registry, ClientStateManager, Processor, transport implementations.
  • Discovery is now an explicit call: $server->discover().
  • Exception hierarchy updated with McpServerException as base.
  • SchemaGenerator no longer infers string formats.
  • Enhanced tools/call error messages for schema validation failures.
  • Updated README.md and all examples.

Breaking Changes:

Yes, this is a significant refactoring with breaking changes to the public API, particularly around server instantiation (ServerBuilder), running the server (listen), discovery (discover), and transport usage. These changes are necessary for the v2.0.0 release and will be detailed in the release notes.

Related Issues:

- Replaced Server->run() with Server->listen(Transport) for explicit binding.
- Separated core Server logic from transport implementations (Stdio/Http).
- Introduced ServerBuilder for configuration and ServerProtocolHandler for mediation.
- Made attribute discovery an explicit step via Server->discover().
- Refined caching to only cache discovered elements, respecting manual registrations.
- Replaced ConfigurationRepository with Configuration VO and Capabilities VO.
- Simplified core component dependencies (Processor, Registry, ClientStateManager).
- Renamed TransportState to ClientStateManager.
- Renamed McpException to McpServerException and added specific exception types.
- Updated transport implementations (StdioServerTransport, HttpServerTransport).
- Improved default BasicContainer with simple auto-wiring.
- Revised documentation (README) and examples to reflect new architecture.
…nents

- ServerBuilder no longer configures discovery paths or runs discovery automatically during build; discovery is now an explicit step via `Server->discover()`.
- `Server::discover()` now accepts path configurations, clears only discovered/cached elements (preserving manual ones), and saves only discovered elements to cache.
- `Registry` distinguishes between manually registered and discovered elements:
    - Manual registrations take precedence over discovered/cached elements with the same identifier.
    - Caching methods (`loadDiscoveredElementsFromCache`, `saveDiscoveredElementsToCache`, `clearDiscoveredElements`) now operate only on discovered elements.
- `ClientStateManager` constructor defaults to `ArrayCache` if no PSR-16 cache is provided, ensuring basic stateful functionality.
- `ClientStateManager` now stores client-requested log levels.
- `Processor` updated to use `ClientStateManager` for persisting client-requested log levels and relies on `Configuration` VO for server capabilities.
- `JsonRpc\Response` constructor and `fromArray` updated to correctly handle `null` IDs for error responses as per JSON-RPC 2.0 spec, fixing related TypeErrors.
- `StdioServerTransport` constructor now accepts optional input/output stream resources, improving testability and flexibility.
- `HttpServerTransport` POST message handling reverted to synchronous body reading (`getBody()->getContents()`) for reliability with current `react/http` behavior, resolving hangs.
- Corrected `Support\DocBlockParser` and `Support\Discoverer` constructors to directly accept `LoggerInterface` instead of `ContainerInterface`.
- Updated unit tests for `ServerBuilder`, `Server`, `Registry`, `ClientStateManager`, `StdioServerTransport`, `HttpServerTransport`, `ProtocolHandler`, and JSON-RPC classes to reflect architectural changes and improve reliability, including fixes for Mockery state and loop interactions.
- Renamed `Server::getProtocolHandler()` to `Server::getProtocol()` and updated relevant class names (`ProtocolHandler` to `Protocol`).
- Renamed `Server::isLoaded()` in Registry to `discoveryRanOrCached()`.
- Renamed examples and updated their internal scripts and documentation comments to reflect new server API and best practices.
- Added more examples to showcase other use cases of the library
- Enhanced error handling in Processor to provide more informative validation error messages.
- Changed server listening address from '0.0.0.0' to '127.0.0.1' in example server scripts for improved clarity and compatibility.
- Refined logging messages in HttpServerTransport for consistency and clarity.
@CodeWithKyrian CodeWithKyrian merged commit 0e031f7 into main May 11, 2025
@CodeWithKyrian CodeWithKyrian deleted the develop-v2.0 branch May 11, 2025 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issues with dates

2 participants