@@ -11,7 +11,7 @@ import {
1111import * as jsonConfig from '../../../src/utils/json-config' ;
1212import * as platform from '../../../src/utils/platform' ;
1313import * as objectUtils from '../../../src/utils/object-utils' ;
14- import { ClAUDE_CONFIG_FILE , CLAUDE_DIR } from '../../../src/constants' ;
14+ import { ClAUDE_CONFIG_FILE , CLAUDE_DIR , MCP_SERVICES } from '../../../src/constants' ;
1515
1616vi . mock ( '../../../src/utils/json-config' ) ;
1717vi . mock ( '../../../src/utils/platform' ) ;
@@ -185,6 +185,39 @@ describe('mcp utilities', () => {
185185
186186 expect ( result . args ) . toEqual ( [ '--key' , 'api-key' ] ) ;
187187 } ) ;
188+
189+ it ( 'should set environment variable when envVarName is provided' , ( ) => {
190+ const baseConfig = {
191+ type : 'stdio' as const ,
192+ command : 'npx' ,
193+ args : [ '-y' , 'exa-mcp-server' ] ,
194+ env : { EXA_API_KEY : 'placeholder' }
195+ } ;
196+ vi . mocked ( objectUtils . deepClone ) . mockReturnValue ( { ...baseConfig } ) ;
197+ vi . mocked ( platform . isWindows ) . mockReturnValue ( false ) ;
198+
199+ const result = buildMcpServerConfig ( baseConfig , 'test-api-key' , 'placeholder' , 'EXA_API_KEY' ) ;
200+
201+ expect ( result . env ) . toEqual ( { EXA_API_KEY : 'test-api-key' } ) ;
202+ } ) ;
203+
204+ it ( 'should handle environment variable config on Windows' , ( ) => {
205+ const baseConfig = {
206+ type : 'stdio' as const ,
207+ command : 'npx' ,
208+ args : [ '-y' , 'exa-mcp-server' ] ,
209+ env : { EXA_API_KEY : 'placeholder' }
210+ } ;
211+ vi . mocked ( objectUtils . deepClone ) . mockReturnValue ( { ...baseConfig } ) ;
212+ vi . mocked ( platform . isWindows ) . mockReturnValue ( true ) ;
213+ vi . mocked ( platform . getMcpCommand ) . mockReturnValue ( [ 'cmd' , '/c' , 'npx' ] ) ;
214+
215+ const result = buildMcpServerConfig ( baseConfig , 'test-api-key' , 'placeholder' , 'EXA_API_KEY' ) ;
216+
217+ expect ( result . command ) . toBe ( 'cmd' ) ;
218+ expect ( result . args ) . toEqual ( [ '/c' , 'npx' , '-y' , 'exa-mcp-server' ] ) ;
219+ expect ( result . env ) . toEqual ( { EXA_API_KEY : 'test-api-key' } ) ;
220+ } ) ;
188221 } ) ;
189222
190223 describe ( 'fixWindowsMcpConfig' , ( ) => {
@@ -224,5 +257,52 @@ describe('mcp utilities', () => {
224257 } ) ;
225258 } ) ;
226259
227- // Extended Tests
260+ describe ( 'Exa MCP Service Integration' , ( ) => {
261+ beforeEach ( ( ) => {
262+ // Mock deepClone to return a proper copy
263+ vi . mocked ( objectUtils . deepClone ) . mockImplementation ( obj => JSON . parse ( JSON . stringify ( obj ) ) ) ;
264+ } ) ;
265+
266+ it ( 'should have exa service configured with environment variable' , ( ) => {
267+ const exaService = MCP_SERVICES . find ( s => s . id === 'exa' ) ;
268+
269+ expect ( exaService ) . toBeDefined ( ) ;
270+ expect ( exaService ! . config . command ) . toBe ( 'npx' ) ;
271+ expect ( exaService ! . config . args ) . toContain ( 'exa-mcp-server' ) ;
272+ expect ( exaService ! . config . env ) . toHaveProperty ( 'EXA_API_KEY' ) ;
273+ expect ( exaService ! . apiKeyEnvVar ) . toBe ( 'EXA_API_KEY' ) ;
274+ } ) ;
275+
276+ it ( 'should build exa service config with API key in environment' , ( ) => {
277+ const exaService = MCP_SERVICES . find ( s => s . id === 'exa' ) ;
278+ vi . mocked ( platform . isWindows ) . mockReturnValue ( false ) ;
279+
280+ const config = buildMcpServerConfig (
281+ exaService ! . config ,
282+ 'test-exa-key-123' ,
283+ undefined ,
284+ exaService ! . apiKeyEnvVar
285+ ) ;
286+
287+ expect ( config . env ) . toEqual ( { EXA_API_KEY : 'test-exa-key-123' } ) ;
288+ expect ( config . args ) . toEqual ( [ '-y' , 'exa-mcp-server' ] ) ;
289+ } ) ;
290+
291+ it ( 'should handle exa service on Windows platform' , ( ) => {
292+ const exaService = MCP_SERVICES . find ( s => s . id === 'exa' ) ;
293+ vi . mocked ( platform . isWindows ) . mockReturnValue ( true ) ;
294+ vi . mocked ( platform . getMcpCommand ) . mockReturnValue ( [ 'cmd' , '/c' , 'npx' ] ) ;
295+
296+ const config = buildMcpServerConfig (
297+ exaService ! . config ,
298+ 'test-key' ,
299+ undefined ,
300+ exaService ! . apiKeyEnvVar
301+ ) ;
302+
303+ expect ( config . command ) . toBe ( 'cmd' ) ;
304+ expect ( config . args ) . toEqual ( [ '/c' , 'npx' , '-y' , 'exa-mcp-server' ] ) ;
305+ expect ( config . env ) . toEqual ( { EXA_API_KEY : 'test-key' } ) ;
306+ } ) ;
307+ } ) ;
228308} ) ;
0 commit comments