Skip to content

Commit a691ca1

Browse files
committed
fix command
1 parent 12fbae7 commit a691ca1

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/Console/ExecuteToolCommand.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Laravel\Boost\Mcp\ToolRegistry;
99
use Laravel\Mcp\Request;
1010
use Laravel\Mcp\Response;
11+
use Laravel\Mcp\Server\Tool;
12+
use Throwable;
1113

1214
class ExecuteToolCommand extends Command
1315
{
@@ -37,30 +39,34 @@ public function handle(): int
3739
return 1;
3840
}
3941

40-
try {
41-
// Execute the tool
42-
$tool = app($toolClass);
43-
44-
$request = new Request($arguments ?? []);
45-
$response = $tool->handle($request);
42+
/** @var Tool $tool */
43+
$tool = app($toolClass);
4644

47-
// Output the result as JSON for the parent process
48-
echo json_encode([
49-
'isError' => $response->isError(),
50-
'content' => (string) $response->content(),
51-
]);
45+
$request = new Request($arguments ?? []);
5246

53-
return 0;
54-
55-
} catch (\Throwable $e) {
56-
// Output error result
47+
try {
48+
/** @var Response $response */
49+
$response = $tool->handle($request);
50+
} catch (Throwable $e) {
5751
$errorResult = Response::error("Tool execution failed (E_THROWABLE): {$e->getMessage()}");
52+
5853
$this->error(json_encode([
5954
'isError' => true,
60-
'content' => (string) $errorResult->content(),
55+
'content' => [
56+
$errorResult->content()->toTool($tool),
57+
],
6158
]));
6259

63-
return 1;
60+
return static::FAILURE;
6461
}
62+
63+
echo json_encode([
64+
'isError' => $response->isError(),
65+
'content' => [
66+
$response->content()->toTool($tool),
67+
],
68+
]);
69+
70+
return static::SUCCESS;
6571
}
6672
}

0 commit comments

Comments
 (0)