@@ -264,6 +264,40 @@ describe('McpClientManager', () => {
264264 'No MCP server registered with the name "non-existent"' ,
265265 ) ;
266266 } ) ;
267+
268+ it ( 'should create a new McpClient with updated config on restart' , async ( ) => {
269+ const originalConfig = { command : 'node' , args : [ '--port' , '8000' ] } ;
270+ const updatedConfig = { command : 'node' , args : [ '--port' , '9000' ] } ;
271+
272+ mockConfig . getMcpServers . mockReturnValue ( {
273+ 'test-server' : originalConfig ,
274+ } ) ;
275+
276+ // Track McpClient constructor calls
277+ const constructorCalls : unknown [ ] [ ] = [ ] ;
278+ vi . mocked ( McpClient ) . mockImplementation ( ( ...args : unknown [ ] ) => {
279+ constructorCalls . push ( args ) ;
280+ return mockedMcpClient ;
281+ } ) ;
282+ mockedMcpClient . getServerConfig . mockReturnValue ( originalConfig ) ;
283+
284+ const manager = new McpClientManager ( '0.0.1' , toolRegistry , mockConfig ) ;
285+ await manager . startConfiguredMcpServers ( ) ;
286+
287+ // First call should use the original config
288+ expect ( constructorCalls ) . toHaveLength ( 1 ) ;
289+ expect ( constructorCalls [ 0 ] [ 1 ] ) . toBe ( originalConfig ) ;
290+
291+ // Simulate config file change and hot-reload
292+ mockConfig . getMcpServers . mockReturnValue ( {
293+ 'test-server' : updatedConfig ,
294+ } ) ;
295+ await manager . startConfiguredMcpServers ( ) ;
296+
297+ // A NEW McpClient should have been constructed with the updated config
298+ expect ( constructorCalls ) . toHaveLength ( 2 ) ;
299+ expect ( constructorCalls [ 1 ] [ 1 ] ) . toBe ( updatedConfig ) ;
300+ } ) ;
267301 } ) ;
268302
269303 describe ( 'getMcpInstructions' , ( ) => {
0 commit comments