Skip to content

Commit 201117a

Browse files
authored
Tweak debug output (#20)
1 parent 81cb483 commit 201117a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/Commands/LoopMcpServerStartCommand.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class LoopMcpServerStartCommand extends Command
2727
public function handle(McpHandler $mcpHandler): int
2828
{
2929
if ($this->option('debug')) {
30-
$this->info('Starting Laravel Loop MCP server (STDIO transport)');
30+
$this->debug('Starting Laravel Loop MCP server (STDIO transport)');
3131
}
3232

3333
if ($this->option('user-id')) {
@@ -43,7 +43,7 @@ public function handle(McpHandler $mcpHandler): int
4343
Auth::login($user);
4444

4545
if ($this->option('debug')) {
46-
$this->info(sprintf('Authenticated with user ID %s', $this->option('user-id')));
46+
$this->debug(sprintf('Authenticated with user ID %s', $this->option('user-id')));
4747
}
4848
}
4949

@@ -53,13 +53,13 @@ public function handle(McpHandler $mcpHandler): int
5353

5454
$stdin->on('data', function ($data) use ($stdout, $mcpHandler) {
5555
if ($this->option('debug')) {
56-
$this->comment('Received data: '.$data);
56+
$this->debug('Received data: '.$data);
5757
}
5858

5959
foreach (explode("\n", trim($data)) as $line) {
6060
if (! json_validate($line)) {
6161
if ($this->option('debug')) {
62-
$this->comment('Invalid line: '.$line);
62+
$this->debug('Invalid line: '.$line);
6363
}
6464

6565
continue;
@@ -70,14 +70,14 @@ public function handle(McpHandler $mcpHandler): int
7070
$response = $mcpHandler->handle($message);
7171

7272
if ($this->option('debug')) {
73-
$this->comment('Response: '.json_encode($response));
73+
$this->debug('Response: '.json_encode($response));
7474
}
7575

7676
if (isset($message['id'])) {
7777
$stdout->write(json_encode($response).PHP_EOL);
7878
}
79-
} catch (Exception $e) {
80-
$this->error('Error processing message: '.$e->getMessage());
79+
} catch (\Throwable $e) {
80+
$this->debug('Error processing message: '.$e->getMessage());
8181

8282
$response = $mcpHandler->formatErrorResponse(
8383
$message['id'] ?? '',
@@ -92,7 +92,7 @@ public function handle(McpHandler $mcpHandler): int
9292
});
9393

9494
if ($this->option('debug')) {
95-
$this->info('Laravel Loop MCP server running. Press Ctrl+C or send SIGTERM to stop.');
95+
$this->debug('Laravel Loop MCP server running. Press Ctrl+C or send SIGTERM to stop.');
9696
}
9797

9898
// Add signal handlers if pcntl is available
@@ -101,7 +101,7 @@ public function handle(McpHandler $mcpHandler): int
101101
info('Received signal: '.$signal.'. Shutting down...');
102102

103103
if ($this->option('debug')) {
104-
$this->info('Received signal: '.$signal.'. Shutting down...');
104+
$this->debug('Received signal: '.$signal.'. Shutting down...');
105105
}
106106

107107
$loop->stop();
@@ -130,4 +130,9 @@ public function handle(McpHandler $mcpHandler): int
130130

131131
return Command::SUCCESS;
132132
}
133+
134+
protected function debug($message)
135+
{
136+
$this->getOutput()->getOutput()->getErrorOutput()->writeln($message);
137+
}
133138
}

0 commit comments

Comments
 (0)