@@ -82,13 +82,13 @@ describe('configCommand', () => {
8282 it ( 'should execute claude mcp add command with default port and pointer name' , ( ) => {
8383 configCommand ( SupportedTool . CLAUDE ) ;
8484
85- // Verify execSync was called once with the correct command
86- expect ( mockExecSync ) . toHaveBeenCalledTimes ( 1 ) ;
87- const command = mockExecSync . mock . calls [ 0 ] [ 0 ] ;
85+ // Verify execSync was called twice (remove + add)
86+ expect ( mockExecSync ) . toHaveBeenCalledTimes ( 2 ) ;
87+ const addCommand = mockExecSync . mock . calls [ 1 ] [ 0 ] ;
8888
89- // Verify exact command structure
89+ // Verify exact command structure for add command
9090 const expectedCommand = 'claude mcp add pointer -s user --env MCP_POINTER_PORT=7007 -- npx -y @mcp-pointer/server start' ;
91- expect ( command ) . toBe ( expectedCommand ) ;
91+ expect ( addCommand ) . toBe ( expectedCommand ) ;
9292
9393 // Verify success message
9494 expect ( mockLoggerInfo ) . toHaveBeenCalledWith ( expect . stringContaining ( '✅ Successfully configured MCP Pointer for Claude Code' ) ) ;
@@ -99,10 +99,47 @@ describe('configCommand', () => {
9999
100100 configCommand ( SupportedTool . CLAUDE ) ;
101101
102- expect ( mockExecSync ) . toHaveBeenCalledTimes ( 1 ) ;
103- const command = mockExecSync . mock . calls [ 0 ] [ 0 ] ;
102+ expect ( mockExecSync ) . toHaveBeenCalledTimes ( 2 ) ;
103+ const addCommand = mockExecSync . mock . calls [ 1 ] [ 0 ] ;
104104 const expectedCommand = 'claude mcp add pointer -s user --env MCP_POINTER_PORT=8888 -- npx -y @mcp-pointer/server start' ;
105- expect ( command ) . toBe ( expectedCommand ) ;
105+ expect ( addCommand ) . toBe ( expectedCommand ) ;
106+ } ) ;
107+
108+ it ( 'should attempt to remove existing server before adding new one' , ( ) => {
109+ configCommand ( SupportedTool . CLAUDE ) ;
110+
111+ // Verify execSync was called twice (remove + add)
112+ expect ( mockExecSync ) . toHaveBeenCalledTimes ( 2 ) ;
113+
114+ // First call should be remove command
115+ const removeCommand = mockExecSync . mock . calls [ 0 ] [ 0 ] ;
116+ expect ( removeCommand ) . toBe ( 'claude mcp remove pointer -s user' ) ;
117+
118+ // Second call should be add command
119+ const addCommand = mockExecSync . mock . calls [ 1 ] [ 0 ] ;
120+ expect ( addCommand ) . toBe ( 'claude mcp add pointer -s user --env MCP_POINTER_PORT=7007 -- npx -y @mcp-pointer/server start' ) ;
121+
122+ expect ( mockLoggerInfo ) . toHaveBeenCalledWith ( expect . stringContaining ( '🔄 Removed existing MCP Pointer configuration' ) ) ;
123+ expect ( mockLoggerInfo ) . toHaveBeenCalledWith ( expect . stringContaining ( '✅ Successfully configured MCP Pointer for Claude Code' ) ) ;
124+ } ) ;
125+
126+ it ( 'should continue adding even if remove fails' , ( ) => {
127+ // Mock remove command to fail, but add command to succeed
128+ mockExecSync
129+ . mockImplementationOnce ( ( ) => {
130+ throw new Error ( 'Server not found' ) ;
131+ } )
132+ . mockImplementationOnce ( ( ) => Buffer . from ( '' ) ) ;
133+
134+ configCommand ( SupportedTool . CLAUDE ) ;
135+
136+ // Verify execSync was still called twice
137+ expect ( mockExecSync ) . toHaveBeenCalledTimes ( 2 ) ;
138+
139+ // Should still log success message
140+ expect ( mockLoggerInfo ) . toHaveBeenCalledWith ( expect . stringContaining ( '✅ Successfully configured MCP Pointer for Claude Code' ) ) ;
141+ // Should not log removal message when remove fails
142+ expect ( mockLoggerInfo ) . not . toHaveBeenCalledWith ( expect . stringContaining ( '🔄 Removed existing MCP Pointer configuration' ) ) ;
106143 } ) ;
107144
108145 it ( 'should handle command failure gracefully' , ( ) => {
0 commit comments