@@ -65,22 +65,50 @@ describe('mcp add command', () => {
6565 } ) ;
6666 } ) ;
6767
68- it ( 'should add a stdio server to project settings' , async ( ) => {
68+ it ( 'should add a stdio server to user settings by default ' , async ( ) => {
6969 await parser . parseAsync (
7070 'add my-server /path/to/server arg1 arg2 -e FOO=bar' ,
7171 ) ;
7272
73- expect ( mockSetValue ) . toHaveBeenCalledWith (
74- SettingScope . Workspace ,
75- 'mcpServers' ,
76- {
77- 'my-server' : {
78- command : '/path/to/server' ,
79- args : [ 'arg1' , 'arg2' ] ,
80- env : { FOO : 'bar' } ,
81- } ,
73+ expect ( mockSetValue ) . toHaveBeenCalledWith ( SettingScope . User , 'mcpServers' , {
74+ 'my-server' : {
75+ command : '/path/to/server' ,
76+ args : [ 'arg1' , 'arg2' ] ,
77+ env : { FOO : 'bar' } ,
78+ } ,
79+ } ) ;
80+ } ) ;
81+
82+ it ( 'should auto-detect http transport when commandOrUrl is an https URL' , async ( ) => {
83+ await parser . parseAsync ( 'add http-server https://example.com/mcp' ) ;
84+
85+ expect ( mockSetValue ) . toHaveBeenCalledWith ( SettingScope . User , 'mcpServers' , {
86+ 'http-server' : {
87+ httpUrl : 'https://example.com/mcp' ,
8288 } ,
89+ } ) ;
90+ } ) ;
91+
92+ it ( 'should auto-detect http transport when commandOrUrl is an http URL' , async ( ) => {
93+ await parser . parseAsync ( 'add http-server http://localhost:8080/mcp' ) ;
94+
95+ expect ( mockSetValue ) . toHaveBeenCalledWith ( SettingScope . User , 'mcpServers' , {
96+ 'http-server' : {
97+ httpUrl : 'http://localhost:8080/mcp' ,
98+ } ,
99+ } ) ;
100+ } ) ;
101+
102+ it ( 'should respect explicit transport even when commandOrUrl is a URL' , async ( ) => {
103+ await parser . parseAsync (
104+ 'add --transport sse sse-server https://example.com/sse-endpoint' ,
83105 ) ;
106+
107+ expect ( mockSetValue ) . toHaveBeenCalledWith ( SettingScope . User , 'mcpServers' , {
108+ 'sse-server' : {
109+ url : 'https://example.com/sse-endpoint' ,
110+ } ,
111+ } ) ;
84112 } ) ;
85113
86114 it ( 'should add an sse server to user settings' , async ( ) => {
@@ -96,55 +124,43 @@ describe('mcp add command', () => {
96124 } ) ;
97125 } ) ;
98126
99- it ( 'should add an http server to project settings' , async ( ) => {
127+ it ( 'should add an http server to user settings by default ' , async ( ) => {
100128 await parser . parseAsync (
101129 'add --transport http http-server https://example.com/mcp -H "Authorization: Bearer your-token"' ,
102130 ) ;
103131
104- expect ( mockSetValue ) . toHaveBeenCalledWith (
105- SettingScope . Workspace ,
106- 'mcpServers' ,
107- {
108- 'http-server' : {
109- httpUrl : 'https://example.com/mcp' ,
110- headers : { Authorization : 'Bearer your-token' } ,
111- } ,
132+ expect ( mockSetValue ) . toHaveBeenCalledWith ( SettingScope . User , 'mcpServers' , {
133+ 'http-server' : {
134+ httpUrl : 'https://example.com/mcp' ,
135+ headers : { Authorization : 'Bearer your-token' } ,
112136 } ,
113- ) ;
137+ } ) ;
114138 } ) ;
115139
116140 it ( 'should handle MCP server args with -- separator' , async ( ) => {
117141 await parser . parseAsync (
118142 'add my-server npx -- -y http://example.com/some-package' ,
119143 ) ;
120144
121- expect ( mockSetValue ) . toHaveBeenCalledWith (
122- SettingScope . Workspace ,
123- 'mcpServers' ,
124- {
125- 'my-server' : {
126- command : 'npx' ,
127- args : [ '-y' , 'http://example.com/some-package' ] ,
128- } ,
145+ expect ( mockSetValue ) . toHaveBeenCalledWith ( SettingScope . User , 'mcpServers' , {
146+ 'my-server' : {
147+ command : 'npx' ,
148+ args : [ '-y' , 'http://example.com/some-package' ] ,
129149 } ,
130- ) ;
150+ } ) ;
131151 } ) ;
132152
133153 it ( 'should handle unknown options as MCP server args' , async ( ) => {
134154 await parser . parseAsync (
135155 'add test-server npx -y http://example.com/some-package' ,
136156 ) ;
137157
138- expect ( mockSetValue ) . toHaveBeenCalledWith (
139- SettingScope . Workspace ,
140- 'mcpServers' ,
141- {
142- 'test-server' : {
143- command : 'npx' ,
144- args : [ '-y' , 'http://example.com/some-package' ] ,
145- } ,
158+ expect ( mockSetValue ) . toHaveBeenCalledWith ( SettingScope . User , 'mcpServers' , {
159+ 'test-server' : {
160+ command : 'npx' ,
161+ args : [ '-y' , 'http://example.com/some-package' ] ,
146162 } ,
147- ) ;
163+ } ) ;
148164 } ) ;
149165
150166 describe ( 'when handling scope and directory' , ( ) => {
@@ -166,10 +182,10 @@ describe('mcp add command', () => {
166182 setupMocks ( '/path/to/project' , '/path/to/project' ) ;
167183 } ) ;
168184
169- it ( 'should use project scope by default' , async ( ) => {
185+ it ( 'should use user scope by default' , async ( ) => {
170186 await parser . parseAsync ( `add ${ serverName } ${ command } ` ) ;
171187 expect ( mockSetValue ) . toHaveBeenCalledWith (
172- SettingScope . Workspace ,
188+ SettingScope . User ,
173189 'mcpServers' ,
174190 expect . any ( Object ) ,
175191 ) ;
@@ -199,10 +215,10 @@ describe('mcp add command', () => {
199215 setupMocks ( '/path/to/project/subdir' , '/path/to/project' ) ;
200216 } ) ;
201217
202- it ( 'should use project scope by default' , async ( ) => {
218+ it ( 'should use user scope by default' , async ( ) => {
203219 await parser . parseAsync ( `add ${ serverName } ${ command } ` ) ;
204220 expect ( mockSetValue ) . toHaveBeenCalledWith (
205- SettingScope . Workspace ,
221+ SettingScope . User ,
206222 'mcpServers' ,
207223 expect . any ( Object ) ,
208224 ) ;
@@ -214,22 +230,14 @@ describe('mcp add command', () => {
214230 setupMocks ( '/home/user' , '/home/user' ) ;
215231 } ) ;
216232
217- it ( 'should show an error by default' , async ( ) => {
218- const mockProcessExit = vi
219- . spyOn ( process , 'exit' )
220- . mockImplementation ( ( ( ) => {
221- throw new Error ( 'process.exit called' ) ;
222- } ) as ( code ?: number ) => never ) ;
223-
224- await expect (
225- parser . parseAsync ( `add ${ serverName } ${ command } ` ) ,
226- ) . rejects . toThrow ( 'process.exit called' ) ;
227-
228- expect ( mockWriteStderrLine ) . toHaveBeenCalledWith (
229- 'Error: Please use --scope user to edit settings in the home directory.' ,
233+ it ( 'should use user scope by default without error' , async ( ) => {
234+ await parser . parseAsync ( `add ${ serverName } ${ command } ` ) ;
235+ expect ( mockSetValue ) . toHaveBeenCalledWith (
236+ SettingScope . User ,
237+ 'mcpServers' ,
238+ expect . any ( Object ) ,
230239 ) ;
231- expect ( mockProcessExit ) . toHaveBeenCalledWith ( 1 ) ;
232- expect ( mockSetValue ) . not . toHaveBeenCalled ( ) ;
240+ expect ( mockWriteStderrLine ) . not . toHaveBeenCalled ( ) ;
233241 } ) ;
234242
235243 it ( 'should show an error when --scope=project is used explicitly' , async ( ) => {
@@ -266,16 +274,16 @@ describe('mcp add command', () => {
266274 setupMocks ( '/home/user/some/dir' , '/home/user/some/dir' ) ;
267275 } ) ;
268276
269- it ( 'should use project scope by default' , async ( ) => {
277+ it ( 'should use user scope by default' , async ( ) => {
270278 await parser . parseAsync ( `add ${ serverName } ${ command } ` ) ;
271279 expect ( mockSetValue ) . toHaveBeenCalledWith (
272- SettingScope . Workspace ,
280+ SettingScope . User ,
273281 'mcpServers' ,
274282 expect . any ( Object ) ,
275283 ) ;
276284 } ) ;
277285
278- it ( 'should write to the WORKSPACE scope, not the USER scope ' , async ( ) => {
286+ it ( 'should write to the USER scope by default ' , async ( ) => {
279287 await parser . parseAsync ( `add my-new-server echo` ) ;
280288
281289 // We expect setValue to be called once.
@@ -284,8 +292,8 @@ describe('mcp add command', () => {
284292 // We get the scope that setValue was called with.
285293 const calledScope = mockSetValue . mock . calls [ 0 ] [ 0 ] ;
286294
287- // We assert that the scope was Workspace, not User .
288- expect ( calledScope ) . toBe ( SettingScope . Workspace ) ;
295+ // We assert that the scope was User by default .
296+ expect ( calledScope ) . toBe ( SettingScope . User ) ;
289297 } ) ;
290298 } ) ;
291299
@@ -294,10 +302,10 @@ describe('mcp add command', () => {
294302 setupMocks ( '/tmp/foo' , '/tmp/foo' ) ;
295303 } ) ;
296304
297- it ( 'should use project scope by default' , async ( ) => {
305+ it ( 'should use user scope by default' , async ( ) => {
298306 await parser . parseAsync ( `add ${ serverName } ${ command } ` ) ;
299307 expect ( mockSetValue ) . toHaveBeenCalledWith (
300- SettingScope . Workspace ,
308+ SettingScope . User ,
301309 'mcpServers' ,
302310 expect . any ( Object ) ,
303311 ) ;
@@ -328,12 +336,12 @@ describe('mcp add command', () => {
328336 } ) ;
329337 } ) ;
330338
331- it ( 'should update the existing server in the project scope' , async ( ) => {
339+ it ( 'should update the existing server in the user scope by default ' , async ( ) => {
332340 await parser . parseAsync (
333341 `add ${ serverName } ${ updatedCommand } ${ updatedArgs . join ( ' ' ) } ` ,
334342 ) ;
335343 expect ( mockSetValue ) . toHaveBeenCalledWith (
336- SettingScope . Workspace ,
344+ SettingScope . User ,
337345 'mcpServers' ,
338346 expect . objectContaining ( {
339347 [ serverName ] : expect . objectContaining ( {
0 commit comments