Skip to content

Prevent non-JSON stdout output from corrupting MCP tool responses#641

Merged
pushpak1300 merged 4 commits intolaravel:mainfrom
OmarFaruk-0x01:fix/strip-deprecation-warnnig-tooloutput
Mar 11, 2026
Merged

Prevent non-JSON stdout output from corrupting MCP tool responses#641
pushpak1300 merged 4 commits intolaravel:mainfrom
OmarFaruk-0x01:fix/strip-deprecation-warnnig-tooloutput

Conversation

@OmarFaruk-0x01
Copy link
Contributor

@OmarFaruk-0x01 OmarFaruk-0x01 commented Mar 9, 2026

Problem

When the MCP tool subprocess produces any non-JSON output on stdout before the actual JSON response, the MCP client fails to parse the response:

CleanShot 2026-03-09 at 17 56 45

My Case

Running Laravel Boost MCP on PHP 8.4 with spatie/laravel-comments v1.7.3 installed. PHP 8.4 deprecates implicitly nullable parameters, and this package uses that pattern. Calling any Boost MCP tool (e.g., application-info) produced:

Deprecated: Spatie\Comments\Models\Concerns\HasComments::subscribers(): Implicitly marking parameter $type as nullable is deprecated...

Deprecated: Spatie\Comments\Models\Concerns\HasComments::comment(): Implicitly marking parameter $commentator as nullable is deprecated...

{"isError":false,"content":[...]}

The deprecation text prefixed the JSON, breaking the MCP protocol entirely.

Changes

  1. Added ini_set('display_errors', 'stderr') to redirect PHP errors to stderr instead of stdout during tool execution.

  2. Added extractJson() safety net that strips any leading non-JSON content from stdout before parsing.

@pushpak1300 pushpak1300 self-requested a review March 11, 2026 13:28
@pushpak1300 pushpak1300 merged commit dff4deb into laravel:main Mar 11, 2026
21 checks passed
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