Skip to content

Commit 3256d50

Browse files
committed
(fix): address review comments on region routing
Pass through credential-bearing endpoints instead of prefixing the region onto the userinfo, document that cached regions (including the 'default' sentinel) can be stale for up to CACHE_TTL_SECONDS after a project migrates, and mark the _endpoint assertion as SDK-internal.
1 parent eb3a40e commit 3256d50

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/mcp_server_appwrite/server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ def build_client_for_request(
228228
# must be addressed through the region subdomain (e.g.
229229
# ``https://sgp.cloud.appwrite.io/v1``); other gateways reject project-scoped
230230
# calls with 401 general_access_forbidden. Regions are looked up once per
231-
# project via the console API and cached briefly.
231+
# project via the console API and cached briefly; the 'default' sentinel is
232+
# cached like any region, so a project that migrates regions may be routed to
233+
# its old home for up to CACHE_TTL_SECONDS.
232234
_project_region_cache: dict[str, tuple[str, float]] = {}
233235

234236

@@ -243,6 +245,10 @@ def resolve_region_endpoint(base_endpoint: str, region: str | None) -> str:
243245
hostname = split.hostname or ""
244246
if not hostname or hostname.startswith(f"{region}."):
245247
return base_endpoint
248+
if "@" in split.netloc:
249+
# Prefixing the netloc would land the region on the userinfo, not the
250+
# host; credential-bearing endpoints are never regional, so pass through.
251+
return base_endpoint
246252
return urlunsplit(split._replace(netloc=f"{region}.{split.netloc}"))
247253

248254

tests/unit/test_server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ def test_resolve_client_routes_target_project_to_home_region(self):
666666
patch.object(server_module, "_lookup_project_region", return_value="sgp"),
667667
):
668668
client = server_module.resolve_client(target_project="proj")
669+
# _endpoint is SDK-internal, but it is the only place the resolved
670+
# endpoint is observable without a network call (context.py reads it too).
669671
self.assertEqual(client._endpoint, "https://sgp.cloud.appwrite.io/v1")
670672

671673

0 commit comments

Comments
 (0)