Feature #80: The URL hostname extraction feature enhances the readability of MCP server configurations by displaying only the hostname portion for URL-based servers in the SOURCE column, instead of the full URL.
Before this feature, URL-based MCP servers displayed their full URLs in the SOURCE column, which could be:
- Verbose: Long URLs with protocols, ports, and paths cluttered the output
- Hard to Read: Difficult to quickly identify the server location
- Inconsistent: Mixed display of commands and full URLs in the same column
Before (Full URL Display):
SOURCE | STATUS | NAME | TRANSPORT
http://localhost:3000/mcp | ❌ | local-server | http
https://api.example.com | ❌ | api-server | http
npx mcp-server | ❌ | stdio-server | stdio
After (Hostname Display):
SOURCE | STATUS | NAME | TRANSPORT
localhost | ❌ | local-server | http
api.example.com | ❌ | api-server | http
npx mcp-server | ❌ | stdio-server | stdio
The system automatically detects when an MCP server configuration contains a url field, indicating it's a URL-based server.
Uses Node.js built-in URL constructor to parse URLs and extract the hostname portion:
- Protocol: Stripped from display (http://, https://, etc.)
- Hostname: Preserved and displayed (localhost, api.example.com, etc.)
- Port: Stripped from display (:3000, :8080, etc.)
- Path: Stripped from display (/mcp, /v1/mcp, etc.)
- Query Parameters: Stripped from display (?param=value)
Automatically adds http:// protocol if none is specified for proper parsing:
// Input: "localhost:3000"
// Processed: "http://localhost:3000"
// Output: "localhost"If URL parsing fails for any reason, the original string is displayed as a fallback:
// Input: "invalid-url"
// Parsing fails → fallback to original
// Output: "invalid-url"Located in src/utils/url-utils.ts:
export function extractHostname(urlString: string): string {
try {
// Handle URLs without protocol by adding a default one
let urlToParse = urlString
if (!urlToParse.includes('://')) {
urlToParse = `http://${urlToParse}`
}
const url = new URL(urlToParse)
return url.hostname
} catch (error) {
// If URL parsing fails, return the original string
return urlString
}
}The feature is integrated into two key services:
- Extracts hostname during server configuration conversion
- Updates the
sourcefield whenserverConfig.urlis present - Maintains backward compatibility for non-URL servers
- Sets the
sourcefield to hostname when URL is available - Ensures consistent display across all server information
Updated src/types/mcp-config-service.types.ts to include optional url field:
export interface MCPServerConfig {
name: string
command?: string
args?: string[]
type?: string
url?: string // ← New field for URL-based servers
env?: Record<string, string>
}- HTTP:
http://localhost:3000 - HTTPS:
https://api.example.com - Custom:
ws://localhost:8080,tcp://192.168.1.100 - Protocol-less:
localhost:3000(auto-addshttp://)
- Domain Names:
api.example.com,localhost - IP Addresses:
192.168.1.100,::1(IPv6) - Subdomains:
dev.api.example.com - Local Development:
localhost,127.0.0.1
- Missing Protocol: Automatically adds
http:// - Invalid URLs: Graceful fallback to original string
- Empty Strings: Returns empty string
- Malformed URLs: Fallback to original string
Input: "http://localhost:3000/mcp"
Output: "localhost"
Input: "https://api.example.com/v1/mcp"
Output: "api.example.com"
Input: "http://192.168.1.100:8080"
Output: "192.168.1.100"
Input: "localhost:3000"
Output: "localhost"
Input: "api.example.com"
Output: "api.example.com"
Input: "192.168.1.100:8080"
Output: "192.168.1.100"
Input: "invalid-url"
Output: "invalid-url" (fallback)
Input: ""
Output: ""
Input: "http://"
Output: "" (empty hostname)
- Cleaner Output: SOURCE column is more concise and focused
- Better Scanning: Users can quickly identify server locations
- Consistent Format: All URL-based servers display consistently
- Faster Recognition: Hostnames are easier to read than full URLs
- Reduced Clutter: Less visual noise in the output
- Professional Appearance: Clean, polished display
- Quick Identification: Developers can rapidly identify server locations
- Easier Debugging: Clearer server information for troubleshooting
- Improved Documentation: Cleaner output for sharing and documentation
The feature is thoroughly tested with comprehensive test cases:
- ✅ HTTP/HTTPS URL parsing
- ✅ Protocol-less URL handling
- ✅ IP address extraction
- ✅ Subdomain handling
- ✅ Complex path handling
- ✅ Query parameter handling
- ✅ Port number handling
- ✅ Error handling and fallbacks
- ✅ MCPConfigService integration
- ✅ MCPServerManagerService integration
- ✅ End-to-end URL processing
Located in __tests__/__fixtures__/mcp-config-service/url-based-servers.json:
{
"mcpServers": {
"localhost-server": {
"type": "http",
"url": "http://localhost:3000/mcp"
},
"api-server": {
"type": "http",
"url": "https://api.example.com/mcp"
}
}
}- Custom Hostname Mapping: Allow users to define custom hostname aliases
- Port Display Option: Optional flag to show/hide port numbers
- Protocol Display Option: Optional flag to show/hide protocols
- Hostname Validation: Additional validation for hostname formats
- Display Preferences: User-configurable display options
- Custom Parsing Rules: Extensible parsing for special URL formats
- Internationalization: Support for international domain names
- Check URL Format: Ensure the URL is properly formatted
- Verify Field Name: Confirm the field is named
url(notURLorserverUrl) - Check Parsing: Verify the URL can be parsed by Node.js URL constructor
- URL Validation: Check if the URL string is valid
- Protocol Issues: Ensure protocol is supported or protocol-less format
- Special Characters: Check for unusual characters that might break parsing
- Empty Hostname: URL might have empty hostname portion
- IP Address Display: Verify IP address format is correct
- Subdomain Handling: Check subdomain format and parsing
To debug URL hostname extraction issues:
- Check the original URL string format
- Verify URL parsing with Node.js URL constructor
- Review service integration points
- Check test coverage for similar scenarios
The URL hostname extraction feature significantly improves the user experience of the ls-mcp tool by:
- Enhancing Readability: Cleaner, more focused SOURCE column display
- Improving Usability: Faster server identification and better workflow
- Maintaining Compatibility: Backward compatible with existing configurations
- Providing Robustness: Graceful handling of edge cases and errors
This feature represents a thoughtful enhancement that addresses real user needs while maintaining the tool's reliability and performance characteristics.