@@ -2,7 +2,6 @@ import chalk from 'chalk';
22import ora from 'ora' ;
33import { DeployStackAPI } from '../auth/api-client' ;
44import { CredentialStorage } from '../auth/storage' ;
5- import { processMCPInstallations , filterValidInstallations } from './config-processor' ;
65import { TeamMCPConfig } from '../../types/mcp' ;
76import { AuthenticationError , AuthError } from '../../types/auth' ;
87
@@ -97,106 +96,7 @@ export class MCPConfigService {
9796 }
9897
9998 /**
100- * Download and store MCP configuration for a team (LEGACY METHOD)
101- * @param teamId Team ID
102- * @param teamName Team name (optional, will be set from API if not provided)
103- * @param api DeployStack API client
104- * @param showSpinner Whether to show progress spinner
105- * @returns Downloaded MCP configuration
106- */
107- async downloadAndStoreMCPConfig (
108- teamId : string ,
109- teamName ?: string ,
110- api ?: DeployStackAPI ,
111- showSpinner : boolean = true
112- ) : Promise < TeamMCPConfig > {
113- let spinner : ReturnType < typeof ora > | null = null ;
114-
115- try {
116- if ( showSpinner ) {
117- spinner = ora ( 'Downloading MCP server configurations...' ) . start ( ) ;
118- }
119-
120- // Use provided API client or create one
121- let apiClient = api ;
122- if ( ! apiClient ) {
123- const credentials = await this . storage . getCredentials ( ) ;
124- if ( ! credentials ) {
125- throw new AuthenticationError (
126- AuthError . STORAGE_ERROR ,
127- 'No authentication found - cannot download MCP config'
128- ) ;
129- }
130- apiClient = new DeployStackAPI ( credentials , credentials . baseUrl ) ;
131- }
132-
133- // Download MCP installations for the team
134- const response = await apiClient . getTeamMCPInstallations ( teamId ) ;
135-
136- if ( ! response . success ) {
137- throw new AuthenticationError (
138- AuthError . NETWORK_ERROR ,
139- 'Failed to download MCP installations from API'
140- ) ;
141- }
142-
143- const installations = response . data || [ ] ;
144-
145- if ( showSpinner && spinner ) {
146- spinner . text = `Downloading user configurations for ${ installations . length } installation${ installations . length === 1 ? '' : 's' } ...` ;
147- }
148-
149- // Download user configurations for each installation
150- const allUserConfigurations = [ ] ;
151- for ( const installation of installations ) {
152- try {
153- const userConfigResponse = await apiClient . getUserConfigurations ( teamId , installation . id ) ;
154- if ( userConfigResponse . success && userConfigResponse . data ) {
155- allUserConfigurations . push ( ...userConfigResponse . data ) ;
156- }
157- } catch ( error ) {
158- // Log warning but continue - user configs are optional
159- console . log ( chalk . yellow ( `⚠️ Could not fetch user configurations for installation ${ installation . installation_name } : ${ error instanceof Error ? error . message : String ( error ) } ` ) ) ;
160- }
161- }
162-
163- if ( showSpinner && spinner ) {
164- spinner . text = `Processing ${ installations . length } installation${ installations . length === 1 ? '' : 's' } with ${ allUserConfigurations . length } user configuration${ allUserConfigurations . length === 1 ? '' : 's' } ...` ;
165- }
166-
167- // Filter and validate installations
168- const validInstallations = filterValidInstallations ( installations ) ;
169-
170- if ( validInstallations . length < installations . length ) {
171- const invalidCount = installations . length - validInstallations . length ;
172- console . log ( chalk . yellow ( `⚠️ Skipped ${ invalidCount } invalid installation${ invalidCount === 1 ? '' : 's' } ` ) ) ;
173- }
174-
175- // Process installations into server configurations with three-tier architecture
176- const config = processMCPInstallations ( teamId , teamName || `Team ${ teamId } ` , validInstallations , allUserConfigurations ) ;
177-
178- if ( showSpinner && spinner ) {
179- spinner . text = 'Storing MCP configuration securely...' ;
180- }
181-
182- // Store the configuration securely
183- await this . storage . storeMCPConfig ( config ) ;
184-
185- if ( showSpinner && spinner ) {
186- spinner . succeed ( `MCP configuration downloaded and stored (${ config . servers . length } server${ config . servers . length === 1 ? '' : 's' } )` ) ;
187- }
188-
189- return config ;
190- } catch ( error ) {
191- if ( spinner ) {
192- spinner . fail ( 'Failed to download MCP configuration' ) ;
193- }
194- throw error ;
195- }
196- }
197-
198- /**
199- * Switch team MCP configuration
99+ * Switch team MCP configuration using new gateway endpoint
200100 * Clears old config and downloads new config for the team
201101 * @param teamId New team ID
202102 * @param teamName New team name
@@ -214,8 +114,24 @@ export class MCPConfigService {
214114 await this . storage . clearMCPConfig ( credentials . selectedTeam . id ) ;
215115 }
216116
217- // Download and store new configuration
218- return await this . downloadAndStoreMCPConfig ( teamId , teamName , api , true ) ;
117+ // Detect device info for hardware_id
118+ const { detectDeviceInfo } = await import ( '../../utils/device-detection' ) ;
119+ const deviceInfo = await detectDeviceInfo ( ) ;
120+
121+ // Download merged configuration using new gateway endpoint
122+ const gatewayConfig = await this . downloadGatewayMCPConfig ( deviceInfo . hardware_id , api , true ) ;
123+
124+ // Convert and store the gateway config in the format expected by local storage
125+ const teamMCPConfig = this . convertGatewayConfigToTeamConfig (
126+ teamId ,
127+ teamName ,
128+ gatewayConfig
129+ ) ;
130+
131+ // Store the converted configuration
132+ await this . storeMCPConfig ( teamMCPConfig ) ;
133+
134+ return teamMCPConfig ;
219135 }
220136
221137 /**
0 commit comments