# Windows Launcher Guide

This guide provides detailed information about different launcher approaches for Windows and how to troubleshoot "spawn EINVAL" errors.

## Understanding "spawn EINVAL" Errors

The "spawn EINVAL" error in Node.js typically indicates that there's an invalid argument when trying to spawn a child process. When this occurs with an MCP server, it's often related to:

1. Spaces in file paths
2. Incorrect path formatting
3. Command syntax issues
4. Working directory problems

## Launcher Options

> **Note:** These launchers use `dist/index.js` which is the correct entry point when building from source. If you installed via npm/npx, use the `mcp-debugger` CLI command instead (the package exposes `dist/cli` as its executable shim, which loads `dist/cli.mjs`).

We've created several alternative launchers to address potential issues. Here's a comparison of the different approaches:

### 1. Simple Batch Script (`simple-run.cmd`)

```batch
@echo off
REM Simple wrapper script that changes to the correct directory first
cd /d "%~dp0"
node dist\index.js stdio
```

**Benefits**:
- Changes to the project directory first, avoiding path issues
- Very simple and straightforward

### 2. JavaScript Launcher (`direct-launch.js`)

```javascript
#!/usr/bin/env node
const { spawn } = require('child_process');
const path = require('path');

// Spawn `node dist/index.js stdio` as a child process, forwarding stdio
const child = spawn(
  process.execPath,
  [path.join(__dirname, 'dist', 'index.js'), 'stdio'],
  { stdio: 'inherit', cwd: __dirname }
);

child.on('exit', (code) => process.exit(code ?? 1));
child.on('error', (err) => {
  console.error('Launcher error:', err);
  process.exit(1);
});
```

**Benefits**:
- Avoids command-line path handling completely
- Spawns the server as a child process with the required `stdio` argument
- Forwards all stdio streams to the child

### 3. PowerShell Script (`mcp-launcher.ps1`)

```powershell
# PowerShell launcher for Debug MCP Server
# Get the script directory
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Build the full path to the index.js file
$indexPath = Join-Path -Path $scriptDir -ChildPath "dist\index.js"
# Run the server
try {
    & node $indexPath stdio
} catch {
    Write-Error "Error running node: $_"
    exit 1
}
```

**Benefits**:
- PowerShell has better path handling for complex paths
- Error handling is more robust

### 4. Traditional Batch Script (`run-debug-server.cmd`)

```batch
@echo off
REM Debug MCP Server Launcher
SET SCRIPT_DIR=%~dp0
SET INDEX_PATH=%SCRIPT_DIR%dist\index.js
REM Remove any trailing slash from the path
IF %SCRIPT_DIR:~-1%==\ SET SCRIPT_DIR=%SCRIPT_DIR:~0,-1%
ECHO Starting Debug MCP Server...
ECHO Using script path: %INDEX_PATH%
REM Run the server with any arguments passed to this script
node "%INDEX_PATH%" stdio %*
```

**Benefits**:
- Explicit path handling
- Shows path information for debugging
- Passes through additional arguments

## Configuration in MCP Settings

When configuring your MCP settings file:

1. **Simple Path (Recommended)**:
```json
"command": "C:\\path\\to\\mcp-debugger\\simple-run.cmd"
```

2. **With Spaces in Path**:
```json
"command": "C:\\Program Files\\mcp-debugger\\run-debug-server.cmd"
```

3. **Direct node invocation**:
```json
"command": "node \"C:\\workspace\\mcp-debugger\\direct-launch.js\""
```

## Troubleshooting Approach

If you encounter "spawn EINVAL" or similar errors:

1. Test each launcher manually in a command prompt before using it in MCP settings
2. Try running the server directly: `node dist/index.js stdio`
3. Use backslashes instead of forward slashes in your paths
4. Try different quoting styles
5. Check your current working directory with `echo %cd%`

## Testing the Launcher

Run your chosen launcher script from the command line first to verify it works before configuring it in the MCP settings.
