Skip to content
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
9 changes: 6 additions & 3 deletions src/Console/Commands/McpInspectorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,22 @@ public function handle(): int
}

if ($localServer) {
$currentDir = getcwd();
$artisanPath = base_path('artisan');

$normalizedArtisanPath = str_replace('\\', '/', $artisanPath);

$command = [
'npx',
'@modelcontextprotocol/inspector',
$this->phpBinary(),
$currentDir.'/artisan',
$artisanPath,
"mcp:start {$handle}",
];

$guidance = [
'Transport Type' => 'STDIO',
'Command' => $this->phpBinary(),
'Arguments' => implode(' ', [base_path('/artisan'), 'mcp:start', $handle]),
'Arguments' => implode(' ', [$normalizedArtisanPath, 'mcp:start', $handle]),
];
} else {
$serverUrl = str_replace('https://', 'http://', route('mcp-server.'.$handle));
Expand Down
66 changes: 66 additions & 0 deletions tests/Unit/Console/Commands/McpInspectorCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

use Laravel\Mcp\Console\Commands\McpInspectorCommand;
use Laravel\Mcp\Server\Registrar;

beforeEach(function () {
$this->registrar = Mockery::mock(Registrar::class);
$this->app->instance('mcp', $this->registrar);
});

it('normalizes windows paths in guidance output', function () {
$command = Mockery::mock(McpInspectorCommand::class)->makePartial();
$this->registrar
->shouldReceive('getLocalServer')
->with('demo')
->andReturn(function () {});

$this->registrar
->shouldReceive('getWebServer')
->with('demo')
->andReturn(null);

$windowsPath = 'D:\\Herd\\cyborgfinance\\artisan';
$normalizedPath = str_replace('\\', '/', $windowsPath);

expect($normalizedPath)->toBe('D:/Herd/cyborgfinance/artisan');
});

it('normalizes mixed paths correctly', function () {
$testCases = [
'D:\\Herd\\cyborgfinance\\artisan' => 'D:/Herd/cyborgfinance/artisan',
'/var/www/laravel/artisan' => '/var/www/laravel/artisan',
'C:\\xampp\\htdocs\\project\\artisan' => 'C:/xampp/htdocs/project/artisan',
'/home/user/project/artisan' => '/home/user/project/artisan',
];

foreach ($testCases as $input => $expected) {
$normalized = str_replace('\\', '/', $input);
expect($normalized)->toBe($expected);
}
});

it('fails with invalid handle', function () {
$this->registrar
->shouldReceive('getLocalServer')
->with('invalid')
->andReturn(null);

$this->registrar
->shouldReceive('getWebServer')
->with('invalid')
->andReturn(null);

$this->artisan('mcp:inspector', ['handle' => 'invalid'])
->expectsOutput('Starting the MCP Inspector for server: invalid')
->expectsOutput('Please pass a valid MCP handle')
->assertExitCode(1);
});

it('validates handle argument is required', function () {
expect(function () {
$this->artisan('mcp:inspector');
})->toThrow(RuntimeException::class, 'Not enough arguments (missing: "handle")');
});
Loading