Skip to content

Commit 659a6b2

Browse files
fix: streamline MCP server configuration
1 parent a62146f commit 659a6b2

File tree

2 files changed

+120
-133
lines changed

2 files changed

+120
-133
lines changed

registry/coder-labs/modules/copilot-cli/scripts/install.sh

Lines changed: 117 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -81,115 +81,6 @@ setup_copilot_configurations() {
8181
mkdir -p "$module_path"
8282
mkdir -p "$HOME/.config"
8383

84-
if [ -n "$ARG_MCP_CONFIG" ]; then
85-
echo "Configuring custom MCP servers..."
86-
if command_exists jq; then
87-
echo "$ARG_MCP_CONFIG" | jq '
88-
.mcpServers = (.mcpServers // {}) |
89-
if .mcpServers.github == null then
90-
.mcpServers.github = {"command": "@github/copilot-mcp-github"}
91-
else . end |
92-
if "'"$ARG_REPORT_TASKS"'" == "true" then
93-
.mcpServers.coder = {
94-
"command": "coder",
95-
"args": ["exp", "mcp", "server"],
96-
"type": "stdio",
97-
"env": {
98-
"CODER_MCP_APP_STATUS_SLUG": "'"$ARG_MCP_APP_STATUS_SLUG"'",
99-
"CODER_MCP_AI_AGENTAPI_URL": "http://localhost:3284"
100-
}
101-
}
102-
else . end
103-
' > "$module_path/mcp_config.json"
104-
elif command_exists node; then
105-
node -e "
106-
const config = JSON.parse(\`$ARG_MCP_CONFIG\`);
107-
config.mcpServers = config.mcpServers || {};
108-
109-
if (!config.mcpServers.github) {
110-
config.mcpServers.github = {
111-
command: '@github/copilot-mcp-github'
112-
};
113-
}
114-
115-
if ('$ARG_REPORT_TASKS' === 'true') {
116-
config.mcpServers.coder = {
117-
command: 'coder',
118-
args: ['exp', 'mcp', 'server'],
119-
type: 'stdio',
120-
env: {
121-
CODER_MCP_APP_STATUS_SLUG: '$ARG_MCP_APP_STATUS_SLUG',
122-
CODER_MCP_AI_AGENTAPI_URL: 'http://localhost:3284'
123-
}
124-
};
125-
}
126-
127-
console.log(JSON.stringify(config, null, 2));
128-
" > "$module_path/mcp_config.json"
129-
else
130-
if [ "$ARG_REPORT_TASKS" = "true" ]; then
131-
echo "$ARG_MCP_CONFIG" | sed 's/}$//' > "$module_path/mcp_config.json"
132-
cat >> "$module_path/mcp_config.json" << EOF
133-
"github": {
134-
"command": "@github/copilot-mcp-github"
135-
},
136-
"coder": {
137-
"command": "coder",
138-
"args": ["exp", "mcp", "server"],
139-
"type": "stdio",
140-
"env": {
141-
"CODER_MCP_APP_STATUS_SLUG": "$ARG_MCP_APP_STATUS_SLUG",
142-
"CODER_MCP_AI_AGENTAPI_URL": "http://localhost:3284"
143-
}
144-
}
145-
}
146-
}
147-
EOF
148-
else
149-
echo "$ARG_MCP_CONFIG" | sed 's/}$//' > "$module_path/mcp_config.json"
150-
cat >> "$module_path/mcp_config.json" << EOF
151-
"github": {
152-
"command": "@github/copilot-mcp-github"
153-
}
154-
}
155-
}
156-
EOF
157-
fi
158-
fi
159-
else
160-
if [ "$ARG_REPORT_TASKS" = "true" ]; then
161-
echo "Configuring default MCP servers with Coder task reporting..."
162-
cat > "$module_path/mcp_config.json" << EOF
163-
{
164-
"mcpServers": {
165-
"github": {
166-
"command": "@github/copilot-mcp-github"
167-
},
168-
"coder": {
169-
"command": "coder",
170-
"args": ["exp", "mcp", "server"],
171-
"type": "stdio",
172-
"env": {
173-
"CODER_MCP_APP_STATUS_SLUG": "$ARG_MCP_APP_STATUS_SLUG",
174-
"CODER_MCP_AI_AGENTAPI_URL": "http://localhost:3284"
175-
}
176-
}
177-
}
178-
}
179-
EOF
180-
else
181-
cat > "$module_path/mcp_config.json" << 'EOF'
182-
{
183-
"mcpServers": {
184-
"github": {
185-
"command": "@github/copilot-mcp-github"
186-
}
187-
}
188-
}
189-
EOF
190-
fi
191-
fi
192-
19384
setup_copilot_config
19485

19586
echo "$ARG_WORKDIR" > "$module_path/trusted_directories"
@@ -199,8 +90,123 @@ setup_copilot_config() {
19990
local config_file="$HOME/.config/copilot.json"
20091

20192
if [ -n "$ARG_COPILOT_CONFIG" ]; then
202-
echo "Setting up Copilot configuration..."
203-
echo "$ARG_COPILOT_CONFIG" > "$config_file"
93+
echo "Setting up Copilot configuration with MCP servers..."
94+
95+
if [ -n "$ARG_MCP_CONFIG" ]; then
96+
echo "Merging custom MCP servers into Copilot configuration..."
97+
if command_exists jq; then
98+
local merged_config
99+
merged_config=$(echo "$ARG_COPILOT_CONFIG" | jq --argjson mcp_config "$ARG_MCP_CONFIG" '
100+
. + {
101+
mcpServers: ($mcp_config.mcpServers // {}) |
102+
if .github == null then
103+
.github = {"command": "@github/copilot-mcp-github"}
104+
else . end |
105+
if "'"$ARG_REPORT_TASKS"'" == "true" then
106+
.coder = {
107+
"command": "coder",
108+
"args": ["exp", "mcp", "server"],
109+
"type": "stdio",
110+
"env": {
111+
"CODER_MCP_APP_STATUS_SLUG": "'"$ARG_MCP_APP_STATUS_SLUG"'",
112+
"CODER_MCP_AI_AGENTAPI_URL": "http://localhost:3284"
113+
}
114+
}
115+
else . end
116+
}
117+
')
118+
echo "$merged_config" > "$config_file"
119+
elif command_exists node; then
120+
node -e "
121+
const copilotConfig = JSON.parse(\`$ARG_COPILOT_CONFIG\`);
122+
const mcpConfig = JSON.parse(\`$ARG_MCP_CONFIG\`);
123+
124+
copilotConfig.mcpServers = mcpConfig.mcpServers || {};
125+
126+
if (!copilotConfig.mcpServers.github) {
127+
copilotConfig.mcpServers.github = {
128+
command: '@github/copilot-mcp-github'
129+
};
130+
}
131+
132+
if ('$ARG_REPORT_TASKS' === 'true') {
133+
copilotConfig.mcpServers.coder = {
134+
command: 'coder',
135+
args: ['exp', 'mcp', 'server'],
136+
type: 'stdio',
137+
env: {
138+
CODER_MCP_APP_STATUS_SLUG: '$ARG_MCP_APP_STATUS_SLUG',
139+
CODER_MCP_AI_AGENTAPI_URL: 'http://localhost:3284'
140+
}
141+
};
142+
}
143+
144+
console.log(JSON.stringify(copilotConfig, null, 2));
145+
" > "$config_file"
146+
else
147+
echo "$ARG_COPILOT_CONFIG" > "$config_file"
148+
fi
149+
else
150+
if [ "$ARG_REPORT_TASKS" = "true" ]; then
151+
echo "Adding default MCP servers with Coder task reporting..."
152+
if command_exists jq; then
153+
echo "$ARG_COPILOT_CONFIG" | jq '. + {
154+
mcpServers: {
155+
"github": {
156+
"command": "@github/copilot-mcp-github"
157+
},
158+
"coder": {
159+
"command": "coder",
160+
"args": ["exp", "mcp", "server"],
161+
"type": "stdio",
162+
"env": {
163+
"CODER_MCP_APP_STATUS_SLUG": "'"$ARG_MCP_APP_STATUS_SLUG"'",
164+
"CODER_MCP_AI_AGENTAPI_URL": "http://localhost:3284"
165+
}
166+
}
167+
}
168+
}' > "$config_file"
169+
elif command_exists node; then
170+
node -e "
171+
const config = JSON.parse(\`$ARG_COPILOT_CONFIG\`);
172+
config.mcpServers = {
173+
github: { command: '@github/copilot-mcp-github' },
174+
coder: {
175+
command: 'coder',
176+
args: ['exp', 'mcp', 'server'],
177+
type: 'stdio',
178+
env: {
179+
CODER_MCP_APP_STATUS_SLUG: '$ARG_MCP_APP_STATUS_SLUG',
180+
CODER_MCP_AI_AGENTAPI_URL: 'http://localhost:3284'
181+
}
182+
}
183+
};
184+
console.log(JSON.stringify(config, null, 2));
185+
" > "$config_file"
186+
else
187+
echo "$ARG_COPILOT_CONFIG" > "$config_file"
188+
fi
189+
else
190+
echo "Adding default GitHub MCP server..."
191+
if command_exists jq; then
192+
echo "$ARG_COPILOT_CONFIG" | jq '. + {
193+
mcpServers: {
194+
"github": {
195+
"command": "@github/copilot-mcp-github"
196+
}
197+
}
198+
}' > "$config_file"
199+
elif command_exists node; then
200+
node -e "
201+
const config = JSON.parse(\`$ARG_COPILOT_CONFIG\`);
202+
config.mcpServers = { github: { command: '@github/copilot-mcp-github' } };
203+
console.log(JSON.stringify(config, null, 2));
204+
" > "$config_file"
205+
else
206+
echo "$ARG_COPILOT_CONFIG" > "$config_file"
207+
fi
208+
fi
209+
fi
204210
else
205211
echo "ERROR: No Copilot configuration provided"
206212
exit 1

registry/coder-labs/modules/copilot-cli/scripts/start.sh

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ validate_copilot_installation() {
2828
build_copilot_args() {
2929
COPILOT_ARGS=()
3030

31-
# Combine system prompt with AI prompt if both exist
3231
if [ -n "$ARG_SYSTEM_PROMPT" ] && [ -n "$ARG_AI_PROMPT" ]; then
3332
local combined_prompt="$ARG_SYSTEM_PROMPT
3433
@@ -85,14 +84,12 @@ configure_copilot_model() {
8584
setup_github_authentication() {
8685
echo "Setting up GitHub authentication..."
8786

88-
# Check for provided token first (highest priority)
8987
if [ -n "$GITHUB_TOKEN" ]; then
9088
export GH_TOKEN="$GITHUB_TOKEN"
9189
echo "✓ Using GitHub token from module configuration"
9290
return 0
9391
fi
9492

95-
# Try external auth
9693
if command_exists coder; then
9794
local github_token
9895
if github_token=$(coder external-auth access-token "${ARG_EXTERNAL_AUTH_ID:-github}" 2> /dev/null); then
@@ -105,7 +102,6 @@ setup_github_authentication() {
105102
fi
106103
fi
107104

108-
# Try GitHub CLI as fallback
109105
if command_exists gh && gh auth status > /dev/null 2>&1; then
110106
echo "✓ Using GitHub CLI OAuth authentication"
111107
return 0
@@ -114,7 +110,7 @@ setup_github_authentication() {
114110
echo "⚠ No GitHub authentication available"
115111
echo " Copilot CLI will prompt for login during first use"
116112
echo " Use the '/login' command in Copilot CLI to authenticate"
117-
return 0 # Don't fail - let Copilot CLI handle authentication
113+
return 0
118114
}
119115

120116
start_agentapi() {
@@ -123,26 +119,11 @@ start_agentapi() {
123119

124120
build_copilot_args
125121

126-
local mcp_args=()
127-
local module_path="$HOME/.copilot-module"
128-
129-
if [ -f "$module_path/mcp_config.json" ]; then
130-
mcp_args+=(--mcp-config "$module_path/mcp_config.json")
131-
fi
132-
133122
if [ ${#COPILOT_ARGS[@]} -gt 0 ]; then
134123
echo "Copilot arguments: ${COPILOT_ARGS[*]}"
135-
if [ ${#mcp_args[@]} -gt 0 ]; then
136-
agentapi server --type claude --term-width 120 --term-height 40 "${mcp_args[@]}" -- copilot "${COPILOT_ARGS[@]}"
137-
else
138-
agentapi server --type claude --term-width 120 --term-height 40 -- copilot "${COPILOT_ARGS[@]}"
139-
fi
124+
agentapi server --type claude --term-width 120 --term-height 40 -- copilot "${COPILOT_ARGS[@]}"
140125
else
141-
if [ ${#mcp_args[@]} -gt 0 ]; then
142-
agentapi server --type claude --term-width 120 --term-height 40 "${mcp_args[@]}" -- copilot
143-
else
144-
agentapi server --type claude --term-width 120 --term-height 40 -- copilot
145-
fi
126+
agentapi server --type claude --term-width 120 --term-height 40 -- copilot
146127
fi
147128
}
148129

0 commit comments

Comments
 (0)