Skip to content

Commit d433ff0

Browse files
committed
feat: add raw package name to application info in case we need it for search docs filtering
1 parent d2333bd commit d433ff0

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/Mcp/Tools/ApplicationInfo.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
#[IsReadOnly]
1818
class ApplicationInfo extends Tool
1919
{
20-
public function __construct(protected Roster $roster) {}
20+
public function __construct(protected Roster $roster)
21+
{
22+
}
2123

2224
public function description(): string
2325
{
@@ -30,15 +32,15 @@ public function schema(ToolInputSchema $schema): ToolInputSchema
3032
}
3133

3234
/**
33-
* @param array<string> $arguments
35+
* @param array<string> $arguments
3436
*/
3537
public function handle(array $arguments): ToolResult
3638
{
3739
return ToolResult::json([
3840
'php_version' => PHP_VERSION,
3941
'laravel_version' => app()->version(),
4042
'database_engine' => config('database.default'),
41-
'packages' => $this->roster->packages()->map(fn (Package $package) => ['name' => $package->name(), 'version' => $package->version()]),
43+
'packages' => $this->roster->packages()->map(fn(Package $package) => ['roster_name' => $package->name(), 'version' => $package->version(), 'package_name' => $package->rawName()]),
4244
'models' => $this->discoverModels(),
4345
]);
4446
}
@@ -53,8 +55,8 @@ private function discoverModels(): array
5355
$models = [];
5456
$appPath = app_path();
5557

56-
if (! is_dir($appPath)) {
57-
return ['app-path-isnt-a-directory:'.$appPath];
58+
if (!is_dir($appPath)) {
59+
return ['app-path-isnt-a-directory:' . $appPath];
5860
}
5961

6062
$finder = Finder::create()
@@ -65,17 +67,17 @@ private function discoverModels(): array
6567
foreach ($finder as $file) {
6668
$relativePath = $file->getRelativePathname();
6769
$namespace = app()->getNamespace();
68-
$className = $namespace.str_replace(
69-
['/', '.php'],
70-
['\\', ''],
71-
$relativePath
72-
);
70+
$className = $namespace . str_replace(
71+
['/', '.php'],
72+
['\\', ''],
73+
$relativePath
74+
);
7375

7476
try {
7577
if (class_exists($className)) {
7678
$reflection = new ReflectionClass($className);
77-
if ($reflection->isSubclassOf(Model::class) && ! $reflection->isAbstract()) {
78-
$models[$className] = $appPath.DIRECTORY_SEPARATOR.$relativePath;
79+
if ($reflection->isSubclassOf(Model::class) && !$reflection->isAbstract()) {
80+
$models[$className] = $appPath . DIRECTORY_SEPARATOR . $relativePath;
7981
}
8082
}
8183
} catch (\Throwable) {

tests/Feature/Mcp/Tools/ApplicationInfoTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
test('it returns application info with packages', function () {
1313
$packages = new PackageCollection([
14-
new Package(Packages::LARAVEL, '11.0.0'),
15-
new Package(Packages::PEST, '2.0.0'),
14+
new Package(Packages::LARAVEL, 'laravel/framework', '11.0.0'),
15+
new Package(Packages::PEST, 'pestphp/pest', '2.0.0'),
1616
]);
1717

1818
$roster = Mockery::mock(Roster::class);
@@ -31,9 +31,11 @@
3131
expect($content['laravel_version'])->toBe(app()->version());
3232
expect($content['database_engine'])->toBe(config('database.default'));
3333
expect($content['packages'])->toHaveCount(2);
34-
expect($content['packages'][0]['name'])->toBe('LARAVEL');
34+
expect($content['packages'][0]['roster_name'])->toBe('LARAVEL');
35+
expect($content['packages'][0]['package_name'])->toBe('laravel/framework');
3536
expect($content['packages'][0]['version'])->toBe('11.0.0');
36-
expect($content['packages'][1]['name'])->toBe('PEST');
37+
expect($content['packages'][1]['roster_name'])->toBe('PEST');
38+
expect($content['packages'][1]['package_name'])->toBe('pestphp/pest');
3739
expect($content['packages'][1]['version'])->toBe('2.0.0');
3840
expect($content['models'])->toBeArray();
3941
});

0 commit comments

Comments
 (0)