mcp-combiner 0.20.0.dev3__tar.gz → 0.20.0.dev5__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 (99) hide show
  1. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/CHANGELOG.md +13 -0
  2. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/PKG-INFO +1 -1
  3. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/auth.py +3 -5
  4. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/config.py +113 -7
  5. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/mockserver.py +33 -2
  6. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/pyproject.toml +1 -1
  7. mcp_combiner-0.20.0.dev5/tests/test_public_url.py +146 -0
  8. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/uv.lock +1 -1
  9. mcp_combiner-0.20.0.dev3/tests/test_public_url.py +0 -59
  10. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/.gitignore +0 -0
  11. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/.python-version +0 -0
  12. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/LICENSE +0 -0
  13. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/README.md +0 -0
  14. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/__init__.py +0 -0
  15. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/__main__.py +0 -0
  16. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/asgi.py +0 -0
  17. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/authprompt.py +0 -0
  18. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/backing.py +0 -0
  19. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/binding.py +0 -0
  20. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/connections.py +0 -0
  21. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/ctl.py +0 -0
  22. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/era.py +0 -0
  23. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/externalservers.py +0 -0
  24. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/fastvalidate.py +0 -0
  25. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/handover.py +0 -0
  26. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/heldcalls.py +0 -0
  27. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/inbound_auth.py +0 -0
  28. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/isolated.py +0 -0
  29. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/listen.py +0 -0
  30. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/meta_tools.py +0 -0
  31. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/middleware.py +0 -0
  32. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/mounts.py +0 -0
  33. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/notifications.py +0 -0
  34. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/nvim_channel.py +0 -0
  35. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/nvim_proxy.py +0 -0
  36. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/permissions.py +0 -0
  37. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/proxyfactory.py +0 -0
  38. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/py.typed +0 -0
  39. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/resume_transport.py +0 -0
  40. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/routes.py +0 -0
  41. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/runtime.py +0 -0
  42. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/schema.py +0 -0
  43. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/schemafix.py +0 -0
  44. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/server.py +0 -0
  45. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/sharedserver.py +0 -0
  46. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/status.py +0 -0
  47. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/toolcache.py +0 -0
  48. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/ui_host/__init__.py +0 -0
  49. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/ui_host/advertise.py +0 -0
  50. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/ui_host/holder.py +0 -0
  51. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/ui_host/routes.py +0 -0
  52. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/ui_host/sessions.py +0 -0
  53. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/ui_host/static/app-bridge.bundle.js +0 -0
  54. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/ui_host/templates.py +0 -0
  55. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/upstream_era.py +0 -0
  56. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/upstream_listen.py +0 -0
  57. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/mcp_combiner/upstream_session.py +0 -0
  58. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/pyrightconfig.json +0 -0
  59. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/conftest.py +0 -0
  60. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/fakes.py +0 -0
  61. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/fixtures/servers.json +0 -0
  62. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_advertised_origin.py +0 -0
  63. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_app_meta.py +0 -0
  64. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_auth.py +0 -0
  65. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_authprompt.py +0 -0
  66. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_binding.py +0 -0
  67. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_combiner_reconnect.py +0 -0
  68. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_config.py +0 -0
  69. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_connections.py +0 -0
  70. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_ctl_lifecycle.py +0 -0
  71. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_elicit_e2e.py +0 -0
  72. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_era.py +0 -0
  73. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_externalservers.py +0 -0
  74. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_handover.py +0 -0
  75. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_inbound_auth.py +0 -0
  76. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_isolated.py +0 -0
  77. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_isolated_lifecycle_e2e.py +0 -0
  78. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_isolated_stdio.py +0 -0
  79. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_live_claude.py +0 -0
  80. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_mockserver.py +0 -0
  81. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_mounts.py +0 -0
  82. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_notifications.py +0 -0
  83. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_notifications_e2e.py +0 -0
  84. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_nvim_channel.py +0 -0
  85. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_nvim_e2e.py +0 -0
  86. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_oauth_mock.py +0 -0
  87. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_permissions.py +0 -0
  88. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_reload_config.py +0 -0
  89. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_resume_transport.py +0 -0
  90. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_route_matrix.py +0 -0
  91. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_schema_fixes.py +0 -0
  92. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_session_filter.py +0 -0
  93. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_session_independence.py +0 -0
  94. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_sharedserver.py +0 -0
  95. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_tool_fetch_wedge.py +0 -0
  96. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_ui_host.py +0 -0
  97. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_upstream_restart.py +0 -0
  98. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_upstream_session.py +0 -0
  99. {mcp_combiner-0.20.0.dev3 → mcp_combiner-0.20.0.dev5}/tests/test_visibility_and_reset_e2e.py +0 -0
@@ -32,6 +32,19 @@ tagged `vX.Y.Z`.
32
32
  raw tailnet IP, falling back to the IP. `oauth.public_url: "auto"` is
33
33
  `http://<magicdns name>:<port>`; `"https://{auto}"` suits `tailscale serve`.
34
34
  New `MCP_COMBINER_OAUTH_PUBLIC_URL` (a literal URL) overrides the setting.
35
+ - `MCP_COMBINER_OAUTH_PUBLIC_URL` (and a literal `public_url`) may be a bare
36
+ host: `http://` and, on plain http, the combiner's port are added. A bare
37
+ host used to become a redirect URI with no scheme, which broke the OAuth
38
+ connection outright.
39
+ - **`{oauth_redirect}` in server entries** expands to that server's callback,
40
+ `<public_url>/oauth/callback/<server>`, in `args`, `env`, `headers` and `url`
41
+ (and in a `sharedServers` / `externalServers` entry used by exactly one
42
+ server), so a server can be told its redirect URI without a machine name in
43
+ the config. Left as-is, with a warning, when there's no public URL.
44
+ - `MCP_COMBINER_OAUTH_PUBLIC_URL` now applies when servers.json has no `oauth`
45
+ block (it was ignored then).
46
+ - Mock server `--issuer` (`auto` = the tailnet name): the authorization server
47
+ URL it advertises, so a phone can complete the mock's OAuth flow.
35
48
  - An explicit advertised origin keeps its own port
36
49
  (`MCP_COMBINER_UI_ADVERTISE=http://host:443` gave `http://host:443:9741`),
37
50
  and a bare IPv6 host is bracketed.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: mcp-combiner
3
- Version: 0.20.0-dev.3
3
+ Version: 0.20.0-dev.5
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
@@ -25,7 +25,7 @@ import time
25
25
  import typing
26
26
  from pathlib import Path
27
27
  from typing import Any, ClassVar
28
- from urllib.parse import parse_qs, quote, urlencode, urljoin, urlparse, urlunparse
28
+ from urllib.parse import parse_qs, urlencode, urljoin, urlparse, urlunparse
29
29
 
30
30
  import anyio
31
31
  import httpx2
@@ -56,7 +56,7 @@ from mcp.shared.auth import AuthorizationCodeResult, OAuthToken
56
56
  from pydantic import AnyHttpUrl
57
57
 
58
58
  from mcp_combiner import authprompt
59
- from mcp_combiner.config import AuthPrompt, resolve_auth_prompt
59
+ from mcp_combiner.config import AuthPrompt, oauth_redirect_uri, resolve_auth_prompt
60
60
 
61
61
  logger = logging.getLogger("mcp-combiner")
62
62
 
@@ -289,9 +289,7 @@ class _RefreshTokenOAuth(OAuth):
289
289
  return
290
290
  # Redirect back to the combiner's own /oauth/callback/<server> route
291
291
  # instead of the loopback callback server the parent configured.
292
- redirect = AnyHttpUrl(
293
- f"{self.public_url}/oauth/callback/{quote(self.server_name, safe='')}"
294
- )
292
+ redirect = AnyHttpUrl(oauth_redirect_uri(self.public_url, self.server_name))
295
293
  self.context.client_metadata.redirect_uris = [redirect]
296
294
  if self._static_client_info is not None:
297
295
  self._static_client_info.redirect_uris = [redirect]
@@ -735,6 +735,22 @@ class OAuthConfig(BaseModel):
735
735
  PUBLIC_URL_ENV = "MCP_COMBINER_OAUTH_PUBLIC_URL"
736
736
 
737
737
 
738
+ def _complete_url(value: str) -> str:
739
+ """A bare host becomes a URL: ``http://`` when there's no scheme, and the
740
+ combiner's port on plain ``http`` with none (``https`` keeps 443)."""
741
+ if "://" not in value:
742
+ value = f"http://{value}"
743
+ scheme, _, rest = value.partition("://")
744
+ authority, slash, path = rest.partition("/")
745
+ from mcp_combiner.ui_host.advertise import _has_port
746
+
747
+ if scheme == "http" and not _has_port(authority):
748
+ from mcp_combiner.runtime import RUNTIME
749
+
750
+ authority = f"{authority}:{RUNTIME.serve_port or 9741}"
751
+ return f"{scheme}://{authority}{slash}{path}"
752
+
753
+
738
754
  def resolve_public_url(setting: str | None) -> str | None:
739
755
  """The concrete ``oauth.public_url``.
740
756
 
@@ -744,9 +760,9 @@ def resolve_public_url(setting: str | None) -> str | None:
744
760
  URL with ``{auto}`` as its host (``https://{auto}`` for ``tailscale
745
761
  serve``). No tailnet → ``None``: links use the loopback callback.
746
762
  """
747
- env = os.environ.get(PUBLIC_URL_ENV, "").strip()
763
+ env = os.environ.get(PUBLIC_URL_ENV, "").strip().rstrip("/")
748
764
  if env:
749
- return env.rstrip("/")
765
+ return _complete_url(env)
750
766
  from mcp_combiner.ui_host.advertise import AUTO, AUTO_HOST, tailnet_host
751
767
 
752
768
  value = (setting or "").strip().rstrip("/")
@@ -757,7 +773,7 @@ def resolve_public_url(setting: str | None) -> str | None:
757
773
  elif "://" not in value:
758
774
  value = f"http://{value}"
759
775
  if AUTO_HOST not in value:
760
- return value
776
+ return _complete_url(value)
761
777
  name = tailnet_host()
762
778
  if name is None:
763
779
  logger.info("oauth.public_url %s: no tailnet here — links use the loopback callback", value)
@@ -771,6 +787,89 @@ def resolve_public_url(setting: str | None) -> str | None:
771
787
  return f"{scheme}://{authority.replace(AUTO_HOST, name)}{slash}{path}"
772
788
 
773
789
 
790
+ OAUTH_REDIRECT = "{oauth_redirect}"
791
+
792
+
793
+ def oauth_redirect_uri(public_url: str, server: str) -> str:
794
+ """Where the combiner receives *server*'s OAuth redirect (the
795
+ ``/oauth/callback/<server>`` route) under *public_url*."""
796
+ from urllib.parse import quote
797
+
798
+ return f"{public_url}/oauth/callback/{quote(server, safe='')}"
799
+
800
+
801
+ def _replace_in(value: Any, text: str) -> Any:
802
+ """*value* with ``{oauth_redirect}`` replaced by *text* in every string."""
803
+ if isinstance(value, str):
804
+ return value.replace(OAUTH_REDIRECT, text)
805
+ if isinstance(value, list):
806
+ return [_replace_in(v, text) for v in value]
807
+ if isinstance(value, dict):
808
+ return {k: _replace_in(v, text) for k, v in value.items()}
809
+ return value
810
+
811
+
812
+ def _mentions(value: Any) -> bool:
813
+ if isinstance(value, str):
814
+ return OAUTH_REDIRECT in value
815
+ if isinstance(value, list):
816
+ return any(_mentions(v) for v in value)
817
+ if isinstance(value, dict):
818
+ return any(_mentions(v) for v in value.values())
819
+ return False
820
+
821
+
822
+ def expand_oauth_redirects(
823
+ servers: dict[str, Any],
824
+ shared: dict[str, Any],
825
+ external: dict[str, Any],
826
+ public_url: str | None,
827
+ ) -> tuple[dict[str, Any], dict[str, Any], dict[str, Any]]:
828
+ """Expand ``{oauth_redirect}`` in raw config entries: a server's own entry
829
+ gets its callback URL (:func:`oauth_redirect_uri`); a ``sharedServers`` /
830
+ ``externalServers`` entry gets the callback of the one server that uses it.
831
+ For servers that must be told the combiner's redirect URI (an external
832
+ OAuth provider setup). Left as-is, with a warning, without a public URL or
833
+ when a backing entry serves several servers."""
834
+ if not any(_mentions(t) for t in (servers, shared, external)):
835
+ return servers, shared, external
836
+ if public_url is None:
837
+ logger.warning(
838
+ "{oauth_redirect} needs oauth.public_url (or %s): left unexpanded", PUBLIC_URL_ENV
839
+ )
840
+ return servers, shared, external
841
+ servers = {
842
+ name: _replace_in(entry, oauth_redirect_uri(public_url, name))
843
+ for name, entry in servers.items()
844
+ }
845
+
846
+ def backing(table: dict[str, Any], keys: tuple[str, ...]) -> dict[str, Any]:
847
+ out: dict[str, Any] = {}
848
+ for name, entry in table.items():
849
+ if not _mentions(entry):
850
+ out[name] = entry
851
+ continue
852
+ users = [
853
+ server
854
+ for server, srv in servers.items()
855
+ if isinstance(srv, dict) and any(srv.get(k) == name for k in keys)
856
+ ]
857
+ if len(users) == 1:
858
+ out[name] = _replace_in(entry, oauth_redirect_uri(public_url, users[0]))
859
+ else:
860
+ logger.warning(
861
+ "{oauth_redirect} in '%s' is ambiguous: used by %s — left unexpanded",
862
+ name,
863
+ users or "no server",
864
+ )
865
+ out[name] = entry
866
+ return out
867
+
868
+ shared = backing(shared, ("sharedServer", "shared_server"))
869
+ external = backing(external, ("externalServer", "external_server"))
870
+ return servers, shared, external
871
+
872
+
774
873
  class IsolationConfig(BaseModel):
775
874
  """Lifecycle knobs for token-keyed isolated upstream sessions.
776
875
 
@@ -885,17 +984,26 @@ class CombinerConfig(BaseModel):
885
984
  except json.JSONDecodeError as exc:
886
985
  raise ValueError(f"Config file {path} is not valid JSON: {exc}") from exc
887
986
 
987
+ # Resolved first: {oauth_redirect} in server entries names its result.
988
+ # Always parsed, so $MCP_COMBINER_OAUTH_PUBLIC_URL applies without an
989
+ # "oauth" block.
990
+ raw_oauth: dict[str, Any] = raw.get("oauth", {})
991
+ oauth = OAuthConfig.from_dict(raw_oauth)
992
+
888
993
  raw_servers: dict[str, Any] = raw.get("servers", raw.get("mcpServers", {}))
994
+ raw_shared: dict[str, Any] = raw.get("sharedServers", {})
995
+ raw_external: dict[str, Any] = raw.get("externalServers", {})
996
+ raw_servers, raw_shared, raw_external = expand_oauth_redirects(
997
+ raw_servers, raw_shared, raw_external, oauth.public_url
998
+ )
889
999
  servers = {
890
1000
  name: ServerConfig.from_dict(name, srv_data) for name, srv_data in raw_servers.items()
891
1001
  }
892
1002
 
893
- raw_shared: dict[str, Any] = raw.get("sharedServers", {})
894
1003
  shared_servers = {
895
1004
  name: SharedServerConfig.from_dict(name, data) for name, data in raw_shared.items()
896
1005
  }
897
1006
 
898
- raw_external: dict[str, Any] = raw.get("externalServers", {})
899
1007
  external_servers = {
900
1008
  name: ExternalServerConfig.from_dict(name, data) for name, data in raw_external.items()
901
1009
  }
@@ -925,8 +1033,6 @@ class CombinerConfig(BaseModel):
925
1033
  field,
926
1034
  )
927
1035
 
928
- raw_oauth: dict[str, Any] = raw.get("oauth", {})
929
- oauth = OAuthConfig.from_dict(raw_oauth) if raw_oauth else OAuthConfig()
930
1036
  # Validates every server's prompt up front (a typo fails the load, not
931
1037
  # the first re-auth) and flags elicitation that can't reach a remote device.
932
1038
  for name, srv in servers.items():
@@ -1391,6 +1391,21 @@ class MockOAuthProvider:
1391
1391
  await send({"type": "http.response.body", "body": body})
1392
1392
 
1393
1393
 
1394
+ def _issuer_url(setting: str | None, local_host: str, port: int) -> str:
1395
+ """The mock's advertised issuer: *setting* (``auto`` = the tailnet name),
1396
+ else ``http://<local_host>:<port>``."""
1397
+ if setting is None:
1398
+ return f"http://{local_host}:{port}"
1399
+ if setting.strip().lower() == "auto":
1400
+ from mcp_combiner.ui_host.advertise import tailnet_host
1401
+
1402
+ name = tailnet_host()
1403
+ if name is None:
1404
+ raise SystemExit("--issuer auto: no tailnet on this machine")
1405
+ return f"http://{name}:{port}"
1406
+ return setting.rstrip("/")
1407
+
1408
+
1394
1409
  def pin_handshake_only(mcp_srv: FastMCP) -> None:
1395
1410
  """Answer server/discover with no supported versions, so a probing client
1396
1411
  (and the combiner's protocol: auto) uses the handshake. HTTP only: on an
@@ -1456,6 +1471,17 @@ def main(argv: list[str] | None = None) -> None:
1456
1471
  "mock__end_session and a visible session_id on mock__remember / mock__recall."
1457
1472
  ),
1458
1473
  )
1474
+ parser.add_argument(
1475
+ "--issuer",
1476
+ default=None,
1477
+ metavar="URL",
1478
+ help=(
1479
+ "With --oauth: the authorization server URL the mock advertises, where "
1480
+ "browsers are sent to log in (default: http://<host>:<port>). 'auto' = "
1481
+ "this machine's tailnet name on --port, so a phone can authorize; bind "
1482
+ "--host to every interface (or the tailnet address) to serve it."
1483
+ ),
1484
+ )
1459
1485
  parser.add_argument(
1460
1486
  "--oauth",
1461
1487
  action="store_true",
@@ -1479,8 +1505,13 @@ def main(argv: list[str] | None = None) -> None:
1479
1505
  parser.error("--oauth requires --transport http")
1480
1506
  import uvicorn
1481
1507
 
1482
- issuer = f"http://{args.host}:{args.port}"
1483
- provider = MockOAuthProvider(resource_url=f"{issuer}/mcp", issuer_url=issuer)
1508
+ from mcp_combiner.binding import WILDCARDS
1509
+
1510
+ local = "127.0.0.1" if args.host in WILDCARDS else args.host
1511
+ issuer = _issuer_url(args.issuer, local, args.port)
1512
+ provider = MockOAuthProvider(
1513
+ resource_url=f"http://{local}:{args.port}/mcp", issuer_url=issuer
1514
+ )
1484
1515
  mcp_srv, _state = build_server(
1485
1516
  args.name, args.transport, specs, state_dir, provider, args.sessions
1486
1517
  )
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mcp-combiner"
3
- version = "0.20.0-dev.3"
3
+ version = "0.20.0-dev.5"
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"
@@ -0,0 +1,146 @@
1
+ """``oauth.public_url``: the portable ``auto`` setting and the env override."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import logging
7
+ from pathlib import Path
8
+
9
+ import pytest
10
+
11
+ from mcp_combiner.config import (
12
+ PUBLIC_URL_ENV,
13
+ CombinerConfig,
14
+ OAuthConfig,
15
+ resolve_public_url,
16
+ )
17
+ from mcp_combiner.runtime import RUNTIME
18
+
19
+ NAME = "box.tailnet.ts.net"
20
+
21
+
22
+ @pytest.fixture(autouse=True)
23
+ def _tailnet(monkeypatch: pytest.MonkeyPatch) -> None:
24
+ monkeypatch.delenv(PUBLIC_URL_ENV, raising=False)
25
+ monkeypatch.setattr("mcp_combiner.ui_host.advertise._tailscale_dns_name", lambda: NAME)
26
+ monkeypatch.setattr(RUNTIME, "serve_port", 9741)
27
+
28
+
29
+ @pytest.mark.parametrize(
30
+ ("setting", "resolved"),
31
+ [
32
+ ("auto", f"http://{NAME}:9741"),
33
+ ("AUTO", f"http://{NAME}:9741"),
34
+ ("{auto}", f"http://{NAME}:9741"),
35
+ ("http://{auto}", f"http://{NAME}:9741"),
36
+ ("https://{auto}", f"https://{NAME}"),
37
+ ("https://{auto}:8443/", f"https://{NAME}:8443"),
38
+ ("http://{auto}:80/prefix", f"http://{NAME}:80/prefix"),
39
+ ("https://auto", "https://auto"), # a host named auto is just a host
40
+ ("https://combiner.example.com/", "https://combiner.example.com"),
41
+ ("combiner.example.com:9741", "http://combiner.example.com:9741"),
42
+ ("combiner.example.com", "http://combiner.example.com:9741"),
43
+ ("http://[fd7a::1]", "http://[fd7a::1]:9741"),
44
+ ("http://[fd7a::1]:80", "http://[fd7a::1]:80"),
45
+ ("", None),
46
+ (None, None),
47
+ ],
48
+ )
49
+ def test_setting_forms(setting: str | None, resolved: str | None) -> None:
50
+ assert resolve_public_url(setting) == resolved
51
+
52
+
53
+ def test_the_env_var_is_a_literal_url_and_wins(monkeypatch: pytest.MonkeyPatch) -> None:
54
+ monkeypatch.setenv(PUBLIC_URL_ENV, "https://auth.example.com/")
55
+ assert resolve_public_url("auto") == "https://auth.example.com"
56
+ assert OAuthConfig.from_dict({}).public_url == "https://auth.example.com"
57
+ monkeypatch.setenv(PUBLIC_URL_ENV, "https://{auto}") # not special in the env
58
+ assert resolve_public_url(None) == "https://{auto}"
59
+ # A bare host (as easily typed into a shell profile) is completed.
60
+ monkeypatch.setenv(PUBLIC_URL_ENV, "box.example.ts.net")
61
+ assert resolve_public_url(None) == "http://box.example.ts.net:9741"
62
+
63
+
64
+ def test_auto_without_a_tailnet_means_loopback_links(monkeypatch: pytest.MonkeyPatch) -> None:
65
+ monkeypatch.setattr("mcp_combiner.ui_host.advertise._tailscale_dns_name", lambda: None)
66
+ monkeypatch.setattr("mcp_combiner.ui_host.advertise._tailscale_ip", lambda: None)
67
+ monkeypatch.setattr("mcp_combiner.ui_host.advertise._interface_scan_ip", lambda: None)
68
+ assert resolve_public_url("auto") is None
69
+ config = OAuthConfig.from_dict({"public_url": "auto"})
70
+ assert config.public_url is None and config.prompt is None
71
+
72
+
73
+ def test_the_config_stores_the_resolved_url() -> None:
74
+ assert OAuthConfig.from_dict({"public_url": "auto"}).public_url == f"http://{NAME}:9741"
75
+
76
+
77
+ # ── {oauth_redirect} in server entries ─────────────────────────────
78
+
79
+
80
+ def _load(tmp_path: Path, doc: dict[str, object]) -> CombinerConfig:
81
+ path = tmp_path / "servers.json"
82
+ path.write_text(json.dumps(doc))
83
+ return CombinerConfig.load(str(path))
84
+
85
+
86
+ def test_oauth_redirect_expands_per_server(tmp_path: Path) -> None:
87
+ config = _load(
88
+ tmp_path,
89
+ {
90
+ "oauth": {"public_url": "auto"},
91
+ "servers": {
92
+ "gws": {
93
+ "command": "gws-mcp",
94
+ "env": {"REDIRECT_URI": "{oauth_redirect}"},
95
+ "args": ["--redirect", "{oauth_redirect}"],
96
+ },
97
+ "other": {"url": "http://127.0.0.1:1/mcp?cb={oauth_redirect}"},
98
+ },
99
+ },
100
+ )
101
+ gws = f"http://{NAME}:9741/oauth/callback/gws"
102
+ assert config.servers["gws"].env == {"REDIRECT_URI": gws}
103
+ assert config.servers["gws"].args == ["--redirect", gws]
104
+ assert config.servers["other"].url == (
105
+ f"http://127.0.0.1:1/mcp?cb=http://{NAME}:9741/oauth/callback/other"
106
+ )
107
+
108
+
109
+ def test_oauth_redirect_in_a_backing_entry_names_its_one_user(tmp_path: Path) -> None:
110
+ config = _load(
111
+ tmp_path,
112
+ {
113
+ "oauth": {"public_url": "https://auth.example.com"},
114
+ "sharedServers": {
115
+ "gws-proc": {"command": "gws", "env": {"CB": "{oauth_redirect}"}},
116
+ "shared-twice": {"command": "x", "env": {"CB": "{oauth_redirect}"}},
117
+ },
118
+ "servers": {
119
+ "gws": {"url": "http://127.0.0.1:1/mcp", "sharedServer": "gws-proc"},
120
+ "a": {"url": "http://127.0.0.1:2/mcp", "sharedServer": "shared-twice"},
121
+ "b": {"url": "http://127.0.0.1:3/mcp", "sharedServer": "shared-twice"},
122
+ },
123
+ },
124
+ )
125
+ assert config.shared_servers["gws-proc"].env == {
126
+ "CB": "https://auth.example.com/oauth/callback/gws"
127
+ }
128
+ assert config.shared_servers["shared-twice"].env == {"CB": "{oauth_redirect}"}
129
+
130
+
131
+ def test_oauth_redirect_needs_a_public_url(
132
+ tmp_path: Path, caplog: pytest.LogCaptureFixture
133
+ ) -> None:
134
+ with caplog.at_level(logging.WARNING, logger="mcp-combiner"):
135
+ config = _load(tmp_path, {"servers": {"s": {"command": "x", "args": ["{oauth_redirect}"]}}})
136
+ assert config.servers["s"].args == ["{oauth_redirect}"]
137
+ assert "needs oauth.public_url" in caplog.text
138
+
139
+
140
+ def test_the_env_url_applies_without_an_oauth_block(
141
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
142
+ ) -> None:
143
+ monkeypatch.setenv(PUBLIC_URL_ENV, "https://auth.example.com")
144
+ config = _load(tmp_path, {"servers": {"s": {"command": "x", "args": ["{oauth_redirect}"]}}})
145
+ assert config.oauth.public_url == "https://auth.example.com"
146
+ assert config.servers["s"].args == ["https://auth.example.com/oauth/callback/s"]
@@ -712,7 +712,7 @@ wheels = [
712
712
 
713
713
  [[package]]
714
714
  name = "mcp-combiner"
715
- version = "0.20.0-dev.3"
715
+ version = "0.20.0-dev.5"
716
716
  source = { editable = "." }
717
717
  dependencies = [
718
718
  { name = "fastmcp" },
@@ -1,59 +0,0 @@
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"