Skip to content

Conversation

@CodeWithKyrian
Copy link
Contributor

This PR introduces a comprehensive overhaul to achieve full compatibility with php-mcp/server v2.x.x+ and significantly enhance the developer experience for Laravel users.

Key Goals Achieved:

  • Modernized Core Integration: Utilizes the php-mcp/server v2.x ServerBuilder, explicit discovery mechanisms, clear transport separation, and the new Configuration value object.
  • "Laravely" Developer Experience:
    • Introduced a fluent API for manual MCP element registration via the Mcp Facade and a dedicated definitions file (e.g., routes/mcp.php), similar to defining Laravel routes.
    • Seamlessly integrates with Laravel's service container (for handler DI), cache (with fallback), logger, and event system.
    • Configuration is now more robust and aligned with Laravel conventions via config/mcp.php.
  • Flexible Transport Management:
    • The mcp:serve Artisan command now clearly supports stdio and a dedicated http (ReactPHP-based) transport, with CLI options for configuration.
    • The integrated HTTP+SSE transport (via Laravel routes and McpController) has been re-architected to correctly use a custom LaravelHttpTransport that bridges with the core MCP Protocol handler.
  • Clear Discovery & Caching: Auto-discovery in development is configurable, and the mcp:discover command provides explicit control over discovery and caching. Manual registrations always take precedence.
  • Namespace Standardization: The package's base namespace has been updated to PhpMcp\Laravel for better clarity and convention.

Major Changes Include:

  • McpServiceProvider: Rebuilt to use ServerBuilder for \PhpMcp\Server\Server instantiation, correctly wiring all Laravel dependencies and applying configurations. Implements configurable auto-discovery.
  • McpRegistrar & BluePrint Objects: Power the new fluent facade API for manual registrations.
  • Updated config/mcp.php: New structure, new keys for dedicated HTTP transport, simplified cache and discovery settings.
  • Artisan Commands (mcp:discover, mcp:list, mcp:serve): Refactored to interact with the new Server instance and core transport implementations. mcp:serve now offers an interactive prompt for transport selection.
  • LaravelHttpTransport & McpController: Reworked for correct interaction with the core Protocol when serving MCP via integrated Laravel routes. The controller now drives events on the custom transport.
  • Event System: Core server list change notifiers now dispatch Laravel events, handled by McpNotificationListener to queue MCP notifications.

This refactor addresses previous architectural limitations and aims to make php-mcp/laravel the definitive way to build MCP-enabled Laravel applications.

BREAKING CHANGES: (To be detailed in Release Notes)

  • Namespace change from PhpMcp\Laravel\Server to PhpMcp\Laravel.
  • Significant changes to config/mcp.php structure and keys.
  • The old ConfigAdapter is removed.
  • Internal workings of how the Server is built and configured have changed; direct manipulation of old internal classes will break.
  • The mcp:serve command's behavior for HTTP transport now launches a dedicated server by default (use integrated routes for embedded functionality).

@CodeWithKyrian CodeWithKyrian merged commit 7f02775 into main Jun 4, 2025
@CodeWithKyrian CodeWithKyrian deleted the refactor/v2 branch June 4, 2025 13:32
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.

2 participants