mcp-combiner 0.20.0.dev2__tar.gz → 0.20.0.dev3__tar.gz

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.
Files changed (98) hide show
  1. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/CHANGELOG.md +15 -3
  2. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/PKG-INFO +1 -1
  3. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/asgi.py +1 -1
  4. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/binding.py +19 -10
  5. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/config.py +48 -3
  6. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/runtime.py +3 -0
  7. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/ui_host/advertise.py +73 -15
  8. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/pyproject.toml +1 -1
  9. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_advertised_origin.py +43 -0
  10. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_binding.py +17 -7
  11. mcp_combiner-0.20.0.dev3/tests/test_public_url.py +59 -0
  12. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/uv.lock +1 -1
  13. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/.gitignore +0 -0
  14. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/.python-version +0 -0
  15. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/LICENSE +0 -0
  16. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/README.md +0 -0
  17. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/__init__.py +0 -0
  18. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/__main__.py +0 -0
  19. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/auth.py +0 -0
  20. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/authprompt.py +0 -0
  21. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/backing.py +0 -0
  22. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/connections.py +0 -0
  23. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/ctl.py +0 -0
  24. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/era.py +0 -0
  25. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/externalservers.py +0 -0
  26. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/fastvalidate.py +0 -0
  27. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/handover.py +0 -0
  28. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/heldcalls.py +0 -0
  29. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/inbound_auth.py +0 -0
  30. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/isolated.py +0 -0
  31. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/listen.py +0 -0
  32. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/meta_tools.py +0 -0
  33. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/middleware.py +0 -0
  34. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/mockserver.py +0 -0
  35. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/mounts.py +0 -0
  36. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/notifications.py +0 -0
  37. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/nvim_channel.py +0 -0
  38. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/nvim_proxy.py +0 -0
  39. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/permissions.py +0 -0
  40. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/proxyfactory.py +0 -0
  41. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/py.typed +0 -0
  42. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/resume_transport.py +0 -0
  43. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/routes.py +0 -0
  44. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/schema.py +0 -0
  45. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/schemafix.py +0 -0
  46. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/server.py +0 -0
  47. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/sharedserver.py +0 -0
  48. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/status.py +0 -0
  49. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/toolcache.py +0 -0
  50. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/ui_host/__init__.py +0 -0
  51. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/ui_host/holder.py +0 -0
  52. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/ui_host/routes.py +0 -0
  53. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/ui_host/sessions.py +0 -0
  54. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/ui_host/static/app-bridge.bundle.js +0 -0
  55. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/ui_host/templates.py +0 -0
  56. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/upstream_era.py +0 -0
  57. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/upstream_listen.py +0 -0
  58. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/mcp_combiner/upstream_session.py +0 -0
  59. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/pyrightconfig.json +0 -0
  60. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/conftest.py +0 -0
  61. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/fakes.py +0 -0
  62. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/fixtures/servers.json +0 -0
  63. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_app_meta.py +0 -0
  64. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_auth.py +0 -0
  65. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_authprompt.py +0 -0
  66. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_combiner_reconnect.py +0 -0
  67. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_config.py +0 -0
  68. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_connections.py +0 -0
  69. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_ctl_lifecycle.py +0 -0
  70. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_elicit_e2e.py +0 -0
  71. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_era.py +0 -0
  72. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_externalservers.py +0 -0
  73. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_handover.py +0 -0
  74. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_inbound_auth.py +0 -0
  75. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_isolated.py +0 -0
  76. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_isolated_lifecycle_e2e.py +0 -0
  77. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_isolated_stdio.py +0 -0
  78. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_live_claude.py +0 -0
  79. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_mockserver.py +0 -0
  80. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_mounts.py +0 -0
  81. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_notifications.py +0 -0
  82. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_notifications_e2e.py +0 -0
  83. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_nvim_channel.py +0 -0
  84. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_nvim_e2e.py +0 -0
  85. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_oauth_mock.py +0 -0
  86. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_permissions.py +0 -0
  87. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_reload_config.py +0 -0
  88. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_resume_transport.py +0 -0
  89. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_route_matrix.py +0 -0
  90. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_schema_fixes.py +0 -0
  91. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_session_filter.py +0 -0
  92. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_session_independence.py +0 -0
  93. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_sharedserver.py +0 -0
  94. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_tool_fetch_wedge.py +0 -0
  95. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_ui_host.py +0 -0
  96. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_upstream_restart.py +0 -0
  97. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_upstream_session.py +0 -0
  98. {mcp_combiner-0.20.0.dev2 → mcp_combiner-0.20.0.dev3}/tests/test_visibility_and_reset_e2e.py +0 -0
@@ -17,12 +17,24 @@ tagged `vX.Y.Z`.
17
17
  silently got the `elicitUnavailable` fallback.)
18
18
  - **Bind to several addresses.** `bind.host` (servers.json) takes a list, and
19
19
  `--host` / `MCP_COMBINER_HOST` a comma-separated one: e.g.
20
- `["127.0.0.1", "tailscale"]` serves loopback and the tailnet but not the
21
- LAN. `tailscale` resolves to this machine's tailnet address at startup; an
20
+ `["127.0.0.1", "auto"]` serves loopback and the tailnet but not the
21
+ LAN. `auto` resolves to this machine's tailnet address at startup; an
22
22
  address that isn't up is skipped with a warning (startup fails only if none
23
23
  bind); a wildcard covers the rest. The UI relay (port + 1) follows the same
24
24
  bind. Any non-loopback bind without an inbound bearer token warns. The pi
25
- plugin connects to the first entry (loopback for a wildcard or `tailscale`).
25
+ plugin connects to the first entry (loopback for a wildcard or `auto`).
26
+ A host name that doesn't resolve at startup is skipped like an address
27
+ that isn't up.
28
+ - **Portable tailnet settings.** `auto` as a whole value, or `{auto}` as the
29
+ host inside a URL, means this machine on its tailnet, in `bind.host`,
30
+ `MCP_COMBINER_UI_ADVERTISE` and `oauth.public_url`. Advertise `auto` (the
31
+ default) now names the MagicDNS name (`tailscale status`) rather than the
32
+ raw tailnet IP, falling back to the IP. `oauth.public_url: "auto"` is
33
+ `http://<magicdns name>:<port>`; `"https://{auto}"` suits `tailscale serve`.
34
+ New `MCP_COMBINER_OAUTH_PUBLIC_URL` (a literal URL) overrides the setting.
35
+ - An explicit advertised origin keeps its own port
36
+ (`MCP_COMBINER_UI_ADVERTISE=http://host:443` gave `http://host:443:9741`),
37
+ and a bare IPv6 host is bracketed.
26
38
  - **Per-server `protocol` setting** — `auto` (default), `legacy` or `2026`:
27
39
  which MCP revision the combiner speaks to an upstream. `auto` asks the server
28
40
  (`server/discover`) before mounting it; a server listing 2026-07-28 is
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: mcp-combiner
3
- Version: 0.20.0-dev.2
3
+ Version: 0.20.0-dev.3
4
4
  Summary: An MCP aggregator — fronts multiple MCP servers behind a single Streamable HTTP endpoint, shareable across clients.
5
5
  Project-URL: Homepage, https://github.com/georgeharker/mcp-companion
6
6
  Project-URL: Repository, https://github.com/georgeharker/mcp-companion
@@ -368,6 +368,7 @@ def create_app(options: ServeOptions | None = None) -> Starlette:
368
368
  """
369
369
  if options is None:
370
370
  options = ServeOptions.from_env()
371
+ RUNTIME.serve_port = options.port
371
372
 
372
373
  combiner, proc_manager = create_combiner(
373
374
  options.config,
@@ -444,7 +445,6 @@ def create_app(options: ServeOptions | None = None) -> Starlette:
444
445
  logger.info("auth: inbound bearer required on /mcp, /sessions, /handover")
445
446
  # The UI host's loopback clients read this to present the same bearer on
446
447
  # their /mcp/<token> calls (the middleware does not exempt loopback).
447
- from mcp_combiner.runtime import RUNTIME
448
448
 
449
449
  RUNTIME.inbound_auth_token = options.auth_token
450
450
  RUNTIME.local_origin = f"http://127.0.0.1:{options.port}"
@@ -2,13 +2,16 @@
2
2
 
3
3
  The bind setting (CLI ``--host`` > ``MCP_COMBINER_HOST`` > servers.json
4
4
  ``bind.host`` > ``127.0.0.1``) is a list: ``"bind": {"host": ["127.0.0.1",
5
- "tailscale"]}``, or comma-separated on the CLI / in the env var. Entries:
5
+ "auto"]}``, or comma-separated on the CLI / in the env var. Entries:
6
6
 
7
7
  - an address (``127.0.0.1``, ``::1``, ``100.101.102.103``);
8
- - ``tailscale`` — this machine's tailnet IPv4, looked up at startup (the same
9
- detection the widget URLs use, ``ui_host.advertise``);
8
+ - ``auto`` — this machine's tailnet IPv4, looked up at startup (the tailnet
9
+ detection the widget URLs use, ``ui_host.advertise``; an IP, so no DNS);
10
10
  - a wildcard (``0.0.0.0`` / ``::``) — every interface; it already covers the
11
- specific addresses, so a list containing one keeps only the wildcards.
11
+ specific addresses, so a list containing one keeps only the wildcards;
12
+ - a host name — resolved when binding; one that doesn't resolve is skipped
13
+ like an address that isn't up. (Prefer ``auto`` to a MagicDNS name: same
14
+ address, no DNS dependency.)
12
15
 
13
16
  An address that isn't up when the combiner starts (Tailscale down, an
14
17
  interface gone) is skipped with a warning rather than failing startup; a
@@ -24,10 +27,11 @@ import logging
24
27
  import socket
25
28
  from collections.abc import Sequence
26
29
 
30
+ from mcp_combiner.ui_host.advertise import AUTO
31
+
27
32
  logger = logging.getLogger("mcp-combiner")
28
33
 
29
34
  DEFAULT_HOST = "127.0.0.1"
30
- TAILSCALE = "tailscale"
31
35
  WILDCARDS = frozenset({"0.0.0.0", "::"})
32
36
 
33
37
 
@@ -45,11 +49,11 @@ def parse_hosts(value: str | Sequence[str] | None) -> list[str]:
45
49
 
46
50
 
47
51
  def resolve_hosts(entries: Sequence[str]) -> list[str]:
48
- """Concrete addresses for *entries*: ``tailscale`` looked up, wildcards
52
+ """Concrete addresses for *entries*: ``auto`` looked up, wildcards
49
53
  collapsed, unavailable aliases dropped (warned). ``[]`` → the default."""
50
54
  hosts: list[str] = []
51
55
  for entry in entries or [DEFAULT_HOST]:
52
- if entry.lower() == TAILSCALE:
56
+ if entry.lower() == AUTO:
53
57
  address = tailnet_address()
54
58
  if address is None:
55
59
  logger.warning(
@@ -69,9 +73,9 @@ def resolve_hosts(entries: Sequence[str]) -> list[str]:
69
73
 
70
74
  def tailnet_address() -> str | None:
71
75
  """This machine's Tailscale IPv4, or ``None``."""
72
- from mcp_combiner.ui_host.advertise import _interface_scan_ip, _tailscale_ip
76
+ from mcp_combiner.ui_host.advertise import tailnet_ip
73
77
 
74
- return _tailscale_ip() or _interface_scan_ip()
78
+ return tailnet_ip()
75
79
 
76
80
 
77
81
  def is_loopback(host: str) -> bool:
@@ -112,7 +116,12 @@ def _bind_one(host: str, port: int) -> socket.socket | None:
112
116
  sock.listen(2048)
113
117
  except OSError as exc:
114
118
  sock.close()
115
- if exc.errno in (errno.EADDRNOTAVAIL, errno.EAFNOSUPPORT):
119
+ # gaierror: a name that doesn't resolve (yet) — e.g. a MagicDNS name
120
+ # while Tailscale is down.
121
+ if isinstance(exc, socket.gaierror) or exc.errno in (
122
+ errno.EADDRNOTAVAIL,
123
+ errno.EAFNOSUPPORT,
124
+ ):
116
125
  logger.warning("bind: %s:%d isn't available here (%s) — skipped", host, port, exc)
117
126
  return None
118
127
  raise
@@ -692,6 +692,12 @@ class OAuthConfig(BaseModel):
692
692
  OAuth client (for Google: a Web-application client). When unset, the
693
693
  loopback callback is used, which completes only from a browser on the
694
694
  combiner host.
695
+
696
+ ``"auto"`` keeps the config portable: this machine's Tailscale MagicDNS
697
+ name on the combiner's port, or unset when there is no tailnet. Inside a
698
+ URL, ``{auto}`` is that name (``"https://{auto}"`` for ``tailscale
699
+ serve``). ``$MCP_COMBINER_OAUTH_PUBLIC_URL`` (a literal URL) overrides the
700
+ setting. Stored resolved — see :func:`resolve_public_url`.
695
701
  """
696
702
 
697
703
  prompt: AuthPrompt | None = None
@@ -711,7 +717,7 @@ class OAuthConfig(BaseModel):
711
717
  public_url = data.get("public_url") or data.get("publicUrl")
712
718
  if public_url is not None and not isinstance(public_url, str):
713
719
  raise ValueError("oauth.public_url must be a string")
714
- public_url = public_url.rstrip("/") if public_url else None
720
+ public_url = resolve_public_url(public_url)
715
721
  raw_prompt = data.get("prompt")
716
722
  prompt = (
717
723
  None
@@ -726,6 +732,45 @@ class OAuthConfig(BaseModel):
726
732
  )
727
733
 
728
734
 
735
+ PUBLIC_URL_ENV = "MCP_COMBINER_OAUTH_PUBLIC_URL"
736
+
737
+
738
+ def resolve_public_url(setting: str | None) -> str | None:
739
+ """The concrete ``oauth.public_url``.
740
+
741
+ ``$MCP_COMBINER_OAUTH_PUBLIC_URL``, when set, is the URL, verbatim.
742
+ Otherwise the *setting*: a literal URL; ``auto`` — this machine's
743
+ Tailscale MagicDNS name (else its tailnet IP) on the combiner's port; or a
744
+ URL with ``{auto}`` as its host (``https://{auto}`` for ``tailscale
745
+ serve``). No tailnet → ``None``: links use the loopback callback.
746
+ """
747
+ env = os.environ.get(PUBLIC_URL_ENV, "").strip()
748
+ if env:
749
+ return env.rstrip("/")
750
+ from mcp_combiner.ui_host.advertise import AUTO, AUTO_HOST, tailnet_host
751
+
752
+ value = (setting or "").strip().rstrip("/")
753
+ if not value:
754
+ return None
755
+ if value.lower() == AUTO:
756
+ value = f"http://{AUTO_HOST}"
757
+ elif "://" not in value:
758
+ value = f"http://{value}"
759
+ if AUTO_HOST not in value:
760
+ return value
761
+ name = tailnet_host()
762
+ if name is None:
763
+ logger.info("oauth.public_url %s: no tailnet here — links use the loopback callback", value)
764
+ return None
765
+ scheme, _, rest = value.partition("://")
766
+ authority, slash, path = rest.partition("/")
767
+ if authority == AUTO_HOST and scheme == "http":
768
+ from mcp_combiner.runtime import RUNTIME
769
+
770
+ authority = f"{AUTO_HOST}:{RUNTIME.serve_port or 9741}"
771
+ return f"{scheme}://{authority.replace(AUTO_HOST, name)}{slash}{path}"
772
+
773
+
729
774
  class IsolationConfig(BaseModel):
730
775
  """Lifecycle knobs for token-keyed isolated upstream sessions.
731
776
 
@@ -764,8 +809,8 @@ class BindConfig(BaseModel):
764
809
  ``0.0.0.0`` serves loopback + every interface (LAN + tailnet) — required
765
810
  for the remote widget leg (docs/designs/advertised-ui-origin.md).
766
811
 
767
- ``host`` may be a list — ``["127.0.0.1", "tailscale"]`` listens on loopback
768
- and the tailnet only (``tailscale`` resolves to this machine's tailnet
812
+ ``host`` may be a list — ``["127.0.0.1", "auto"]`` listens on loopback
813
+ and the tailnet only (``auto`` resolves to this machine's tailnet
769
814
  address at startup); see ``mcp_combiner.binding``.
770
815
  """
771
816
 
@@ -389,6 +389,9 @@ class CombinerRuntime:
389
389
  # The combiner's own loopback base URL (http://127.0.0.1:<port>), set by
390
390
  # create_app — where locally-opened links (OAuth short links) point.
391
391
  local_origin: str | None = None
392
+ # The port the combiner serves on, set by create_app before the config is
393
+ # loaded (oauth.public_url "auto" without a port defaults to it).
394
+ serve_port: int | None = None
392
395
  conn_manager: ConnectionManager | None = None
393
396
  proc_manager: BackingProcessManager | None = None
394
397
 
@@ -8,14 +8,16 @@ advertise knob changes only the origin prefix of `/ui/<token>/…` URLs.
8
8
 
9
9
  Modes (MCP_COMBINER_UI_ADVERTISE, default ``auto``):
10
10
 
11
- - ``auto`` — two-tier discovery: (1) ask tailscaled (``tailscale ip -4`` — the
12
- authoritative answer when the daemon runs), (2) fall back to scanning
13
- interface addresses for Tailscale's reserved CGNAT range (100.64.0.0/10 —
14
- with the caveat that some ISPs assign CGNAT space too, which is why tier 1
15
- exists), (3) neither finds a tailnet → the bind host (loopback today).
11
+ - ``auto`` — this machine's tailnet name, by :func:`tailnet_host`: (1) its
12
+ MagicDNS name (``tailscale status --json``, ``Self.DNSName``), (2) its
13
+ tailnet IP from tailscaled (``tailscale ip -4``), (3) an interface address in
14
+ Tailscale's reserved CGNAT range (100.64.0.0/10 — some ISPs assign CGNAT
15
+ space too, which is why the daemon outranks it); none → the bind host
16
+ (loopback).
16
17
  - ``loopback`` — force local-only URLs (the pre-feature behavior).
17
- - ``http://host[:port]`` — explicit override, the only machine-specific form,
18
- for the tailscale-serve (TLS/MagicDNS) variant.
18
+ - ``http://host[:port]`` — explicit override; ``{auto}`` as the host stands for
19
+ the tailnet name (``https://{auto}`` for the tailscale-serve variant), so the
20
+ setting stays portable. Braces can't occur in a real host name.
19
21
 
20
22
  v1 resolves once at boot (tailnet IP changes are rare; a restart heals). The
21
23
  design doc notes the refinement: a TTL cache behind the URL constructors so
@@ -62,6 +64,45 @@ def _tailscale_ip() -> str | None:
62
64
  return None
63
65
 
64
66
 
67
+ def _tailscale_dns_name() -> str | None:
68
+ """This machine's MagicDNS name from the tailscale daemon, or ``None``
69
+ (daemon absent, MagicDNS off)."""
70
+ import json
71
+
72
+ if shutil.which("tailscale") is None:
73
+ return None
74
+ try:
75
+ out = subprocess.run(
76
+ ["tailscale", "status", "--json", "--peers=false"],
77
+ capture_output=True,
78
+ text=True,
79
+ timeout=_TIER1_TIMEOUT_S,
80
+ check=False,
81
+ )
82
+ status = json.loads(out.stdout or "{}")
83
+ except (OSError, subprocess.TimeoutExpired, ValueError):
84
+ return None
85
+ me = status.get("Self") if isinstance(status, dict) else None
86
+ name = me.get("DNSName") if isinstance(me, dict) else None
87
+ return name.rstrip(".") or None if isinstance(name, str) else None
88
+
89
+
90
+ #: A setting's whole value meaning "this machine's tailnet" (bind, advertise,
91
+ #: oauth.public_url), and the same as a host placeholder inside a URL.
92
+ AUTO = "auto"
93
+ AUTO_HOST = "{auto}"
94
+
95
+
96
+ def tailnet_host() -> str | None:
97
+ """This machine's tailnet name for URLs: MagicDNS name, else tailnet IP."""
98
+ return _tailscale_dns_name() or _tailscale_ip() or _interface_scan_ip()
99
+
100
+
101
+ def tailnet_ip() -> str | None:
102
+ """This machine's tailnet IPv4 (for binding: no DNS involved)."""
103
+ return _tailscale_ip() or _interface_scan_ip()
104
+
105
+
65
106
  def _interface_scan_ip() -> str | None:
66
107
  """Tier 2: scan interface addresses for the CGNAT range.
67
108
 
@@ -108,22 +149,39 @@ def resolve_advertised_host(bind_host: str, mode: str | None = None) -> str:
108
149
  """
109
150
  import os
110
151
 
111
- advertise = (mode or os.environ.get(_ENV) or "auto").strip().lower()
112
- if advertise in ("", "auto"):
113
- found = _tailscale_ip() or _interface_scan_ip()
114
- if found:
115
- return found
116
- # Bind-all is a bind, not a name — never construct URLs with it.
117
- return "127.0.0.1" if bind_host in ("0.0.0.0", "::", "") else bind_host
152
+ advertise = (mode or os.environ.get(_ENV) or AUTO).strip().lower()
153
+ # Bind-all is a bind, not a name — never construct URLs with it.
154
+ local = "127.0.0.1" if bind_host in ("0.0.0.0", "::", "") else bind_host
155
+ if advertise in ("", AUTO):
156
+ return tailnet_host() or local
118
157
  if advertise in ("loopback", "local", "none"):
119
158
  return bind_host
120
159
  # Explicit origin: accept scheme://host[:port] and a bare host alike.
121
160
  if "://" in advertise:
122
161
  advertise = advertise.split("://", 1)[1]
123
- return advertise.rstrip("/") or bind_host
162
+ advertise = advertise.rstrip("/")
163
+ if AUTO_HOST in advertise:
164
+ name = tailnet_host()
165
+ if name is None:
166
+ return local
167
+ advertise = advertise.replace(AUTO_HOST, name)
168
+ return advertise or bind_host
124
169
 
125
170
 
126
171
  def advertised_origin(bind_host: str, port: int, mode: str | None = None) -> str:
127
172
  """The full advertised origin for the UI host page (``http://<host>:<port>``)."""
128
173
  host = resolve_advertised_host(bind_host, mode)
174
+ if _has_port(host):
175
+ return f"http://{host}" # an explicit origin's own port wins
176
+ if ":" in host and not host.startswith("["):
177
+ host = f"[{host}]" # a bare IPv6 address
129
178
  return f"http://{host}:{port}"
179
+
180
+
181
+ def _has_port(host: str) -> bool:
182
+ """Whether *host* already carries ``:port`` (``name:80``, ``[::1]:80``;
183
+ a bare IPv6 address does not)."""
184
+ head, sep, tail = host.rpartition(":")
185
+ if not sep or not tail.isdigit():
186
+ return False
187
+ return head.endswith("]") or ":" not in head
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mcp-combiner"
3
- version = "0.20.0-dev.2"
3
+ version = "0.20.0-dev.3"
4
4
  description = "An MCP aggregator — fronts multiple MCP servers behind a single Streamable HTTP endpoint, shareable across clients."
5
5
  requires-python = ">=3.12"
6
6
  license = "MIT"
@@ -21,6 +21,8 @@ from mcp_combiner.ui_host.advertise import (
21
21
  @pytest.fixture(autouse=True)
22
22
  def _clean_env(monkeypatch: pytest.MonkeyPatch) -> None:
23
23
  monkeypatch.delenv("MCP_COMBINER_UI_ADVERTISE", raising=False)
24
+ # No MagicDNS name unless a test gives one (never the real machine's).
25
+ monkeypatch.setattr("mcp_combiner.ui_host.advertise._tailscale_dns_name", lambda: None)
24
26
 
25
27
 
26
28
  def test_cgnat_range_shape() -> None:
@@ -79,3 +81,44 @@ def test_origin_composition() -> None:
79
81
  advertised_origin("127.0.0.1", 9741, "combiner.example") == "http://combiner.example:9741"
80
82
  )
81
83
  assert advertised_origin("127.0.0.1", 9741, "loopback") == "http://127.0.0.1:9741"
84
+
85
+
86
+ def test_auto_prefers_the_magicdns_name(monkeypatch: pytest.MonkeyPatch) -> None:
87
+ monkeypatch.setattr(
88
+ "mcp_combiner.ui_host.advertise._tailscale_dns_name", lambda: "box.tailnet.ts.net"
89
+ )
90
+ monkeypatch.setattr("mcp_combiner.ui_host.advertise._tailscale_ip", lambda: "100.64.5.5")
91
+ assert resolve_advertised_host("127.0.0.1") == "box.tailnet.ts.net"
92
+ assert advertised_origin("127.0.0.1", 9741, "AUTO") == "http://box.tailnet.ts.net:9741"
93
+
94
+
95
+ def test_auto_placeholder_inside_an_explicit_origin(monkeypatch: pytest.MonkeyPatch) -> None:
96
+ monkeypatch.setattr(
97
+ "mcp_combiner.ui_host.advertise._tailscale_dns_name", lambda: "box.tailnet.ts.net"
98
+ )
99
+ assert advertised_origin("127.0.0.1", 9741, "https://{auto}:443") == (
100
+ "http://box.tailnet.ts.net:443"
101
+ )
102
+ assert advertised_origin("127.0.0.1", 9741, "{auto}") == "http://box.tailnet.ts.net:9741"
103
+ # A host that happens to be called "auto" is just a host.
104
+ assert advertised_origin("127.0.0.1", 9741, "http://auto:8000") == "http://auto:8000"
105
+
106
+
107
+ def test_auto_placeholder_without_a_tailnet_is_local(monkeypatch: pytest.MonkeyPatch) -> None:
108
+ monkeypatch.setattr("mcp_combiner.ui_host.advertise._tailscale_ip", lambda: None)
109
+ monkeypatch.setattr("mcp_combiner.ui_host.advertise._interface_scan_ip", lambda: None)
110
+ assert resolve_advertised_host("0.0.0.0", "https://{auto}") == "127.0.0.1"
111
+
112
+
113
+ @pytest.mark.parametrize(
114
+ ("mode", "origin"),
115
+ [
116
+ ("http://box.tailnet.ts.net", "http://box.tailnet.ts.net:9741"),
117
+ ("http://box.tailnet.ts.net:443", "http://box.tailnet.ts.net:443"),
118
+ ("box.tailnet.ts.net:8080/", "http://box.tailnet.ts.net:8080"),
119
+ ("http://[fd7a::1]:9000", "http://[fd7a::1]:9000"),
120
+ ("fd7a::1", "http://[fd7a::1]:9741"),
121
+ ],
122
+ )
123
+ def test_an_explicit_origin_keeps_its_own_port(mode: str, origin: str) -> None:
124
+ assert advertised_origin("127.0.0.1", 9741, mode) == origin
@@ -29,25 +29,23 @@ def _has_ipv6_loopback() -> bool:
29
29
  class TestParseAndResolve:
30
30
  def test_parse_accepts_strings_lists_and_dedupes(self) -> None:
31
31
  assert binding.parse_hosts("127.0.0.1, ::1,127.0.0.1") == ["127.0.0.1", "::1"]
32
- assert binding.parse_hosts(["127.0.0.1", " tailscale "]) == ["127.0.0.1", "tailscale"]
32
+ assert binding.parse_hosts(["127.0.0.1", " auto "]) == ["127.0.0.1", "auto"]
33
33
  assert binding.parse_hosts("") == []
34
34
  assert binding.parse_hosts(None) == []
35
35
 
36
- def test_tailscale_resolves_to_the_tailnet_address(
37
- self, monkeypatch: pytest.MonkeyPatch
38
- ) -> None:
36
+ def test_auto_resolves_to_the_tailnet_address(self, monkeypatch: pytest.MonkeyPatch) -> None:
39
37
  monkeypatch.setattr(binding, "tailnet_address", lambda: "100.101.102.103")
40
- assert binding.resolve_hosts(["127.0.0.1", "tailscale"]) == [
38
+ assert binding.resolve_hosts(["127.0.0.1", "auto"]) == [
41
39
  "127.0.0.1",
42
40
  "100.101.102.103",
43
41
  ]
44
42
 
45
- def test_missing_tailscale_is_skipped_with_a_warning(
43
+ def test_auto_without_a_tailnet_is_skipped_with_a_warning(
46
44
  self, monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
47
45
  ) -> None:
48
46
  monkeypatch.setattr(binding, "tailnet_address", lambda: None)
49
47
  with caplog.at_level(logging.WARNING, logger="mcp-combiner"):
50
- assert binding.resolve_hosts(["127.0.0.1", "Tailscale"]) == ["127.0.0.1"]
48
+ assert binding.resolve_hosts(["127.0.0.1", "Auto"]) == ["127.0.0.1"]
51
49
  assert "no Tailscale address" in caplog.text
52
50
 
53
51
  def test_a_wildcard_covers_the_rest(self) -> None:
@@ -140,3 +138,15 @@ async def test_a_busy_relay_port_does_not_stop_the_combiner(
140
138
  async with httpx2.AsyncClient(timeout=5.0) as http:
141
139
  assert (await http.get(f"http://127.0.0.1:{combiner.port}/health")).status_code == 200
142
140
  assert "UI relay: can't listen" in (tmp_path / "combiner.log").read_text()
141
+
142
+
143
+ def test_an_unresolvable_name_is_skipped(caplog: pytest.LogCaptureFixture) -> None:
144
+ port = free_port()
145
+ with caplog.at_level(logging.WARNING, logger="mcp-combiner"):
146
+ sockets = binding.bind_sockets(["127.0.0.1", "no-such-host.invalid"], port)
147
+ try:
148
+ assert len(sockets) == 1
149
+ assert "no-such-host.invalid" in caplog.text
150
+ finally:
151
+ for s in sockets:
152
+ s.close()
@@ -0,0 +1,59 @@
1
+ """``oauth.public_url``: the portable ``auto`` setting and the env override."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import pytest
6
+
7
+ from mcp_combiner.config import PUBLIC_URL_ENV, OAuthConfig, resolve_public_url
8
+ from mcp_combiner.runtime import RUNTIME
9
+
10
+ NAME = "box.tailnet.ts.net"
11
+
12
+
13
+ @pytest.fixture(autouse=True)
14
+ def _tailnet(monkeypatch: pytest.MonkeyPatch) -> None:
15
+ monkeypatch.delenv(PUBLIC_URL_ENV, raising=False)
16
+ monkeypatch.setattr("mcp_combiner.ui_host.advertise._tailscale_dns_name", lambda: NAME)
17
+ monkeypatch.setattr(RUNTIME, "serve_port", 9741)
18
+
19
+
20
+ @pytest.mark.parametrize(
21
+ ("setting", "resolved"),
22
+ [
23
+ ("auto", f"http://{NAME}:9741"),
24
+ ("AUTO", f"http://{NAME}:9741"),
25
+ ("{auto}", f"http://{NAME}:9741"),
26
+ ("http://{auto}", f"http://{NAME}:9741"),
27
+ ("https://{auto}", f"https://{NAME}"),
28
+ ("https://{auto}:8443/", f"https://{NAME}:8443"),
29
+ ("http://{auto}:80/prefix", f"http://{NAME}:80/prefix"),
30
+ ("https://auto", "https://auto"), # a host named auto is just a host
31
+ ("https://combiner.example.com/", "https://combiner.example.com"),
32
+ ("combiner.example.com:9741", "http://combiner.example.com:9741"),
33
+ ("", None),
34
+ (None, None),
35
+ ],
36
+ )
37
+ def test_setting_forms(setting: str | None, resolved: str | None) -> None:
38
+ assert resolve_public_url(setting) == resolved
39
+
40
+
41
+ def test_the_env_var_is_a_literal_url_and_wins(monkeypatch: pytest.MonkeyPatch) -> None:
42
+ monkeypatch.setenv(PUBLIC_URL_ENV, "https://auth.example.com/")
43
+ assert resolve_public_url("auto") == "https://auth.example.com"
44
+ assert OAuthConfig.from_dict({}).public_url == "https://auth.example.com"
45
+ monkeypatch.setenv(PUBLIC_URL_ENV, "https://{auto}") # not special in the env
46
+ assert resolve_public_url(None) == "https://{auto}"
47
+
48
+
49
+ def test_auto_without_a_tailnet_means_loopback_links(monkeypatch: pytest.MonkeyPatch) -> None:
50
+ monkeypatch.setattr("mcp_combiner.ui_host.advertise._tailscale_dns_name", lambda: None)
51
+ monkeypatch.setattr("mcp_combiner.ui_host.advertise._tailscale_ip", lambda: None)
52
+ monkeypatch.setattr("mcp_combiner.ui_host.advertise._interface_scan_ip", lambda: None)
53
+ assert resolve_public_url("auto") is None
54
+ config = OAuthConfig.from_dict({"public_url": "auto"})
55
+ assert config.public_url is None and config.prompt is None
56
+
57
+
58
+ def test_the_config_stores_the_resolved_url() -> None:
59
+ assert OAuthConfig.from_dict({"public_url": "auto"}).public_url == f"http://{NAME}:9741"
@@ -712,7 +712,7 @@ wheels = [
712
712
 
713
713
  [[package]]
714
714
  name = "mcp-combiner"
715
- version = "0.20.0-dev.2"
715
+ version = "0.20.0-dev.3"
716
716
  source = { editable = "." }
717
717
  dependencies = [
718
718
  { name = "fastmcp" },