|
1 | | -# The original of this file is in the PostSharp.Engineering repo. |
2 | | -# You can generate this file using `./Build.ps1 generate-scripts`. |
3 | | - |
4 | | -param( |
5 | | - [string]$Prompt, |
6 | | - [int]$McpPort |
7 | | -) |
8 | | - |
9 | | -$ErrorActionPreference = "Stop" |
10 | | - |
11 | | -if ($env:RUNNING_IN_DOCKER -ne "true") |
12 | | -{ |
13 | | - Write-Error "This script must be run inside a Docker container. Set RUNNING_IN_DOCKER=true to override." |
14 | | - exit 1 |
15 | | -} |
16 | | - |
17 | | -# Configure MCP approval server if port is specified |
18 | | -$mcpConfigArg = "" |
19 | | -if ($McpPort -gt 0) |
20 | | -{ |
21 | | - # Get MCP secret from environment variable |
22 | | - $mcpSecret = $env:MCP_APPROVAL_SERVER_TOKEN |
23 | | - if ( [string]::IsNullOrEmpty($mcpSecret)) |
24 | | - { |
25 | | - Write-Error "MCP_APPROVAL_SERVER_TOKEN environment variable is not set. Cannot authenticate to MCP server." |
26 | | - exit 1 |
27 | | - } |
28 | | - |
29 | | - # URL-encode the secret for path segment |
30 | | - $encodedSecret = [System.Web.HttpUtility]::UrlEncode($mcpSecret) |
31 | | - $sseUrl = "http://host.docker.internal:$McpPort/$encodedSecret/sse" |
32 | | - Write-Host "Configuring MCP approval server (authenticated)" -ForegroundColor Cyan |
33 | | - |
34 | | - # Create temporary MCP config file |
35 | | - $mcpConfigPath = "$env:TEMP\mcp-config.json" |
36 | | - $mcpConfig = @{ |
37 | | - 'mcpServers' = @{ |
38 | | - 'host-approval' = @{ |
39 | | - 'type' = 'sse' |
40 | | - 'url' = $sseUrl |
41 | | - } |
42 | | - } |
43 | | - } |
44 | | - $mcpConfig | ConvertTo-Json -Depth 10 | Set-Content $mcpConfigPath -Encoding UTF8 |
45 | | - $mcpConfigArg = "--mcp-config `"$mcpConfigPath`"" |
46 | | - Write-Host "MCP config file created: $mcpConfigPath" -ForegroundColor Green |
47 | | -} |
48 | | - |
49 | | -Write-Host "Starting Claude CLI..." -ForegroundColor Green |
50 | | - |
51 | | -# Run Claude |
52 | | -if ($Prompt) |
53 | | -{ |
54 | | - Write-Host "Running Claude with prompt: $Prompt" -ForegroundColor Cyan |
55 | | - $cmd = "claude --dangerously-skip-permissions $mcpConfigArg -p `"$Prompt`"" |
56 | | - Invoke-Expression $cmd |
57 | | -} |
58 | | -else |
59 | | -{ |
60 | | - Write-Host "Running Claude in interactive mode" -ForegroundColor Cyan |
61 | | - $cmd = "claude --dangerously-skip-permissions $mcpConfigArg" |
62 | | - Invoke-Expression $cmd |
63 | | -} |
64 | | - |
65 | | -exit $LASTEXITCODE |
| 1 | +# The original of this file is in the PostSharp.Engineering repo. |
| 2 | +# You can generate this file using `./Build.ps1 generate-scripts`. |
| 3 | + |
| 4 | +param( |
| 5 | + [string]$Prompt, |
| 6 | + [int]$McpPort |
| 7 | +) |
| 8 | + |
| 9 | +$ErrorActionPreference = "Stop" |
| 10 | + |
| 11 | +if ($env:RUNNING_IN_DOCKER -ne "true") |
| 12 | +{ |
| 13 | + Write-Error "This script must be run inside a Docker container. Set RUNNING_IN_DOCKER=true to override." |
| 14 | + exit 1 |
| 15 | +} |
| 16 | + |
| 17 | +# Configure MCP approval server if port is specified |
| 18 | +$mcpConfigArg = "" |
| 19 | +if ($McpPort -gt 0) |
| 20 | +{ |
| 21 | + # Get MCP secret from environment variable |
| 22 | + $mcpSecret = $env:MCP_APPROVAL_SERVER_TOKEN |
| 23 | + if ( [string]::IsNullOrEmpty($mcpSecret)) |
| 24 | + { |
| 25 | + Write-Error "MCP_APPROVAL_SERVER_TOKEN environment variable is not set. Cannot authenticate to MCP server." |
| 26 | + exit 1 |
| 27 | + } |
| 28 | + |
| 29 | + # URL-encode the secret for path segment |
| 30 | + $encodedSecret = [System.Web.HttpUtility]::UrlEncode($mcpSecret) |
| 31 | + |
| 32 | + # On Windows containers, host.docker.internal doesn't resolve. |
| 33 | + # Use the default gateway IP which points to the host. |
| 34 | + $hostIp = (Get-NetRoute -DestinationPrefix '0.0.0.0/0' | Select-Object -First 1).NextHop |
| 35 | + if ([string]::IsNullOrEmpty($hostIp)) |
| 36 | + { |
| 37 | + Write-Error "Could not determine host IP from default gateway." |
| 38 | + exit 1 |
| 39 | + } |
| 40 | + Write-Host "Host IP (gateway): $hostIp" -ForegroundColor Cyan |
| 41 | + |
| 42 | + $sseUrl = "http://${hostIp}:$McpPort/$encodedSecret/sse" |
| 43 | + Write-Host "Configuring MCP approval server (authenticated)" -ForegroundColor Cyan |
| 44 | + |
| 45 | + # Create temporary MCP config file |
| 46 | + $mcpConfigPath = "$env:TEMP\mcp-config.json" |
| 47 | + $mcpConfig = @{ |
| 48 | + 'mcpServers' = @{ |
| 49 | + 'host-approval' = @{ |
| 50 | + 'type' = 'sse' |
| 51 | + 'url' = $sseUrl |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + $mcpConfig | ConvertTo-Json -Depth 10 | Set-Content $mcpConfigPath -Encoding UTF8 |
| 56 | + $mcpConfigArg = "--mcp-config `"$mcpConfigPath`"" |
| 57 | + Write-Host "MCP config file created: $mcpConfigPath" -ForegroundColor Green |
| 58 | +} |
| 59 | + |
| 60 | +Write-Host "Starting Claude CLI..." -ForegroundColor Green |
| 61 | + |
| 62 | +# Run Claude |
| 63 | +if ($Prompt) |
| 64 | +{ |
| 65 | + Write-Host "Running Claude with prompt: $Prompt" -ForegroundColor Cyan |
| 66 | + $cmd = "claude --dangerously-skip-permissions $mcpConfigArg -p `"$Prompt`"" |
| 67 | + Invoke-Expression $cmd |
| 68 | +} |
| 69 | +else |
| 70 | +{ |
| 71 | + Write-Host "Running Claude in interactive mode" -ForegroundColor Cyan |
| 72 | + $cmd = "claude --dangerously-skip-permissions $mcpConfigArg" |
| 73 | + Invoke-Expression $cmd |
| 74 | +} |
| 75 | + |
| 76 | +exit $LASTEXITCODE |
0 commit comments