MCPcopy Create free account
hub / github.com/IBM/mcp-cli / is_trusted_domain

Method is_trusted_domain

src/mcp_cli/utils/preferences.py:372–396  ·  view source on GitHub ↗

Check if a server URL belongs to a trusted domain. Args: server_url: The server URL to check (may be None for STDIO servers) Returns: True if the server's domain matches a trusted domain

(self, server_url: str | None)

Source from the content-addressed store, hash-verified

370 return True # type: ignore[unreachable] # safety fallback
371
372 def is_trusted_domain(self, server_url: str | None) -> bool:
373 """Check if a server URL belongs to a trusted domain.
374
375 Args:
376 server_url: The server URL to check (may be None for STDIO servers)
377
378 Returns:
379 True if the server's domain matches a trusted domain
380 """
381 if not server_url:
382 return False
383
384 from urllib.parse import urlparse
385
386 try:
387 parsed = urlparse(server_url)
388 hostname = parsed.hostname or ""
389 except Exception:
390 return False
391
392 trusted = self.preferences.ui.tool_confirmation.trusted_domains
393 for domain in trusted:
394 if hostname == domain or hostname.endswith(f".{domain}"):
395 return True
396 return False
397
398 def get_trusted_domains(self) -> list[str]:
399 """Get the list of trusted domains."""

Callers 10

_should_confirm_toolMethod · 0.80
test_exact_matchMethod · 0.80
test_subdomain_matchMethod · 0.80
test_none_urlMethod · 0.80
test_empty_urlMethod · 0.80
test_no_schemeMethod · 0.80
test_http_schemeMethod · 0.80

Calls

no outgoing calls

Tested by 9

test_exact_matchMethod · 0.64
test_subdomain_matchMethod · 0.64
test_none_urlMethod · 0.64
test_empty_urlMethod · 0.64
test_no_schemeMethod · 0.64
test_http_schemeMethod · 0.64