@@ -113,79 +113,71 @@ setup_copilot_config() {
113113setup_mcp_config () {
114114 local mcp_config_file=" $1 "
115115
116- # Start with Coder MCP server if task reporting is enabled
117- local mcp_servers=" {}"
116+ echo ' {"mcpServers": {}}' > " $mcp_config_file "
118117
119118 if [ " $ARG_REPORT_TASKS " = " true" ] && [ -n " $ARG_MCP_APP_STATUS_SLUG " ]; then
120119 echo " Adding Coder MCP server for task reporting..."
120+ setup_coder_mcp_server " $mcp_config_file "
121+ fi
121122
122- # Create wrapper script for Coder MCP server
123- cat << EOF > /tmp/copilot-mcp-wrapper.sh
124- #!/usr/bin/env bash
125- set -e
123+ if [ -n " $ARG_MCP_CONFIG " ] ; then
124+ echo " Adding custom MCP servers... "
125+ add_custom_mcp_servers " $mcp_config_file "
126+ fi
126127
127- export CODER_MCP_APP_STATUS_SLUG="${ARG_MCP_APP_STATUS_SLUG} "
128- export CODER_MCP_AI_AGENTAPI_URL="http://localhost:3284"
129- export CODER_AGENT_URL="${CODER_AGENT_URL} "
130- export CODER_AGENT_TOKEN="${CODER_AGENT_TOKEN} "
128+ echo " MCP configuration completed: $mcp_config_file "
129+ }
131130
132- exec coder exp mcp server
133- EOF
134- chmod +x /tmp/copilot-mcp-wrapper.sh
131+ setup_coder_mcp_server () {
132+ local mcp_config_file=" $1 "
135133
136- # Define Coder MCP server configuration
137- mcp_servers =$(
138- cat << ' EOF '
134+ local coder_mcp_config
135+ coder_mcp_config =$(
136+ cat << EOF
139137{
140- "coder": {
141- "command": "/tmp/copilot-mcp-wrapper.sh",
142- "args": [],
143- "description": "Report ALL tasks and statuses (in progress, done, failed) you are working on.",
144- "type": "stdio",
145- "timeout": 3000,
146- "trust": true
138+ "mcpServers": {
139+ "coder": {
140+ "type": "local",
141+ "command": "coder",
142+ "args": ["exp", "mcp", "server"],
143+ "tools": ["*"],
144+ "env": {
145+ "CODER_MCP_APP_STATUS_SLUG": "${ARG_MCP_APP_STATUS_SLUG} ",
146+ "CODER_MCP_AI_AGENTAPI_URL": "http://localhost:3284",
147+ "CODER_AGENT_URL": "${CODER_AGENT_URL} ",
148+ "CODER_AGENT_TOKEN": "${CODER_AGENT_TOKEN} "
149+ }
150+ }
147151 }
148152}
149153EOF
150- )
151- fi
154+ )
152155
153- # Add custom MCP servers if provided
154- if [ -n " $ARG_MCP_CONFIG " ]; then
155- echo " Adding custom MCP servers..."
156- local custom_servers
157- if command_exists jq; then
158- custom_servers=$( echo " $ARG_MCP_CONFIG " | jq ' .mcpServers // {}' )
159- # Merge custom servers with Coder server
160- mcp_servers=$( echo " $mcp_servers " | jq --argjson custom " $custom_servers " ' . + $custom' )
161- elif command_exists node; then
162- custom_servers=$( echo " $ARG_MCP_CONFIG " | node -e "
163- const input = JSON.parse(require('fs').readFileSync(0, 'utf8'));
164- console.log(JSON.stringify(input.mcpServers || {}));
165- " )
166- mcp_servers=$( node -e "
167- const existing = JSON.parse(\` $mcp_servers \` );
168- const custom = JSON.parse(\` $custom_servers \` );
169- console.log(JSON.stringify({...existing, ...custom}));
170- " )
171- else
172- echo " WARNING: jq and node not available, cannot merge custom MCP servers"
173- fi
174- fi
156+ echo " $coder_mcp_config " > " $mcp_config_file "
157+ }
158+
159+ add_custom_mcp_servers () {
160+ local mcp_config_file=" $1 "
175161
176- # Write final MCP configuration
177162 if command_exists jq; then
178- echo " $mcp_servers " | jq ' {mcpServers: .}' > " $mcp_config_file "
163+ local custom_servers
164+ custom_servers=$( echo " $ARG_MCP_CONFIG " | jq ' .mcpServers // {}' )
165+
166+ local updated_config
167+ updated_config=$( jq --argjson custom " $custom_servers " ' .mcpServers += $custom' " $mcp_config_file " )
168+ echo " $updated_config " > " $mcp_config_file "
179169 elif command_exists node; then
180170 node -e "
181- const servers = JSON.parse(\` $mcp_servers \` );
182- console.log(JSON.stringify({mcpServers: servers}, null, 2));
183- " > " $mcp_config_file "
171+ const fs = require('fs');
172+ const existing = JSON.parse(fs.readFileSync('$mcp_config_file ', 'utf8'));
173+ const input = JSON.parse(\` $ARG_MCP_CONFIG \` );
174+ const custom = input.mcpServers || {};
175+ existing.mcpServers = {...existing.mcpServers, ...custom};
176+ fs.writeFileSync('$mcp_config_file ', JSON.stringify(existing, null, 2));
177+ "
184178 else
185- echo " { \" mcpServers \" : $mcp_servers } " > " $mcp_config_file "
179+ echo " WARNING: jq and node not available, cannot merge custom MCP servers "
186180 fi
187-
188- echo " MCP configuration written to: $mcp_config_file "
189181}
190182
191183configure_coder_integration () {
0 commit comments