Skip to content

response()->stream() throws error in legacy SSE mode #30

@sergioalborada

Description

@sergioalborada

When using legacy SSE transport (legacy: true), MCP throws the following error:

[2025-07-09 08:08:33] local.ERROR: Symfony\Component\HttpFoundation\StreamedResponse::__construct(): Argument #2 ($status) must be of type int, array given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php on line 173 {"exception":"[object] (TypeError(code: 0): Symfony\\Component\\HttpFoundation\\StreamedResponse::__construct(): Argument #2 ($status) must be of type int, array given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php on line 173 at /var/www/html/vendor/symfony/http-foundation/StreamedResponse.php:38)
[stacktrace]
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(173): Symfony\\Component\\HttpFoundation\\StreamedResponse->__construct(Object(Closure), Array, Array)
#1 /var/www/html/vendor/php-mcp/laravel/src/Transports/HttpServerTransport.php(138): Illuminate\\Routing\\ResponseFactory->stream(Object(Closure), Array)
#2 /var/www/html/vendor/php-mcp/laravel/src/Http/Controllers/SseTransportController.php(43): PhpMcp\\Laravel\\Transports\\HttpServerTransport->handleSseRequest(Object(Illuminate\\Http\\Request))
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(47): PhpMcp\\Laravel\\Http\\Controllers\\SseTransportController->handleSse(Object(Illuminate\\Http\\Request))

This is caused by calling response()->stream(callback, [headers]) where the headers array is incorrectly passed as the second argument instead of the third.

Fix is simple: add 200 as second argument or either pass the headers as a named argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions