Skip to content

Commit 5f1a86c

Browse files
feat: update configuration setup
1 parent e32b159 commit 5f1a86c

File tree

3 files changed

+98
-119
lines changed

3 files changed

+98
-119
lines changed

registry/coder-labs/modules/copilot-cli/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ module "copilot_cli" {
6666
6767
mcp_config = jsonencode({
6868
mcpServers = {
69-
github = {
70-
command = "@github/copilot-mcp-github"
69+
custom_server = {
70+
command = "npx"
71+
args = ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/files"]
7172
}
7273
}
7374
})
@@ -94,6 +95,15 @@ module "copilot_cli" {
9495
}
9596
```
9697

98+
## Configuration Files
99+
100+
This module creates and manages configuration files in `~/.config/copilot-cli/`:
101+
102+
- `config.json` - Copilot CLI settings (banner, theme, trusted directories)
103+
- `mcp-config.json` - Model Context Protocol server definitions
104+
105+
The module automatically configures GitHub and Coder MCP servers, and merges any custom MCP servers you provide via `mcp_config`.
106+
97107
### Standalone Mode
98108

99109
Run and configure Copilot CLI as a standalone tool in your workspace.

registry/coder-labs/modules/copilot-cli/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ variable "post_install_script" {
164164
data "coder_workspace" "me" {}
165165
data "coder_workspace_owner" "me" {}
166166

167-
168167
locals {
169168
workdir = trimsuffix(var.workdir, "/")
170169
app_slug = "copilot-cli"

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

Lines changed: 86 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -87,132 +87,102 @@ setup_copilot_configurations() {
8787
}
8888

8989
setup_copilot_config() {
90-
local config_file="$HOME/.config/copilot.json"
90+
local copilot_config_dir="$HOME/.config/copilot-cli"
91+
local copilot_config_file="$copilot_config_dir/config.json"
92+
local mcp_config_file="$copilot_config_dir/mcp-config.json"
93+
94+
mkdir -p "$copilot_config_dir"
9195

9296
if [ -n "$ARG_COPILOT_CONFIG" ]; then
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
97+
echo "Setting up Copilot CLI configuration..."
98+
99+
if command_exists jq; then
100+
echo "$ARG_COPILOT_CONFIG" | jq 'del(.mcpServers)' > "$copilot_config_file"
149101
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
102+
echo "$ARG_COPILOT_CONFIG" > "$copilot_config_file"
209103
fi
104+
105+
echo "Setting up MCP server configuration..."
106+
setup_mcp_config "$mcp_config_file"
210107
else
211108
echo "ERROR: No Copilot configuration provided"
212109
exit 1
213110
fi
214111
}
215112

113+
setup_mcp_config() {
114+
local mcp_config_file="$1"
115+
116+
local mcp_servers="{}"
117+
118+
if [ -n "$ARG_MCP_CONFIG" ]; then
119+
echo "Adding custom MCP servers..."
120+
if command_exists jq; then
121+
mcp_servers=$(echo "$ARG_MCP_CONFIG" | jq '.mcpServers // {}')
122+
else
123+
mcp_servers="$ARG_MCP_CONFIG"
124+
fi
125+
fi
126+
127+
if command_exists jq; then
128+
mcp_servers=$(echo "$mcp_servers" | jq '. + {
129+
"github": {
130+
"command": "@github/copilot-mcp-github"
131+
}
132+
}')
133+
elif command_exists node; then
134+
mcp_servers=$(node -e "
135+
const servers = JSON.parse(\`$mcp_servers\`);
136+
servers.github = { command: '@github/copilot-mcp-github' };
137+
console.log(JSON.stringify(servers));
138+
")
139+
fi
140+
141+
if [ "$ARG_REPORT_TASKS" = "true" ]; then
142+
echo "Adding Coder MCP server for task reporting..."
143+
if command_exists jq; then
144+
mcp_servers=$(echo "$mcp_servers" | jq '. + {
145+
"coder": {
146+
"command": "coder",
147+
"args": ["exp", "mcp", "server"],
148+
"type": "stdio",
149+
"env": {
150+
"CODER_MCP_APP_STATUS_SLUG": "'"$ARG_MCP_APP_STATUS_SLUG"'",
151+
"CODER_MCP_AI_AGENTAPI_URL": "http://localhost:3284"
152+
}
153+
}
154+
}')
155+
elif command_exists node; then
156+
mcp_servers=$(node -e "
157+
const servers = JSON.parse(\`$mcp_servers\`);
158+
servers.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+
console.log(JSON.stringify(servers));
168+
")
169+
fi
170+
fi
171+
172+
if command_exists jq; then
173+
echo "$mcp_servers" | jq '{mcpServers: .}' > "$mcp_config_file"
174+
elif command_exists node; then
175+
node -e "
176+
const servers = JSON.parse(\`$mcp_servers\`);
177+
console.log(JSON.stringify({mcpServers: servers}, null, 2));
178+
" > "$mcp_config_file"
179+
else
180+
echo "{\"mcpServers\": $mcp_servers}" > "$mcp_config_file"
181+
fi
182+
183+
echo "MCP configuration written to: $mcp_config_file"
184+
}
185+
216186
configure_coder_integration() {
217187
if [ "$ARG_REPORT_TASKS" = "true" ]; then
218188
echo "Configuring Copilot CLI task reporting..."

0 commit comments

Comments
 (0)