@@ -1031,6 +1031,84 @@ def test_configure_mcp_server_stdio(self, mock_run, mock_find):
10311031 # Should call run_command 4 times: 3 for removing from all scopes, once for add
10321032 assert mock_run .call_count == 4
10331033
1034+ @patch ('setup_environment.find_command_robust' )
1035+ @patch ('setup_environment.run_command' )
1036+ def test_configure_mcp_server_http_with_ampersand_in_url (self , mock_run , mock_find ):
1037+ """Test configuring HTTP MCP server with URL containing ampersand.
1038+
1039+ This tests the fix for the bug where URLs with '&' query parameters
1040+ were incorrectly interpreted as command separators in Windows CMD/PowerShell.
1041+ """
1042+ mock_find .return_value = 'claude'
1043+ mock_run .return_value = subprocess .CompletedProcess ([], 0 , '' , '' )
1044+
1045+ server = {
1046+ 'name' : 'supabase' ,
1047+ 'scope' : 'user' ,
1048+ 'transport' : 'http' ,
1049+ 'url' : 'https://mcp.supabase.com/mcp?project_ref=xxx&read_only=true' ,
1050+ }
1051+
1052+ result = setup_environment .configure_mcp_server (server )
1053+ assert result is True
1054+ # Should call run_command 4 times: 3 for removing from all scopes, once for add
1055+ assert mock_run .call_count == 4
1056+ # Check the last call (add command) contains the full URL
1057+ add_cmd_str = ' ' .join (str (arg ) for arg in mock_run .call_args_list [3 ][0 ][0 ])
1058+ assert 'mcp add' in add_cmd_str
1059+ assert 'supabase' in add_cmd_str
1060+ # The URL should be in the command (not split by &)
1061+ assert 'project_ref=xxx' in add_cmd_str
1062+ assert 'read_only=true' in add_cmd_str
1063+
1064+ @patch ('setup_environment.find_command_robust' )
1065+ @patch ('setup_environment.run_command' )
1066+ def test_configure_mcp_server_http_with_multiple_query_params (self , mock_run , mock_find ):
1067+ """Test configuring HTTP MCP server with URL containing multiple special characters."""
1068+ mock_find .return_value = 'claude'
1069+ mock_run .return_value = subprocess .CompletedProcess ([], 0 , '' , '' )
1070+
1071+ server = {
1072+ 'name' : 'test-api' ,
1073+ 'scope' : 'user' ,
1074+ 'transport' : 'http' ,
1075+ 'url' : 'https://api.example.com/v1?key=abc&token=xyz&mode=read&format=json' ,
1076+ }
1077+
1078+ result = setup_environment .configure_mcp_server (server )
1079+ assert result is True
1080+ # Check all query parameters are preserved in the command
1081+ add_cmd_str = ' ' .join (str (arg ) for arg in mock_run .call_args_list [3 ][0 ][0 ])
1082+ assert 'key=abc' in add_cmd_str
1083+ assert 'token=xyz' in add_cmd_str
1084+ assert 'mode=read' in add_cmd_str
1085+ assert 'format=json' in add_cmd_str
1086+
1087+ @patch ('setup_environment.find_command_robust' )
1088+ @patch ('setup_environment.run_command' )
1089+ def test_configure_mcp_server_http_with_header_and_special_url (self , mock_run , mock_find ):
1090+ """Test configuring HTTP MCP server with header and URL containing special characters."""
1091+ mock_find .return_value = 'claude'
1092+ mock_run .return_value = subprocess .CompletedProcess ([], 0 , '' , '' )
1093+
1094+ server = {
1095+ 'name' : 'auth-api' ,
1096+ 'scope' : 'user' ,
1097+ 'transport' : 'http' ,
1098+ 'url' : 'https://api.example.com?client_id=123&scope=read&redirect_uri=http://localhost' ,
1099+ 'header' : 'Authorization: Bearer token123' ,
1100+ }
1101+
1102+ result = setup_environment .configure_mcp_server (server )
1103+ assert result is True
1104+ # Check the command contains both header and full URL
1105+ add_cmd_str = ' ' .join (str (arg ) for arg in mock_run .call_args_list [3 ][0 ][0 ])
1106+ assert 'mcp add' in add_cmd_str
1107+ assert 'auth-api' in add_cmd_str
1108+ assert '--header' in add_cmd_str
1109+ assert 'client_id=123' in add_cmd_str
1110+ assert 'scope=read' in add_cmd_str
1111+
10341112
10351113class TestCreateAdditionalSettings :
10361114 """Test additional settings creation."""
0 commit comments