ls-mcp 1.10.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,51 +4,19 @@ export class CredentialDetectionService {
4
4
  */
5
5
  private static readonly CREDENTIAL_PATTERNS = {
6
6
  high: [
7
- // API Keys and Tokens
8
- /api[_-]?key/i,
9
- /api[_-]?token/i,
10
- /access[_-]?token/i,
11
- /secret[_-]?key/i,
12
- /private[_-]?key/i,
13
-
14
- // Authentication Tokens
15
- /auth[_-]?token/i,
16
- /bearer[_-]?token/i,
17
- /jwt[_-]?token/i,
18
- /oauth[_-]?token/i,
7
+ // Generic Key and Token patterns (broad matching)
8
+ /.*key.*/i,
9
+ /.*token.*/i,
19
10
 
20
11
  // Passwords
21
- /password/i,
22
- /passwd/i,
23
- /pwd/i,
24
-
25
- // Credentials
26
- /credential/i,
27
- /creds/i,
28
-
29
- // Specific service patterns
30
- /openai[_-]?api[_-]?key/i,
31
- /anthropic[_-]?api[_-]?key/i,
32
- /firecrawl[_-]?api[_-]?key/i,
33
- /github[_-]?token/i,
34
- /gitlab[_-]?token/i,
35
- /bitbucket[_-]?token/i,
36
-
37
- // Database passwords
38
- /db[_-]?password/i,
39
- /database[_-]?password/i,
40
- /redis[_-]?password/i,
41
- /postgres[_-]?password/i,
42
- /mysql[_-]?password/i,
43
-
44
- // Cloud services
45
- /aws[_-]?secret[_-]?access[_-]?key/i,
46
- /aws[_-]?access[_-]?key[_-]?id/i,
47
- /azure[_-]?key/i,
48
- /gcp[_-]?key/i,
49
- /google[_-]?api[_-]?key/i,
50
- /gemini[_-]?api[_-]?key/i,
51
- /claude[_-]?api[_-]?key/i
12
+ /.*password.*/i,
13
+ /.*passwd.*/i,
14
+ /.*pwd.*/i,
15
+
16
+ // Credentials and Secrets
17
+ /.*credential.*/i,
18
+ /.*creds.*/i,
19
+ /.*secret.*/i
52
20
  ],
53
21
  low: [
54
22
  // Organization and Account IDs
@@ -60,6 +28,217 @@ export class CredentialDetectionService {
60
28
  ]
61
29
  }
62
30
 
31
+ /**
32
+ * Argument patterns for detecting credentials in command-line arguments
33
+ */
34
+ private static readonly ARGUMENT_PATTERNS = {
35
+ high: [
36
+ // API key arguments
37
+ /--api-key/i,
38
+ /--apikey/i,
39
+ /--key/i,
40
+
41
+ // Token arguments
42
+ /--token/i,
43
+ /--access-token/i,
44
+ /--auth-token/i,
45
+ /--bearer-token/i,
46
+
47
+ // Password arguments
48
+ /--password/i,
49
+ /--passwd/i,
50
+ /--pwd/i,
51
+
52
+ // Secret arguments
53
+ /--secret/i,
54
+ /--client-secret/i,
55
+
56
+ // Authentication arguments
57
+ /--auth/i,
58
+ /--authorization/i,
59
+ /--credentials/i,
60
+ /--creds/i
61
+ ],
62
+ low: [
63
+ // Organization and account IDs
64
+ /--org-id/i,
65
+ /--organization-id/i,
66
+ /--account-id/i,
67
+ /--user-id/i
68
+ ]
69
+ }
70
+
71
+ /**
72
+ * Header patterns for detecting credentials in HTTP headers
73
+ */
74
+ private static readonly HEADER_PATTERNS = {
75
+ high: [
76
+ // Authorization headers
77
+ /authorization/i,
78
+ /auth/i,
79
+
80
+ // API key headers
81
+ /x-api-key/i,
82
+ /api-key/i,
83
+ /apikey/i,
84
+
85
+ // Token headers
86
+ /x-access-token/i,
87
+ /access-token/i,
88
+ /bearer-token/i,
89
+ /x-auth-token/i,
90
+ /auth-token/i,
91
+
92
+ // Custom authentication headers
93
+ /x-.*-key/i,
94
+ /x-.*-token/i,
95
+ /x-.*-secret/i,
96
+
97
+ // Service-specific patterns
98
+ /x-github-token/i,
99
+ /x-openai-key/i,
100
+ /x-anthropic-key/i
101
+ ],
102
+ low: [
103
+ // User identification headers
104
+ /x-user-id/i,
105
+ /x-org-id/i,
106
+ /x-organization-id/i,
107
+ /x-account-id/i
108
+ ]
109
+ }
110
+
111
+ /**
112
+ * Variable substitution pattern to detect safe variable references
113
+ */
114
+ private static readonly VARIABLE_SUBSTITUTION_PATTERN = /^\$\{[^}]+\}$/
115
+
116
+ /**
117
+ * Check if a value is a variable substitution pattern (e.g., ${input:token})
118
+ */
119
+ static isVariableSubstitution (value: string): boolean {
120
+ return this.VARIABLE_SUBSTITUTION_PATTERN.test(value)
121
+ }
122
+
123
+ /**
124
+ * Analyze command-line arguments for potential credentials
125
+ */
126
+ static analyzeArguments (args: string[] | undefined): CredentialAnalysisResult {
127
+ if (!args || !Array.isArray(args) || args.length === 0) {
128
+ return {
129
+ hasCredentials: false,
130
+ credentialVars: [],
131
+ riskLevel: 'none'
132
+ }
133
+ }
134
+
135
+ const credentialVars: CredentialVariable[] = []
136
+
137
+ // Check each argument and the next one for credential patterns
138
+ for (let i = 0; i < args.length - 1; i++) {
139
+ const arg = args[i]
140
+ const nextArg = args[i + 1]
141
+
142
+ // Check if current argument matches a credential flag pattern
143
+ const isHighRiskArg = this.ARGUMENT_PATTERNS.high.some(pattern => pattern.test(arg))
144
+ const isLowRiskArg = this.ARGUMENT_PATTERNS.low.some(pattern => pattern.test(arg))
145
+
146
+ if (isHighRiskArg || isLowRiskArg) {
147
+ // The next argument should be the value
148
+ if (nextArg && !nextArg.startsWith('-')) {
149
+ credentialVars.push({
150
+ name: arg,
151
+ value: this.maskValue(nextArg),
152
+ riskLevel: isHighRiskArg ? 'high' : 'low',
153
+ source: 'args'
154
+ })
155
+ i++ // Skip the next argument since we've processed it as a value
156
+ }
157
+ }
158
+ }
159
+
160
+ const hasCredentials = credentialVars.length > 0
161
+ const riskLevel = this.calculateOverallRiskLevel(credentialVars)
162
+
163
+ return {
164
+ hasCredentials,
165
+ credentialVars,
166
+ riskLevel
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Analyze HTTP headers for potential credentials
172
+ */
173
+ static analyzeHeaders (headers: Record<string, string> | undefined): CredentialAnalysisResult {
174
+ if (!headers || typeof headers !== 'object') {
175
+ return {
176
+ hasCredentials: false,
177
+ credentialVars: [],
178
+ riskLevel: 'none'
179
+ }
180
+ }
181
+
182
+ const credentialVars: CredentialVariable[] = []
183
+
184
+ for (const [name, value] of Object.entries(headers)) {
185
+ // Skip variable substitution patterns (they're safe)
186
+ if (this.isVariableSubstitution(value)) {
187
+ continue
188
+ }
189
+
190
+ const isHighRiskHeader = this.HEADER_PATTERNS.high.some(pattern => pattern.test(name))
191
+ const isLowRiskHeader = this.HEADER_PATTERNS.low.some(pattern => pattern.test(name))
192
+
193
+ if (isHighRiskHeader || isLowRiskHeader) {
194
+ credentialVars.push({
195
+ name,
196
+ value: this.maskValue(value),
197
+ riskLevel: isHighRiskHeader ? 'high' : 'low',
198
+ source: 'headers'
199
+ })
200
+ }
201
+ }
202
+
203
+ const hasCredentials = credentialVars.length > 0
204
+ const riskLevel = this.calculateOverallRiskLevel(credentialVars)
205
+
206
+ return {
207
+ hasCredentials,
208
+ credentialVars,
209
+ riskLevel
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Comprehensive analysis of server configuration for credentials
215
+ */
216
+ static analyzeServerConfig (config: {
217
+ env?: Record<string, string>
218
+ args?: string[]
219
+ headers?: Record<string, string>
220
+ }): CredentialAnalysisResult {
221
+ const envResult = this.analyzeEnvironmentVariables(config.env)
222
+ const argsResult = this.analyzeArguments(config.args)
223
+ const headersResult = this.analyzeHeaders(config.headers)
224
+
225
+ // Combine all credential variables
226
+ const allCredentialVars = [
227
+ ...envResult.credentialVars,
228
+ ...argsResult.credentialVars,
229
+ ...headersResult.credentialVars
230
+ ]
231
+
232
+ const hasCredentials = allCredentialVars.length > 0
233
+ const riskLevel = this.calculateOverallRiskLevel(allCredentialVars)
234
+
235
+ return {
236
+ hasCredentials,
237
+ credentialVars: allCredentialVars,
238
+ riskLevel
239
+ }
240
+ }
241
+
63
242
  /**
64
243
  * Check if an environment variable name suggests it might contain credentials
65
244
  */
@@ -83,11 +262,17 @@ export class CredentialDetectionService {
83
262
  const credentialVars: CredentialVariable[] = []
84
263
 
85
264
  for (const [name, value] of Object.entries(env)) {
265
+ // Skip variable substitution patterns (they're safe)
266
+ if (this.isVariableSubstitution(value)) {
267
+ continue
268
+ }
269
+
86
270
  if (this.isPotentialCredential(name)) {
87
271
  credentialVars.push({
88
272
  name,
89
273
  value: this.maskValue(value),
90
- riskLevel: this.assessRiskLevel(name)
274
+ riskLevel: this.assessRiskLevel(name),
275
+ source: 'env'
91
276
  })
92
277
  }
93
278
  }
@@ -157,6 +342,7 @@ export interface CredentialVariable {
157
342
  name: string
158
343
  value: string
159
344
  riskLevel: 'low' | 'high'
345
+ source?: 'env' | 'args' | 'headers'
160
346
  }
161
347
 
162
348
  export interface CredentialAnalysisResult {
@@ -0,0 +1,82 @@
1
+ import path from 'node:path'
2
+ import fs from 'node:fs/promises'
3
+ import { homedir } from 'node:os'
4
+
5
+ export class DirectoryBubbleService {
6
+ /**
7
+ * Find a local MCP config file by bubbling up the directory tree
8
+ * @param localPath - The relative path to search for (e.g., '.vscode/mcp.json')
9
+ * @param startDir - The directory to start searching from
10
+ * @returns The absolute path to the found config file, or null if not found
11
+ */
12
+ async findLocalConfigInParentDirectories (
13
+ localPath: string,
14
+ startDir: string
15
+ ): Promise<string | null> {
16
+ try {
17
+ let currentDir = path.resolve(startDir)
18
+ const homeDir = homedir()
19
+ const rootDir = '/'
20
+ let iterationCount = 0
21
+ const maxIterations = 100 // Safety limit to prevent infinite loops
22
+
23
+ // Check the start directory first
24
+ const startDirResult = await this.checkDirectoryForConfig(currentDir, localPath)
25
+ if (startDirResult) {
26
+ return path.join(currentDir, localPath)
27
+ }
28
+
29
+ // Bubble up directory tree until we reach home directory or root
30
+ while (currentDir !== homeDir && currentDir !== rootDir && iterationCount < maxIterations) {
31
+ const parentDir = this.getParentDirectory(currentDir)
32
+ if (!parentDir || parentDir === currentDir) {
33
+ break
34
+ }
35
+
36
+ // Additional safety check: ensure we're actually moving up the tree
37
+ if (parentDir === currentDir || parentDir.length >= currentDir.length) {
38
+ break
39
+ }
40
+
41
+ currentDir = parentDir
42
+ iterationCount++
43
+
44
+ const found = await this.checkDirectoryForConfig(currentDir, localPath)
45
+ if (found) {
46
+ return path.join(currentDir, localPath)
47
+ }
48
+ }
49
+
50
+ return null
51
+ } catch (error) {
52
+ // Silently catch errors as per requirements
53
+ return null
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Check if a config file exists in the specified directory
59
+ * @param dir - The directory to check
60
+ * @param configPath - The relative path to the config file
61
+ * @returns True if the config file exists and is accessible
62
+ */
63
+ private async checkDirectoryForConfig (dir: string, configPath: string): Promise<boolean> {
64
+ try {
65
+ const fullPath = path.join(dir, configPath)
66
+ await fs.access(fullPath)
67
+ return true
68
+ } catch (error) {
69
+ return false
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Get the parent directory of the specified directory
75
+ * @param dir - The directory to get the parent of
76
+ * @returns The parent directory path, or null if already at root
77
+ */
78
+ private getParentDirectory (dir: string): string | null {
79
+ const parent = path.dirname(dir)
80
+ return parent === dir ? null : parent
81
+ }
82
+ }
@@ -111,6 +111,7 @@ export class MCPConfigParser {
111
111
  command: serverConfig.command || '',
112
112
  args: Array.isArray(serverConfig.args) ? serverConfig.args : undefined,
113
113
  type: this.validateType(serverConfig.type) ? serverConfig.type : this.inferTransportType(serverConfig),
114
+ url: serverConfig.url,
114
115
  env
115
116
  }
116
117
  }
@@ -5,6 +5,8 @@ import util from 'node:util'
5
5
  import { MCPPathRegistry } from './mcp-path-registry.js'
6
6
  import { MCPConfigParser } from './mcp-config-parser.js'
7
7
  import { CredentialDetectionService } from './credential-detection-service.js'
8
+ import { DirectoryBubbleService } from './directory-bubble-service.js'
9
+ import { extractHostname } from '../utils/url-utils.js'
8
10
  import {
9
11
  type MCPAppPathsRecord,
10
12
  type MCPFilePath,
@@ -13,15 +15,23 @@ import {
13
15
  type MCPFileGroupsResultRecord
14
16
  } from '../types/mcp-config-service.types.js'
15
17
 
18
+ export interface MCPConfigServiceOptions {
19
+ enableDirectoryBubbling?: boolean
20
+ }
21
+
16
22
  export class MCPConfigService {
17
23
  private pathRegistry: MCPPathRegistry
18
24
  private currentOS: string
19
25
  private debug: util.DebugLogger
26
+ private directoryBubbleService: DirectoryBubbleService
27
+ private enableDirectoryBubbling: boolean
20
28
 
21
- constructor () {
29
+ constructor (options: MCPConfigServiceOptions = {}) {
22
30
  this.pathRegistry = new MCPPathRegistry()
23
31
  this.currentOS = platform()
24
32
  this.debug = util.debuglog('ls-mcp')
33
+ this.directoryBubbleService = new DirectoryBubbleService()
34
+ this.enableDirectoryBubbling = options.enableDirectoryBubbling ?? false
25
35
  }
26
36
 
27
37
  /**
@@ -154,8 +164,27 @@ export class MCPConfigService {
154
164
  let totalServersCount = 0
155
165
 
156
166
  for (const filePathData of paths) {
157
- const resolvedPath = filePathData.filePath.replace('~', process.env.HOME || '')
158
- const absolutePath = path.resolve(resolvedPath)
167
+ let resolvedPath = filePathData.filePath.replace('~', process.env.HOME || '')
168
+ let absolutePath = path.resolve(resolvedPath)
169
+
170
+ // For local paths, try to bubble up if not found in current directory and if enabled
171
+ if (filePathData.type === 'local' && this.enableDirectoryBubbling) {
172
+ try {
173
+ await fs.access(resolvedPath)
174
+ // File exists in current directory, no need to bubble up
175
+ } catch (error) {
176
+ // File not found in current directory, try to bubble up
177
+ const bubbledPath = await this.directoryBubbleService.findLocalConfigInParentDirectories(
178
+ filePathData.filePath,
179
+ process.cwd()
180
+ )
181
+
182
+ if (bubbledPath) {
183
+ resolvedPath = bubbledPath
184
+ absolutePath = path.resolve(resolvedPath)
185
+ }
186
+ }
187
+ }
159
188
 
160
189
  if (uniqueFilePaths.has(absolutePath)) {
161
190
  continue
@@ -227,16 +256,29 @@ export class MCPConfigService {
227
256
 
228
257
  for (const [serverName, serverConfig] of Object.entries(servers)) {
229
258
  if (serverConfig && typeof serverConfig === 'object') {
259
+ // Determine the source: extract hostname from URL or use command
260
+ let source: string
261
+ if (serverConfig.url) {
262
+ source = extractHostname(serverConfig.url)
263
+ } else {
264
+ source = serverConfig.command || ''
265
+ }
266
+
230
267
  serverInfos.push({
231
268
  name: serverName,
232
269
  command: serverConfig.command || '',
233
270
  args: Array.isArray(serverConfig.args) ? serverConfig.args : undefined,
234
271
  transport: serverConfig.type === 'streamable-http' ? 'http' : serverConfig.type, // Map streamable-http to http
235
272
  type: serverConfig.type,
236
- source: serverConfig.command || '',
273
+ source,
237
274
  env: serverConfig.env,
275
+ headers: serverConfig.headers,
238
276
  status: 'stopped', // Default status, will be updated by server manager
239
- credentials: CredentialDetectionService.analyzeEnvironmentVariables(serverConfig.env)
277
+ credentials: CredentialDetectionService.analyzeServerConfig({
278
+ env: serverConfig.env,
279
+ args: serverConfig.args,
280
+ headers: serverConfig.headers
281
+ })
240
282
  })
241
283
  }
242
284
  }
@@ -93,6 +93,53 @@ export class MCPPathRegistry {
93
93
  ]
94
94
  }
95
95
 
96
+ private static readonly LINUX_PATHS: MCPAppPathsRecord = {
97
+ claude: [
98
+ { filePath: path.join(process.env.HOME || '', '.config', 'Claude', 'claude_desktop_config.json'), type: 'global' }
99
+ ],
100
+ claude_code: [
101
+ { filePath: '.mcp.json', type: 'local' }
102
+ ],
103
+ cursor: [
104
+ { filePath: path.join(process.env.HOME || '', '.cursor', 'mcp.json'), type: 'global' },
105
+ { filePath: path.join('.cursor', 'mcp.json'), type: 'local' }
106
+ ],
107
+ vscode: [
108
+ { filePath: path.join('.vscode', 'mcp.json'), type: 'local' },
109
+ { filePath: path.join(process.env.HOME || '', '.config', 'Code', 'User', 'settings.json'), type: 'global' },
110
+ { filePath: path.join(process.env.HOME || '', '.config', 'Code - Insiders', 'User', 'settings.json'), type: 'global' },
111
+ { filePath: path.join(process.env.HOME || '', '.config', 'Code', 'User', 'mcp.json'), type: 'global' },
112
+ { filePath: path.join(process.env.HOME || '', '.config', 'Code - Insiders', 'User', 'mcp.json'), type: 'global' },
113
+ { filePath: path.join(process.env.HOME || '', '.mcp.json'), type: 'global' }
114
+ ],
115
+ cline: [
116
+ { filePath: path.join(process.env.HOME || '', '.config', 'Code', 'User', 'globalStorage', 'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json'), type: 'global' },
117
+ { filePath: path.join(process.env.HOME || '', '.config', 'Code - Insiders', 'User', 'globalStorage', 'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json'), type: 'global' }
118
+ ],
119
+ windsurf: [
120
+ { filePath: path.join('.codeium', 'windsurf', 'mcp_config.json'), type: 'local' }
121
+ ],
122
+ roo: [
123
+ { filePath: path.join(process.env.HOME || '', '.config', 'Code', 'User', 'globalStorage', 'rooveterinaryinc.roo-cline', 'settings', 'cline_mcp_settings.json'), type: 'global' },
124
+ { filePath: path.join(process.env.HOME || '', '.config', 'Code - Insiders', 'User', 'globalStorage', 'rooveterinaryinc.roo-cline', 'settings', 'cline_mcp_settings.json'), type: 'global' }
125
+ ],
126
+ 'intellij-github-copilot': [
127
+ { filePath: path.join(process.env.HOME || '', '.config', 'github-copilot', 'intellij', 'mcp.json'), type: 'global' }
128
+ ],
129
+ junie: [
130
+ { filePath: path.join(process.env.HOME || '', '.junie', 'mcp.json'), type: 'global' },
131
+ { filePath: path.join('.junie', 'mcp', 'mcp.json'), type: 'local' }
132
+ ],
133
+ zed: [
134
+ { filePath: path.join(process.env.HOME || '', '.config', 'zed', 'settings.json'), type: 'global' },
135
+ { filePath: path.join('.zed', 'settings.json'), type: 'local' }
136
+ ],
137
+ gemini: [
138
+ { filePath: path.join(process.env.HOME || '', '.gemini', 'settings.json'), type: 'global' },
139
+ { filePath: path.join('.gemini', 'settings.json'), type: 'local' }
140
+ ]
141
+ }
142
+
96
143
  private customApps: Map<string, MCPAppPathsRecord> = new Map()
97
144
 
98
145
  /**
@@ -106,6 +153,8 @@ export class MCPPathRegistry {
106
153
  case 'darwin':
107
154
  case 'macos':
108
155
  return { ...MCPPathRegistry.DARWIN_PATHS }
156
+ case 'linux':
157
+ return { ...MCPPathRegistry.LINUX_PATHS }
109
158
  default:
110
159
  throw new Error(`Unsupported operating system: ${os}`)
111
160
  }
@@ -137,7 +186,7 @@ export class MCPPathRegistry {
137
186
  * Get all supported operating systems
138
187
  */
139
188
  getSupportedOperatingSystems (): string[] {
140
- return ['win32', 'darwin']
189
+ return ['win32', 'darwin', 'linux']
141
190
  }
142
191
 
143
192
  /**
@@ -1,6 +1,7 @@
1
1
  import path from 'node:path'
2
2
  import { execSync } from 'node:child_process'
3
3
  import { platform } from 'node:os'
4
+ import { extractHostname } from '../utils/url-utils.js'
4
5
 
5
6
  interface MCPServerConfig {
6
7
  name: string
@@ -46,7 +47,7 @@ export class MCPServerManagerService {
46
47
  }
47
48
 
48
49
  if (serverConfig.url) {
49
- this.source = serverConfig.url
50
+ this.source = extractHostname(serverConfig.url)
50
51
  this.transport = 'http' // URLs always use http transport
51
52
  } else {
52
53
  // Build the full command with arguments
@@ -11,7 +11,9 @@ export interface MCPServerConfig {
11
11
  args?: string[]
12
12
  transport?: 'stdio' | 'sse' | 'http'
13
13
  type?: 'sse' | 'http' | 'stdio' | 'streamable-http'
14
+ url?: string
14
15
  env?: Record<string, string>
16
+ headers?: Record<string, string>
15
17
  }
16
18
 
17
19
  export interface MCPAppMetadata {
@@ -35,6 +37,7 @@ export interface MCPServerInfo {
35
37
  type?: 'sse' | 'http' | 'stdio' | 'streamable-http'
36
38
  source?: string
37
39
  env?: Record<string, string>
40
+ headers?: Record<string, string>
38
41
  status?: 'running' | 'stopped'
39
42
  credentials?: CredentialAnalysisResult
40
43
  }
@@ -66,6 +69,7 @@ export interface CredentialVariable {
66
69
  name: string
67
70
  value: string
68
71
  riskLevel: 'low' | 'high'
72
+ source?: 'env' | 'args' | 'headers'
69
73
  }
70
74
 
71
75
  export interface CredentialAnalysisResult {
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Utility functions for URL operations
3
+ */
4
+
5
+ /**
6
+ * Extract hostname from a URL string
7
+ * @param urlString - The URL string to extract hostname from
8
+ * @returns The hostname if valid URL, or the original string if parsing fails
9
+ */
10
+ export function extractHostname (urlString: string): string {
11
+ try {
12
+ // Handle URLs without protocol by adding a default one
13
+ let urlToParse = urlString
14
+ if (!urlToParse.includes('://')) {
15
+ urlToParse = `http://${urlToParse}`
16
+ }
17
+
18
+ const url = new URL(urlToParse)
19
+ return url.hostname
20
+ } catch (error) {
21
+ // If URL parsing fails, return the original string
22
+ return urlString
23
+ }
24
+ }