Skip to content

Enhance MCP commands for WSL compatibility #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
29 changes: 26 additions & 3 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,15 @@ private function installMcpServerConfig(): void
$this->output->write(" {$ideDisplay}... ");
$results = [];

$php = $mcpClient->getPhpPath();
if ($this->shouldInstallMcp()) {
$php = $mcpClient->getPhpPath($this->isRunningInWsl());
$artisan = $mcpClient->getArtisanPath($this->isRunningInWsl());
try {
$artisan = $mcpClient->getArtisanPath();
$result = $mcpClient->installMcp('laravel-boost', $php, [$artisan, 'boost:mcp']);
if ($this->isRunningInWsl()) {
$result = $mcpClient->installMcp('laravel-boost', 'wsl', [$php, $artisan, 'boost:mcp']);
} else {
$result = $mcpClient->installMcp('laravel-boost', $php, [$artisan, 'boost:mcp']);
}

if ($result) {
$results[] = $this->greenTick.' Boost';
Expand All @@ -500,6 +504,7 @@ private function installMcpServerConfig(): void

// Install Herd MCP if enabled
if ($this->shouldInstallHerdMcp()) {
$php = $mcpClient->getPhpPath();
try {
$result = $mcpClient->installMcp(
key: 'herd',
Expand Down Expand Up @@ -545,4 +550,22 @@ private function detectLocalization(): bool
/** @phpstan-ignore-next-line */
return $actuallyUsing && is_dir(base_path('lang'));
}

/**
* Checks if the current script is running inside a Windows Subsystem for Linux (WSL) environment.
*
* This is more specific as it differentiates between a native Linux installation and WSL.
*
* @return bool True if the environment is WSL, false otherwise.
*/
private function isRunningInWsl(): bool
{

// Check for WSL-specific environment variables.
if (! empty(getenv('WSL_DISTRO_NAME')) || ! empty(getenv('IS_WSL'))) {
return true;
}

return false;
}
}
4 changes: 2 additions & 2 deletions src/Contracts/McpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public function useAbsolutePathForMcp(): bool;
/**
* Get the PHP executable path for this MCP client.
*/
public function getPhpPath(): string;
public function getPhpPath($forceAbsolutePath = false): string;

/**
* Get the artisan path for this MCP client.
*/
public function getArtisanPath(): string;
public function getArtisanPath($forceAbsolutePath = false): string;

/**
* Install an MCP server configuration in this IDE.
Expand Down
8 changes: 4 additions & 4 deletions src/Install/CodeEnvironment/CodeEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public function useAbsolutePathForMcp(): bool
return $this->useAbsolutePathForMcp;
}

public function getPhpPath(): string
public function getPhpPath($forceAbsolutePath = false): string
{
return $this->useAbsolutePathForMcp() ? PHP_BINARY : 'php';
return ($this->useAbsolutePathForMcp() || $forceAbsolutePath) ? PHP_BINARY : 'php';
}

public function getArtisanPath(): string
public function getArtisanPath($forceAbsolutePath = false): string
{
return $this->useAbsolutePathForMcp() ? base_path('artisan') : './artisan';
return ($this->useAbsolutePathForMcp() || $forceAbsolutePath) ? base_path('artisan') : './artisan';

}

Expand Down