Skip to content

Fix ServeCommand output interfering with stdio JSON-RPC communication #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpMcp\Server\Transports\HttpServerTransport;
use PhpMcp\Server\Transports\StdioServerTransport;
use PhpMcp\Server\Transports\StreamableHttpServerTransport;
use Symfony\Component\Console\Output\ConsoleOutputInterface;

use function Laravel\Prompts\select;

Expand Down Expand Up @@ -80,10 +81,14 @@ private function handleStdioTransport(Server $server): int
return Command::FAILURE;
}

$this->info('Starting MCP server');
$this->line(" - Transport: STDIO");
$this->line(" - Communication: STDIN/STDOUT");
$this->line(" - Mode: JSON-RPC over Standard I/O");
$output = $this->output->getOutput();

if ($output instanceof ConsoleOutputInterface) {
$output->getErrorOutput()->writeln("Starting MCP server");
$output->getErrorOutput()->writeln(" - Transport: STDIO");
$output->getErrorOutput()->writeln(" - Communication: STDIN/STDOUT");
$output->getErrorOutput()->writeln(" - Mode: JSON-RPC over Standard I/O");
}

try {
$transport = new StdioServerTransport;
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Commands/ServeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function test_serve_command_defaults_to_stdio_and_calls_server_listen()
);

$this->artisan('mcp:serve --transport=stdio')
->expectsOutputToContain('Starting MCP server')
->expectsOutputToContain('Transport: STDIO')
->doesntExpectOutputToContain('Starting MCP server')
->doesntExpectOutputToContain('Transport: STDIO')
->assertSuccessful();
}

Expand Down