Skip to content

Commit e08b3ec

Browse files
committed
update MCP package
1 parent 1fe1329 commit e08b3ec

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/Mcp/Tools/DatabaseSchema.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Laravel\AiAssistant\Mcp\Tools;
44

5-
use Laravel\Mcp\Tools\ToolResponse;
5+
use Laravel\Mcp\Tools\ToolResult;
66
use Laravel\Mcp\Tools\ToolInputSchema;
77
use Laravel\Mcp\Tools\Tool;
88
use Illuminate\Support\Facades\Artisan;
@@ -20,7 +20,7 @@ public function schema(ToolInputSchema $schema): ToolInputSchema
2020
return $schema;
2121
}
2222

23-
public function handle(array $arguments): ToolResponse
23+
public function handle(array $arguments): ToolResult
2424
{
2525
$filename = 'tmp_' . Str::random(40) . '.sql';
2626
$path = database_path("schema/{$filename}");
@@ -31,6 +31,6 @@ public function handle(array $arguments): ToolResponse
3131

3232
unlink($path);
3333

34-
return new ToolResponse($schema);
34+
return ToolResult::text($schema);
3535
}
3636
}

src/Mcp/Tools/LogReader.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Illuminate\Support\Facades\Process;
88
use Laravel\Mcp\Tools\Tool;
99
use Laravel\Mcp\Tools\ToolInputSchema;
10-
use Laravel\Mcp\Tools\ToolResponse;
10+
use Laravel\Mcp\Tools\ToolResult;
1111

1212
class LogReader extends Tool
1313
{
@@ -40,7 +40,7 @@ public function schema(ToolInputSchema $schema): ToolInputSchema
4040
/**
4141
* Execute the tool call.
4242
*/
43-
public function handle(array $arguments): ToolResponse|Generator
43+
public function handle(array $arguments): ToolResult|Generator
4444
{
4545
$numberOfLines = $arguments['lines'];
4646
$grepPattern = $arguments['grep'] ?? null;
@@ -54,7 +54,7 @@ public function handle(array $arguments): ToolResponse|Generator
5454
}
5555

5656
if (! $this->logFileExistsAndIsReadable($logPath)) {
57-
return new ToolResponse("Log file not found or is not readable: {$logPath}");
57+
return ToolResult::error("Log file not found or is not readable: {$logPath}");
5858
}
5959

6060
if ($grepPattern) {
@@ -66,20 +66,20 @@ public function handle(array $arguments): ToolResponse|Generator
6666
$result = Process::run($command);
6767

6868
if (! $result->successful()) {
69-
return new ToolResponse("Failed to read log file. Error: ".trim($result->errorOutput()));
69+
return ToolResult::error("Failed to read log file. Error: ".trim($result->errorOutput()));
7070
}
7171

7272
$output = $result->output();
7373

7474
if (trim($output) === '') {
7575
if ($grepPattern) {
76-
return new ToolResponse("No log entries found matching pattern: {$grepPattern}");
76+
return ToolResult::error("No log entries found matching pattern: {$grepPattern}");
7777
} else {
78-
return new ToolResponse('Log file is empty or no entries found.');
78+
return ToolResult::error('Log file is empty or no entries found.');
7979
}
8080
}
8181

82-
return new ToolResponse(trim($output));
82+
return ToolResult::text(trim($output));
8383
}
8484

8585
/**

tests/Feature/Mcp/Tools/LogReaderTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use Illuminate\Support\Facades\File;
44
use Illuminate\Support\Facades\Process;
55
use Laravel\AiAssistant\Mcp\Tools\LogReader;
6-
use Laravel\Mcp\Tools\ToolResponse;
6+
use Laravel\Mcp\Tools\ToolResult;
77

88
it('calls process with the correct log path when one is provided', function () {
99
Process::fake([
@@ -15,7 +15,7 @@
1515

1616
$tool = new LogReader();
1717

18-
$tool->handle([
18+
$result =$tool->handle([
1919
'lines' => 10,
2020
'log_path' => 'my/custom/log.log',
2121
]);
@@ -114,7 +114,7 @@
114114
]);
115115

116116
$logPath = storage_path('logs/laravel.log');
117-
expect($response)->toEqual(new ToolResponse("Log file not found or is not readable: {$logPath}"));
117+
expect($response)->toEqual(ToolResult::error("Log file not found or is not readable: {$logPath}"));
118118
});
119119

120120
it('returns an error if the log file is not readable', function () {
@@ -127,7 +127,7 @@
127127
]);
128128

129129
$logPath = storage_path('logs/laravel.log');
130-
expect($response)->toEqual(new ToolResponse("Log file not found or is not readable: {$logPath}"));
130+
expect($response)->toEqual(ToolResult::error("Log file not found or is not readable: {$logPath}"));
131131
});
132132

133133
it('returns an error if the process fails', function () {
@@ -147,7 +147,7 @@
147147
'lines' => 10,
148148
]);
149149

150-
expect($response)->toEqual(new ToolResponse("Failed to read log file. Error: Something went wrong"));
150+
expect($response)->toEqual(ToolResult::error("Failed to read log file. Error: Something went wrong"));
151151
});
152152

153153
it('returns a message if no log entries match the grep pattern', function () {
@@ -164,7 +164,7 @@
164164
'grep' => 'non_existent_pattern',
165165
]);
166166

167-
expect($response)->toEqual(new ToolResponse("No log entries found matching pattern: non_existent_pattern"));
167+
expect($response)->toEqual(ToolResult::error("No log entries found matching pattern: non_existent_pattern"));
168168
});
169169

170170
it('returns a message if the log file is empty', function () {
@@ -180,7 +180,7 @@
180180
'lines' => 10,
181181
]);
182182

183-
expect($response)->toEqual(new ToolResponse('Log file is empty or no entries found.'));
183+
expect($response)->toEqual(ToolResult::error('Log file is empty or no entries found.'));
184184
});
185185

186186
it('returns the log content on success', function () {
@@ -196,5 +196,5 @@
196196
'lines' => 10,
197197
]);
198198

199-
expect($response)->toEqual(new ToolResponse("log line 1 \n log line 2"));
199+
expect($response)->toEqual(ToolResult::text("log line 1 \n log line 2"));
200200
});

0 commit comments

Comments
 (0)