Skip to content

Commit 35a631f

Browse files
committed
feat: auto-configure mcp.json and start server in Codespaces
1 parent fcdff56 commit 35a631f

3 files changed

Lines changed: 96 additions & 28 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,27 @@
1010
"portsAttributes": {
1111
"3001": {
1212
"label": "MCP Server",
13-
"onAutoForward": "notify",
13+
"onAutoForward": "openBrowserOnce",
1414
"visibility": "public"
1515
}
1616
},
1717

1818
"postCreateCommand": "npm install && npm run build",
19+
"postStartCommand": "bash .devcontainer/setup.sh",
1920

2021
"customizations": {
2122
"vscode": {
2223
"extensions": [
2324
"dbaeumer.vscode-eslint",
2425
"esbenp.prettier-vscode",
25-
"bradlc.vscode-tailwindcss",
2626
"GitHub.copilot",
2727
"GitHub.copilot-chat"
2828
],
2929
"settings": {
3030
"editor.formatOnSave": true,
31-
"editor.defaultFormatter": null,
32-
"typescript.preferences.importModuleSpecifier": "relative"
31+
"editor.defaultFormatter": "esbenp.prettier-vscode",
32+
"typescript.preferences.importModuleSpecifier": "relative",
33+
"terminal.integrated.defaultProfile.linux": "bash"
3334
}
3435
},
3536
"codespaces": {

.devcontainer/setup.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
# Setup script for GitHub Codespaces
3+
# Configures MCP client settings and starts the server
4+
5+
set -e
6+
7+
echo "🧭 Copilot Compass - Codespaces Setup"
8+
echo "======================================"
9+
10+
# Build if not already built
11+
if [ ! -f "dist/server.js" ]; then
12+
echo "📦 Building project..."
13+
npm run build
14+
fi
15+
16+
# Get the Codespaces URL
17+
if [ -n "$CODESPACE_NAME" ]; then
18+
MCP_URL="https://${CODESPACE_NAME}-3001.app.github.dev/mcp"
19+
echo "✅ Codespaces detected: $CODESPACE_NAME"
20+
else
21+
MCP_URL="http://localhost:3001/mcp"
22+
echo "⚠️ Not running in Codespaces, using localhost"
23+
fi
24+
25+
# Configure VS Code MCP settings
26+
MCP_CONFIG_DIR="$HOME/.vscode-server/data/User"
27+
MCP_CONFIG_FILE="$MCP_CONFIG_DIR/mcp.json"
28+
29+
mkdir -p "$MCP_CONFIG_DIR"
30+
31+
cat > "$MCP_CONFIG_FILE" << EOF
32+
{
33+
"mcpServers": {
34+
"copilot-compass": {
35+
"type": "http",
36+
"url": "$MCP_URL"
37+
}
38+
}
39+
}
40+
EOF
41+
42+
echo "✅ MCP config written to: $MCP_CONFIG_FILE"
43+
echo ""
44+
echo "📋 MCP Server URL: $MCP_URL"
45+
echo ""
46+
47+
# Check for GITHUB_TOKEN
48+
if [ -z "$GITHUB_TOKEN" ]; then
49+
echo "⚠️ GITHUB_TOKEN not set - will use demo data"
50+
echo " Set it in Codespaces secrets: https://github.com/settings/codespaces"
51+
else
52+
echo "✅ GITHUB_TOKEN is configured"
53+
fi
54+
55+
echo ""
56+
echo "🚀 Starting MCP server..."
57+
echo "======================================"
58+
59+
# Start the server
60+
exec node dist/server.js

README.md

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Add to your MCP client configuration (e.g., Claude Desktop, VS Code):
156156

157157
### Run in GitHub Codespaces (Easiest)
158158

159-
The fastest way to get started — no local setup required! Codespaces provides automatic HTTPS URLs, eliminating the need for tunneling tools.
159+
The fastest way to get started — no local setup required! Codespaces provides automatic HTTPS URLs and **auto-configures** the MCP client settings for you.
160160

161161
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/samueltauil/copilot-compass?quickstart=1)
162162

@@ -166,9 +166,19 @@ The fastest way to get started — no local setup required! Codespaces provides
166166
2. Click **Code****Codespaces****Create codespace on main**
167167
3. Wait for the container to build (~2 minutes)
168168

169-
#### Configure GitHub Token
169+
#### What Happens Automatically
170170

171-
Before starting the server, add your GitHub token as a Codespaces secret:
171+
When your Codespace starts:
172+
1. ✅ Dependencies are installed and project is built
173+
2. ✅ MCP server starts automatically on port 3001
174+
3. ✅ Port 3001 is made public with HTTPS
175+
4. ✅ VS Code's `mcp.json` is configured with your Codespace URL
176+
177+
The MCP server URL will be: `https://{codespace-name}-3001.app.github.dev/mcp`
178+
179+
#### Configure GitHub Token (Optional)
180+
181+
For live Copilot metrics (instead of demo data), add your GitHub token as a Codespaces secret:
172182

173183
1. Go to [github.com/settings/codespaces](https://github.com/settings/codespaces)
174184
2. Click **New secret**
@@ -181,37 +191,34 @@ Alternatively, create a `.env` file in the Codespace terminal:
181191

182192
```bash
183193
echo "GITHUB_TOKEN=your-token-here" > .env
194+
npm start # Restart the server
184195
```
185196

186-
#### Start the Server
197+
#### Verify It's Working
187198

188-
```bash
189-
npm start
190-
```
199+
1. Check the terminal — you should see:
200+
```
201+
🧭 Copilot Compass - Codespaces Setup
202+
✅ Codespaces detected: your-codespace-name
203+
✅ MCP config written to: ~/.vscode-server/data/User/mcp.json
204+
🚀 Starting MCP server...
205+
```
191206

192-
#### Get Your Public URL
207+
2. Open the **Ports** tab and verify port 3001 is public
193208

194-
1. Open the **Ports** tab in VS Code (bottom panel)
195-
2. Find port `3001` (labeled "MCP Server")
196-
3. Right-click → **Port Visibility****Public** (if not already)
197-
4. Copy the **Forwarded Address** (e.g., `https://username-codespace-abc123-3001.app.github.dev`)
209+
3. The MCP server is now ready! Use it from Copilot Chat or any MCP client.
198210

199-
#### Connect Your MCP Client
211+
#### Manual Start (If Needed)
200212

201-
Use the Codespaces URL in your MCP configuration:
213+
If the server stops or you need to restart:
202214

203-
```json
204-
{
205-
"mcpServers": {
206-
"copilot-compass": {
207-
"type": "http",
208-
"url": "https://username-codespace-abc123-3001.app.github.dev/mcp"
209-
}
210-
}
211-
}
215+
```bash
216+
npm start
217+
# Or with auto-config:
218+
bash .devcontainer/setup.sh
212219
```
213220

214-
> **Tip**: The Codespaces URL persists as long as your Codespace is running. For long-term use, consider running the server as a background task or using a dedicated VM.
221+
> **Tip**: The Codespaces URL persists as long as your Codespace is running. For long-term use, consider keeping the Codespace alive or using a dedicated VM.
215222
216223
### Public Access via Tunnel (Local Development)
217224

0 commit comments

Comments
 (0)