Skip to content

Conversation

@fsmonter
Copy link
Contributor

@fsmonter fsmonter commented May 2, 2025

This PR implements the MCP Streamable HTTP Transport. It enables client-initiated requests (POST request) with JSON-RPC and Server-Sent Events (SSE) responses on a unified endpoint.

Streamable HTTP Transport

  • Introduced a new streamable_http configuration in config/loop.php, replacing the previous sse configuration. This includes toggling the feature and setting the endpoint path.
  • Updated README.md to describe the new Streamable HTTP transport and added a new docs/http-streaming.md file with detailed configuration and usage instructions.

Routing, Middleware and Controller Enhancements

  • Updated routes/api.php to conditionally register the MCP endpoint based on the new streamable_http.enabled configuration. Middleware and endpoint paths are dynamically applied.
  • Renamed SseEnabledMiddleware to StreamableHttpEnabledMiddleware and updated it to check the new streamable_http.enabled configuration.
  • Updated McpController to handle both JSON and SSE responses. Added methods for JSON-RPC validation, SSE response handling, and client response preference.

New Service for SSE

  • Introduced a new SseService class to handle SSE-specific logic like creating streamed responses and formatting SSE events. Registered in the service provider. [1] [2]

Other Fixes

  • Fixed a bug in LaravelModelToolkit where ToolCollection::merge was not updating the original collection.
  • Updated FindModelTool to use dependency injection for PrismTool instead of static method calls.

Notes

Next Steps The transport spec defines several optional features not included on this PR, but are good candidates for next steps:

  • Server-initiated messages (GET).
  • Session Management
  • Resumability
  • CORS Origin Middleware

Previous HTTP+SSE The streamable HTTP transport replaced the previous HTTP+SSE transport which removes the /sse endpoint. Since this package doesn't implement HTTP+SSE, we're not supporting outdated clients.

@fsmonter fsmonter force-pushed the streamable-http branch 2 times, most recently from d64460e to 0133a12 Compare May 2, 2025 11:37
- Implement client-initiated request (POST endpoint) with JSON-RPC and
SSE responses.
- Fixes LaravelModelToolkit collection
@fsmonter fsmonter force-pushed the streamable-http branch from 0133a12 to 5e961c5 Compare May 2, 2025 11:41
@fsmonter fsmonter requested a review from Copilot May 8, 2025 14:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a new streamable HTTP transport for MCP, which supports client-initiated POST requests with both JSON-RPC and Server-Sent Events responses.

  • Added a new configuration setting and updated service providers to support the new functionality.
  • Renamed and updated middleware and controller logic to conditionally handle JSON versus SSE responses.
  • Added documentation updates to explain the new endpoint usage.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Toolkits/LaravelModelToolkit.php Updated merge operation to correctly update the ToolCollection.
src/Services/SseService.php Introduced a new service for formatting and streaming SSE responses.
src/LoopServiceProvider.php Registered the new SseService as a singleton.
src/Http/Middleware/StreamableHttpEnabledMiddleware.php Renamed middleware and updated configuration key check.
src/Http/Controllers/McpController.php Updated controller to handle JSON and SSE responses based on client headers.
routes/api.php Updated route registration to use the new configuration and middleware.
docs/http-streaming.md Added detailed documentation for configuring and using the new endpoint.
config/loop.php Introduced streamable_http configuration replacing the older sse settings.
README.md Updated README to reflect the new transport and endpoint configuration.

luisdalmolin and others added 3 commits May 13, 2025 15:57
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@luisdalmolin luisdalmolin merged commit 09bc7b9 into main May 13, 2025
11 checks passed
@luisdalmolin luisdalmolin deleted the streamable-http branch May 13, 2025 19:02
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.

3 participants