@@ -113,17 +113,67 @@ setup_copilot_config() {
113113setup_mcp_config () {
114114 local mcp_config_file=" $1 "
115115
116+ # Start with Coder MCP server if task reporting is enabled
116117 local mcp_servers=" {}"
117118
119+ if [ " $ARG_REPORT_TASKS " = " true" ] && [ -n " $ARG_MCP_APP_STATUS_SLUG " ]; then
120+ echo " Adding Coder MCP server for task reporting..."
121+
122+ # Create wrapper script for Coder MCP server
123+ cat << EOF > /tmp/copilot-mcp-wrapper.sh
124+ #!/usr/bin/env bash
125+ set -e
126+
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} "
131+
132+ exec coder exp mcp server
133+ EOF
134+ chmod +x /tmp/copilot-mcp-wrapper.sh
135+
136+ # Define Coder MCP server configuration
137+ mcp_servers=$(
138+ cat << 'EOF '
139+ {
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
147+ }
148+ }
149+ EOF
150+ )
151+ fi
152+
153+ # Add custom MCP servers if provided
118154 if [ -n " $ARG_MCP_CONFIG " ]; then
119155 echo " Adding custom MCP servers..."
156+ local custom_servers
120157 if command_exists jq; then
121- mcp_servers=$( echo " $ARG_MCP_CONFIG " | jq ' .mcpServers // {}' )
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+ " )
122171 else
123- mcp_servers= " $ARG_MCP_CONFIG "
172+ echo " WARNING: jq and node not available, cannot merge custom MCP servers "
124173 fi
125174 fi
126175
176+ # Write final MCP configuration
127177 if command_exists jq; then
128178 echo " $mcp_servers " | jq ' {mcpServers: .}' > " $mcp_config_file "
129179 elif command_exists node; then
@@ -135,31 +185,19 @@ setup_mcp_config() {
135185 echo " {\" mcpServers\" : $mcp_servers }" > " $mcp_config_file "
136186 fi
137187
138- if [ -n " $ARG_MCP_CONFIG " ]; then
139- echo " Custom MCP configuration written to: $mcp_config_file "
140- else
141- echo " Empty MCP configuration file created at: $mcp_config_file "
142- fi
188+ echo " MCP configuration written to: $mcp_config_file "
143189}
144190
145191configure_coder_integration () {
146- if [ " $ARG_REPORT_TASKS " = " true" ]; then
192+ if [ " $ARG_REPORT_TASKS " = " true" ] && [ -n " $ARG_MCP_APP_STATUS_SLUG " ] ; then
147193 echo " Configuring Copilot CLI task reporting..."
148194 export CODER_MCP_APP_STATUS_SLUG=" $ARG_MCP_APP_STATUS_SLUG "
149195 export CODER_MCP_AI_AGENTAPI_URL=" http://localhost:3284"
150-
151- if command_exists coder; then
152- echo " Setting up Coder MCP integration for Copilot CLI..."
153- coder exp mcp configure copilot-cli " $ARG_WORKDIR " 2> /dev/null || true
154- fi
196+ echo " ✓ Coder MCP server configured for task reporting"
155197 else
156- echo " Task reporting disabled."
157- if command_exists coder; then
158- export CODER_MCP_APP_STATUS_SLUG=" "
159- export CODER_MCP_AI_AGENTAPI_URL=" "
160- echo " Configuring Copilot CLI with Coder MCP (no task reporting)..."
161- coder exp mcp configure copilot-cli " $ARG_WORKDIR " 2> /dev/null || true
162- fi
198+ echo " Task reporting disabled or no app status slug provided."
199+ export CODER_MCP_APP_STATUS_SLUG=" "
200+ export CODER_MCP_AI_AGENTAPI_URL=" "
163201 fi
164202}
165203
0 commit comments