mcp-combiner 0.20.0.dev4__tar.gz → 0.21.0.dev1__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.
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/CHANGELOG.md +32 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/PKG-INFO +1 -1
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/auth.py +3 -5
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/config.py +106 -4
- mcp_combiner-0.21.0.dev1/mcp_combiner/listpaging.py +115 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/mounts.py +27 -6
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/server.py +5 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/pyproject.toml +1 -1
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/conftest.py +17 -1
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_authprompt.py +2 -2
- mcp_combiner-0.21.0.dev1/tests/test_listpaging.py +108 -0
- mcp_combiner-0.21.0.dev1/tests/test_public_url.py +146 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/uv.lock +1 -1
- mcp_combiner-0.20.0.dev4/tests/test_public_url.py +0 -65
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/.gitignore +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/.python-version +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/LICENSE +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/README.md +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/__init__.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/__main__.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/asgi.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/authprompt.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/backing.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/binding.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/connections.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/ctl.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/era.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/externalservers.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/fastvalidate.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/handover.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/heldcalls.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/inbound_auth.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/isolated.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/listen.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/meta_tools.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/middleware.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/mockserver.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/notifications.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/nvim_channel.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/nvim_proxy.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/permissions.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/proxyfactory.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/py.typed +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/resume_transport.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/routes.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/runtime.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/schema.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/schemafix.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/sharedserver.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/status.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/toolcache.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/ui_host/__init__.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/ui_host/advertise.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/ui_host/holder.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/ui_host/routes.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/ui_host/sessions.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/ui_host/static/app-bridge.bundle.js +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/ui_host/templates.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/upstream_era.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/upstream_listen.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/mcp_combiner/upstream_session.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/pyrightconfig.json +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/fakes.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/fixtures/servers.json +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_advertised_origin.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_app_meta.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_auth.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_binding.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_combiner_reconnect.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_config.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_connections.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_ctl_lifecycle.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_elicit_e2e.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_era.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_externalservers.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_handover.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_inbound_auth.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_isolated.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_isolated_lifecycle_e2e.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_isolated_stdio.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_live_claude.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_mockserver.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_mounts.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_notifications.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_notifications_e2e.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_nvim_channel.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_nvim_e2e.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_oauth_mock.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_permissions.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_reload_config.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_resume_transport.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_route_matrix.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_schema_fixes.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_session_filter.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_session_independence.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_sharedserver.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_tool_fetch_wedge.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_ui_host.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_upstream_restart.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_upstream_session.py +0 -0
- {mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_visibility_and_reset_e2e.py +0 -0
|
@@ -8,6 +8,31 @@ tagged `vX.Y.Z`.
|
|
|
8
8
|
|
|
9
9
|
### Added
|
|
10
10
|
|
|
11
|
+
- **List paging.** `tools/list`, `resources/list`, `resources/templates/list`
|
|
12
|
+
and `prompts/list` are paged at `MCP_COMBINER_LIST_PAGE_SIZE` items (default
|
|
13
|
+
1000; `0` = off). A server listing thousands of resources (13k from two
|
|
14
|
+
metrics servers in one setup) made a single ~17 MB response, past pi's 16 MiB
|
|
15
|
+
SSE event limit, so interactive-resource discovery failed. The later pages of
|
|
16
|
+
a `resources/list` walk are served from the first page's listing (one
|
|
17
|
+
upstream fan-out per walk, consistent pages). The Neovim plugin now follows
|
|
18
|
+
`nextCursor` for all list calls.
|
|
19
|
+
- **`resourceFilter`** (per server): glob patterns on resource URIs (and
|
|
20
|
+
template URI templates) as the server names them; only matching ones are
|
|
21
|
+
listed. `["ui://*"]` keeps only interactive widgets. Listing only — reading
|
|
22
|
+
a resource by URI still works.
|
|
23
|
+
|
|
24
|
+
## [0.20.0] — 2026-11-03
|
|
25
|
+
|
|
26
|
+
Both MCP revisions, upstream and down. Upgrade notes: upstreams default to
|
|
27
|
+
`protocol: auto`, so a server that offers the 2026-07-28 revision is connected
|
|
28
|
+
on it and owns its own sessions (no per-chat isolation) — set
|
|
29
|
+
`"protocol": "legacy"` for one that still keeps per-connection state (svg-mcp
|
|
30
|
+
< 0.10). The combiner still answers clients on the handshake unless
|
|
31
|
+
`MCP_COMBINER_OFFER_2026=1`. `bind.host` may now be a list; `auto` / `{auto}`
|
|
32
|
+
name this machine on its tailnet in bind, advertise and `oauth.public_url`.
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
|
|
11
36
|
- Era translation, part 2 (still behind `MCP_COMBINER_OFFER_2026=1`):
|
|
12
37
|
permission consent prompts work on the 2026-07-28 revision. A call that
|
|
13
38
|
needs consent returns an `InputRequiredResult` with the same question and
|
|
@@ -36,6 +61,13 @@ tagged `vX.Y.Z`.
|
|
|
36
61
|
host: `http://` and, on plain http, the combiner's port are added. A bare
|
|
37
62
|
host used to become a redirect URI with no scheme, which broke the OAuth
|
|
38
63
|
connection outright.
|
|
64
|
+
- **`{oauth_redirect}` in server entries** expands to that server's callback,
|
|
65
|
+
`<public_url>/oauth/callback/<server>`, in `args`, `env`, `headers` and `url`
|
|
66
|
+
(and in a `sharedServers` / `externalServers` entry used by exactly one
|
|
67
|
+
server), so a server can be told its redirect URI without a machine name in
|
|
68
|
+
the config. Left as-is, with a warning, when there's no public URL.
|
|
69
|
+
- `MCP_COMBINER_OAUTH_PUBLIC_URL` now applies when servers.json has no `oauth`
|
|
70
|
+
block (it was ignored then).
|
|
39
71
|
- Mock server `--issuer` (`auto` = the tailnet name): the authorization server
|
|
40
72
|
URL it advertises, so a phone can complete the mock's OAuth flow.
|
|
41
73
|
- An explicit advertised origin keeps its own port
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: mcp-combiner
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.21.0-dev.1
|
|
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,
|
|
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]
|
|
@@ -422,6 +422,14 @@ class ServerConfig(BaseModel):
|
|
|
422
422
|
Examples: ``["gmail_*", "calendar_*"]`` to only include Gmail and Calendar tools.
|
|
423
423
|
"""
|
|
424
424
|
|
|
425
|
+
resource_filter: list[str] = Field(default_factory=list)
|
|
426
|
+
"""Glob patterns choosing which of this server's resources (and resource
|
|
427
|
+
templates) are listed. Empty (default) lists all. Patterns match the URI as
|
|
428
|
+
the server names it (templates: their URI template), e.g. ``["ui://*"]``
|
|
429
|
+
keeps only interactive widgets — for a server that lists thousands of
|
|
430
|
+
resources (one per metric) its tools already cover. Listing only: a
|
|
431
|
+
resource read by URI still works."""
|
|
432
|
+
|
|
425
433
|
permissions: PermissionPolicy | None = None
|
|
426
434
|
"""Per-call permission policy for this server (overrides/extends the global
|
|
427
435
|
``permissions`` block). ``None`` = inherit the global policy. See
|
|
@@ -494,6 +502,8 @@ class ServerConfig(BaseModel):
|
|
|
494
502
|
"external_server",
|
|
495
503
|
"toolFilter",
|
|
496
504
|
"tool_filter",
|
|
505
|
+
"resourceFilter",
|
|
506
|
+
"resource_filter",
|
|
497
507
|
"permissions",
|
|
498
508
|
"isolate",
|
|
499
509
|
"protocol",
|
|
@@ -518,6 +528,7 @@ class ServerConfig(BaseModel):
|
|
|
518
528
|
shared_server = data.get("sharedServer") or data.get("shared_server")
|
|
519
529
|
external_server = data.get("externalServer") or data.get("external_server")
|
|
520
530
|
tool_filter = data.get("toolFilter") or data.get("tool_filter") or []
|
|
531
|
+
resource_filter = data.get("resourceFilter") or data.get("resource_filter") or []
|
|
521
532
|
|
|
522
533
|
return cls(
|
|
523
534
|
name=name,
|
|
@@ -533,6 +544,7 @@ class ServerConfig(BaseModel):
|
|
|
533
544
|
shared_server=shared_server,
|
|
534
545
|
external_server=external_server,
|
|
535
546
|
tool_filter=tool_filter,
|
|
547
|
+
resource_filter=resource_filter,
|
|
536
548
|
permissions=PermissionPolicy.from_dict(data.get("permissions")),
|
|
537
549
|
isolate=(None if data.get("isolate") is None else bool(data["isolate"])),
|
|
538
550
|
protocol=_upstream_protocol(name, data.get("protocol")),
|
|
@@ -787,6 +799,89 @@ def resolve_public_url(setting: str | None) -> str | None:
|
|
|
787
799
|
return f"{scheme}://{authority.replace(AUTO_HOST, name)}{slash}{path}"
|
|
788
800
|
|
|
789
801
|
|
|
802
|
+
OAUTH_REDIRECT = "{oauth_redirect}"
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
def oauth_redirect_uri(public_url: str, server: str) -> str:
|
|
806
|
+
"""Where the combiner receives *server*'s OAuth redirect (the
|
|
807
|
+
``/oauth/callback/<server>`` route) under *public_url*."""
|
|
808
|
+
from urllib.parse import quote
|
|
809
|
+
|
|
810
|
+
return f"{public_url}/oauth/callback/{quote(server, safe='')}"
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
def _replace_in(value: Any, text: str) -> Any:
|
|
814
|
+
"""*value* with ``{oauth_redirect}`` replaced by *text* in every string."""
|
|
815
|
+
if isinstance(value, str):
|
|
816
|
+
return value.replace(OAUTH_REDIRECT, text)
|
|
817
|
+
if isinstance(value, list):
|
|
818
|
+
return [_replace_in(v, text) for v in value]
|
|
819
|
+
if isinstance(value, dict):
|
|
820
|
+
return {k: _replace_in(v, text) for k, v in value.items()}
|
|
821
|
+
return value
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
def _mentions(value: Any) -> bool:
|
|
825
|
+
if isinstance(value, str):
|
|
826
|
+
return OAUTH_REDIRECT in value
|
|
827
|
+
if isinstance(value, list):
|
|
828
|
+
return any(_mentions(v) for v in value)
|
|
829
|
+
if isinstance(value, dict):
|
|
830
|
+
return any(_mentions(v) for v in value.values())
|
|
831
|
+
return False
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
def expand_oauth_redirects(
|
|
835
|
+
servers: dict[str, Any],
|
|
836
|
+
shared: dict[str, Any],
|
|
837
|
+
external: dict[str, Any],
|
|
838
|
+
public_url: str | None,
|
|
839
|
+
) -> tuple[dict[str, Any], dict[str, Any], dict[str, Any]]:
|
|
840
|
+
"""Expand ``{oauth_redirect}`` in raw config entries: a server's own entry
|
|
841
|
+
gets its callback URL (:func:`oauth_redirect_uri`); a ``sharedServers`` /
|
|
842
|
+
``externalServers`` entry gets the callback of the one server that uses it.
|
|
843
|
+
For servers that must be told the combiner's redirect URI (an external
|
|
844
|
+
OAuth provider setup). Left as-is, with a warning, without a public URL or
|
|
845
|
+
when a backing entry serves several servers."""
|
|
846
|
+
if not any(_mentions(t) for t in (servers, shared, external)):
|
|
847
|
+
return servers, shared, external
|
|
848
|
+
if public_url is None:
|
|
849
|
+
logger.warning(
|
|
850
|
+
"{oauth_redirect} needs oauth.public_url (or %s): left unexpanded", PUBLIC_URL_ENV
|
|
851
|
+
)
|
|
852
|
+
return servers, shared, external
|
|
853
|
+
servers = {
|
|
854
|
+
name: _replace_in(entry, oauth_redirect_uri(public_url, name))
|
|
855
|
+
for name, entry in servers.items()
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
def backing(table: dict[str, Any], keys: tuple[str, ...]) -> dict[str, Any]:
|
|
859
|
+
out: dict[str, Any] = {}
|
|
860
|
+
for name, entry in table.items():
|
|
861
|
+
if not _mentions(entry):
|
|
862
|
+
out[name] = entry
|
|
863
|
+
continue
|
|
864
|
+
users = [
|
|
865
|
+
server
|
|
866
|
+
for server, srv in servers.items()
|
|
867
|
+
if isinstance(srv, dict) and any(srv.get(k) == name for k in keys)
|
|
868
|
+
]
|
|
869
|
+
if len(users) == 1:
|
|
870
|
+
out[name] = _replace_in(entry, oauth_redirect_uri(public_url, users[0]))
|
|
871
|
+
else:
|
|
872
|
+
logger.warning(
|
|
873
|
+
"{oauth_redirect} in '%s' is ambiguous: used by %s — left unexpanded",
|
|
874
|
+
name,
|
|
875
|
+
users or "no server",
|
|
876
|
+
)
|
|
877
|
+
out[name] = entry
|
|
878
|
+
return out
|
|
879
|
+
|
|
880
|
+
shared = backing(shared, ("sharedServer", "shared_server"))
|
|
881
|
+
external = backing(external, ("externalServer", "external_server"))
|
|
882
|
+
return servers, shared, external
|
|
883
|
+
|
|
884
|
+
|
|
790
885
|
class IsolationConfig(BaseModel):
|
|
791
886
|
"""Lifecycle knobs for token-keyed isolated upstream sessions.
|
|
792
887
|
|
|
@@ -901,17 +996,26 @@ class CombinerConfig(BaseModel):
|
|
|
901
996
|
except json.JSONDecodeError as exc:
|
|
902
997
|
raise ValueError(f"Config file {path} is not valid JSON: {exc}") from exc
|
|
903
998
|
|
|
999
|
+
# Resolved first: {oauth_redirect} in server entries names its result.
|
|
1000
|
+
# Always parsed, so $MCP_COMBINER_OAUTH_PUBLIC_URL applies without an
|
|
1001
|
+
# "oauth" block.
|
|
1002
|
+
raw_oauth: dict[str, Any] = raw.get("oauth", {})
|
|
1003
|
+
oauth = OAuthConfig.from_dict(raw_oauth)
|
|
1004
|
+
|
|
904
1005
|
raw_servers: dict[str, Any] = raw.get("servers", raw.get("mcpServers", {}))
|
|
1006
|
+
raw_shared: dict[str, Any] = raw.get("sharedServers", {})
|
|
1007
|
+
raw_external: dict[str, Any] = raw.get("externalServers", {})
|
|
1008
|
+
raw_servers, raw_shared, raw_external = expand_oauth_redirects(
|
|
1009
|
+
raw_servers, raw_shared, raw_external, oauth.public_url
|
|
1010
|
+
)
|
|
905
1011
|
servers = {
|
|
906
1012
|
name: ServerConfig.from_dict(name, srv_data) for name, srv_data in raw_servers.items()
|
|
907
1013
|
}
|
|
908
1014
|
|
|
909
|
-
raw_shared: dict[str, Any] = raw.get("sharedServers", {})
|
|
910
1015
|
shared_servers = {
|
|
911
1016
|
name: SharedServerConfig.from_dict(name, data) for name, data in raw_shared.items()
|
|
912
1017
|
}
|
|
913
1018
|
|
|
914
|
-
raw_external: dict[str, Any] = raw.get("externalServers", {})
|
|
915
1019
|
external_servers = {
|
|
916
1020
|
name: ExternalServerConfig.from_dict(name, data) for name, data in raw_external.items()
|
|
917
1021
|
}
|
|
@@ -941,8 +1045,6 @@ class CombinerConfig(BaseModel):
|
|
|
941
1045
|
field,
|
|
942
1046
|
)
|
|
943
1047
|
|
|
944
|
-
raw_oauth: dict[str, Any] = raw.get("oauth", {})
|
|
945
|
-
oauth = OAuthConfig.from_dict(raw_oauth) if raw_oauth else OAuthConfig()
|
|
946
1048
|
# Validates every server's prompt up front (a typo fails the load, not
|
|
947
1049
|
# the first re-auth) and flags elicitation that can't reach a remote device.
|
|
948
1050
|
for name, srv in servers.items():
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Paginated list responses (``tools/list``, ``resources/list``, …).
|
|
2
|
+
|
|
3
|
+
Some upstreams list thousands of resources (a metrics server exposing one per
|
|
4
|
+
metric). Unpaginated, the combiner's aggregate ``resources/list`` became one
|
|
5
|
+
JSON-RPC message — one SSE event — of tens of megabytes, past clients' event
|
|
6
|
+
limits (pi's is 16 MiB). So list responses are paginated: at most
|
|
7
|
+
:func:`list_page_size` items per page (``MCP_COMBINER_LIST_PAGE_SIZE``,
|
|
8
|
+
default 1000; ``0`` turns paging off), with a ``nextCursor`` the client follows.
|
|
9
|
+
|
|
10
|
+
fastmcp paginates by offset, re-running the full listing for every page. For
|
|
11
|
+
tools that is a cache hit; resources are fanned out to every upstream, so the
|
|
12
|
+
first page's full listing is kept per chat (:class:`ResourceListSnapshots`)
|
|
13
|
+
and the later pages of that walk are cut from it — consistent pages, one
|
|
14
|
+
upstream fan-out per walk.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import os
|
|
20
|
+
import time
|
|
21
|
+
from collections.abc import Sequence
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
import mcp.types as mt
|
|
25
|
+
from fastmcp.resources import Resource
|
|
26
|
+
from fastmcp.server.middleware import CallNext, Middleware, MiddlewareContext
|
|
27
|
+
|
|
28
|
+
PAGE_SIZE_ENV = "MCP_COMBINER_LIST_PAGE_SIZE"
|
|
29
|
+
DEFAULT_PAGE_SIZE = 1000
|
|
30
|
+
#: How long a walk's snapshot serves later pages (a client fetches them back to back).
|
|
31
|
+
SNAPSHOT_TTL_S = 120.0
|
|
32
|
+
_MAX_SNAPSHOTS = 256
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def list_page_size() -> int | None:
|
|
36
|
+
"""Items per list page, or ``None`` for no paging."""
|
|
37
|
+
raw = os.environ.get(PAGE_SIZE_ENV, "").strip()
|
|
38
|
+
if not raw:
|
|
39
|
+
return DEFAULT_PAGE_SIZE
|
|
40
|
+
try:
|
|
41
|
+
size = int(raw)
|
|
42
|
+
except ValueError:
|
|
43
|
+
return DEFAULT_PAGE_SIZE
|
|
44
|
+
return size if size > 0 else None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ResourceListSnapshots:
|
|
48
|
+
"""The full resource listing of each chat's current list walk."""
|
|
49
|
+
|
|
50
|
+
def __init__(self) -> None:
|
|
51
|
+
self._walks: dict[str, tuple[float, Sequence[Resource]]] = {}
|
|
52
|
+
|
|
53
|
+
def keep(self, key: str, resources: Sequence[Resource]) -> None:
|
|
54
|
+
now = time.monotonic()
|
|
55
|
+
self._walks = {k: v for k, v in self._walks.items() if now - v[0] < SNAPSHOT_TTL_S}
|
|
56
|
+
if len(self._walks) >= _MAX_SNAPSHOTS:
|
|
57
|
+
del self._walks[min(self._walks, key=lambda k: self._walks[k][0])]
|
|
58
|
+
self._walks[key] = (now, resources)
|
|
59
|
+
|
|
60
|
+
def get(self, key: str) -> Sequence[Resource] | None:
|
|
61
|
+
entry = self._walks.get(key)
|
|
62
|
+
if entry is None or time.monotonic() - entry[0] >= SNAPSHOT_TTL_S:
|
|
63
|
+
return None
|
|
64
|
+
return entry[1]
|
|
65
|
+
|
|
66
|
+
def reset(self) -> None:
|
|
67
|
+
self._walks.clear()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
SNAPSHOTS = ResourceListSnapshots()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class ResourceListPagingMiddleware(Middleware):
|
|
74
|
+
"""Serve the later pages of a ``resources/list`` walk from its first page's listing."""
|
|
75
|
+
|
|
76
|
+
async def on_list_resources(
|
|
77
|
+
self,
|
|
78
|
+
context: MiddlewareContext[mt.ListResourcesRequest],
|
|
79
|
+
call_next: CallNext[mt.ListResourcesRequest, Sequence[Resource]],
|
|
80
|
+
) -> Sequence[Resource]:
|
|
81
|
+
page_size = list_page_size()
|
|
82
|
+
key = _walk_key(context)
|
|
83
|
+
if page_size is None or key is None:
|
|
84
|
+
return await call_next(context)
|
|
85
|
+
if _cursor(context) is not None:
|
|
86
|
+
snapshot = SNAPSHOTS.get(key)
|
|
87
|
+
if snapshot is not None:
|
|
88
|
+
return snapshot
|
|
89
|
+
resources = await call_next(context)
|
|
90
|
+
if len(resources) > page_size:
|
|
91
|
+
SNAPSHOTS.keep(key, resources)
|
|
92
|
+
return resources
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _walk_key(context: MiddlewareContext[Any]) -> str | None:
|
|
96
|
+
"""The chat whose walk this is: its token, else its connection."""
|
|
97
|
+
from mcp_combiner.middleware import _chat_token
|
|
98
|
+
from mcp_combiner.runtime import downstream_connection
|
|
99
|
+
|
|
100
|
+
token = _chat_token()
|
|
101
|
+
if token:
|
|
102
|
+
return f"token:{token}"
|
|
103
|
+
fctx = context.fastmcp_context
|
|
104
|
+
rc = fctx.request_context if fctx is not None else None
|
|
105
|
+
connection = downstream_connection(rc.session) if rc is not None else None
|
|
106
|
+
return f"conn:{id(connection)}" if connection is not None else None
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _cursor(context: MiddlewareContext[Any]) -> str | None:
|
|
110
|
+
"""The request's pagination cursor (fastmcp's list middleware sees no params)."""
|
|
111
|
+
fctx = context.fastmcp_context
|
|
112
|
+
rc = fctx.request_context if fctx is not None else None
|
|
113
|
+
params = rc._srctx.params if rc is not None else None
|
|
114
|
+
cursor = params.get("cursor") if isinstance(params, dict) else None
|
|
115
|
+
return cursor if isinstance(cursor, str) and cursor else None
|
|
@@ -51,7 +51,9 @@ class BoundedListProvider(Provider):
|
|
|
51
51
|
fires for them and call routing would silently break ("Unknown tool").
|
|
52
52
|
"""
|
|
53
53
|
|
|
54
|
-
def __init__(
|
|
54
|
+
def __init__(
|
|
55
|
+
self, inner: Any, timeout: float | None = None, server_name: str | None = None
|
|
56
|
+
) -> None:
|
|
55
57
|
super().__init__()
|
|
56
58
|
if timeout is None:
|
|
57
59
|
from mcp_combiner.toolcache import UPSTREAM_TOOL_LIST_TIMEOUT
|
|
@@ -59,6 +61,7 @@ class BoundedListProvider(Provider):
|
|
|
59
61
|
timeout = UPSTREAM_TOOL_LIST_TIMEOUT
|
|
60
62
|
self._inner = inner
|
|
61
63
|
self._timeout = timeout
|
|
64
|
+
self._server_name = server_name
|
|
62
65
|
|
|
63
66
|
def __getattr__(self, name: str) -> Any:
|
|
64
67
|
# Only reached for names not found locally or on Provider — delegate
|
|
@@ -114,10 +117,10 @@ class BoundedListProvider(Provider):
|
|
|
114
117
|
return await self._bounded("get_app_tool", app_name, tool_name)
|
|
115
118
|
|
|
116
119
|
async def list_resources(self) -> Any:
|
|
117
|
-
return await self._bounded("list_resources") or []
|
|
120
|
+
return self._filtered(await self._bounded("list_resources") or [], "uri")
|
|
118
121
|
|
|
119
122
|
async def _list_resources(self) -> Any:
|
|
120
|
-
return await self._bounded("list_resources") or []
|
|
123
|
+
return self._filtered(await self._bounded("list_resources") or [], "uri")
|
|
121
124
|
|
|
122
125
|
async def get_resource(self, uri: str, version: Any = None) -> Any:
|
|
123
126
|
return await self._bounded("get_resource", uri, version)
|
|
@@ -126,10 +129,28 @@ class BoundedListProvider(Provider):
|
|
|
126
129
|
return await self._bounded("get_resource", uri, version)
|
|
127
130
|
|
|
128
131
|
async def list_resource_templates(self) -> Any:
|
|
129
|
-
return await self._bounded("list_resource_templates") or []
|
|
132
|
+
return self._filtered(await self._bounded("list_resource_templates") or [], "uri_template")
|
|
130
133
|
|
|
131
134
|
async def _list_resource_templates(self) -> Any:
|
|
132
|
-
return await self._bounded("list_resource_templates") or []
|
|
135
|
+
return self._filtered(await self._bounded("list_resource_templates") or [], "uri_template")
|
|
136
|
+
|
|
137
|
+
def _filtered(self, items: Any, attr: str) -> Any:
|
|
138
|
+
"""*items* narrowed by the server's ``resourceFilter`` (read per listing,
|
|
139
|
+
so a config reload applies without a remount)."""
|
|
140
|
+
from mcp_combiner.runtime import RUNTIME
|
|
141
|
+
|
|
142
|
+
config = RUNTIME.config
|
|
143
|
+
srv = config.servers.get(self._server_name) if config and self._server_name else None
|
|
144
|
+
if srv is None or not srv.resource_filter:
|
|
145
|
+
return items
|
|
146
|
+
import fnmatch
|
|
147
|
+
|
|
148
|
+
patterns = srv.resource_filter
|
|
149
|
+
return [
|
|
150
|
+
item
|
|
151
|
+
for item in items
|
|
152
|
+
if any(fnmatch.fnmatchcase(str(getattr(item, attr, "")), p) for p in patterns)
|
|
153
|
+
]
|
|
133
154
|
|
|
134
155
|
async def get_resource_template(self, uri: str, version: Any = None) -> Any:
|
|
135
156
|
return await self._bounded("get_resource_template", uri, version)
|
|
@@ -208,7 +229,7 @@ def mount_server_provider(combiner: FastMCP, proxy: Any, server_name: str) -> No
|
|
|
208
229
|
|
|
209
230
|
raw = FastMCPProvider(proxy) if isinstance(proxy, FastMCP) else proxy
|
|
210
231
|
before = list(combiner.providers)
|
|
211
|
-
combiner.add_provider(BoundedListProvider(raw), namespace=server_name)
|
|
232
|
+
combiner.add_provider(BoundedListProvider(raw, server_name=server_name), namespace=server_name)
|
|
212
233
|
added = [p for p in combiner.providers if not any(p is q for q in before)]
|
|
213
234
|
if not added:
|
|
214
235
|
logger.warning(
|
|
@@ -20,6 +20,7 @@ from mcp_combiner.config import (
|
|
|
20
20
|
CombinerConfig, # noqa: PLC2701
|
|
21
21
|
)
|
|
22
22
|
from mcp_combiner.connections import ConnectionManager
|
|
23
|
+
from mcp_combiner.listpaging import ResourceListPagingMiddleware, list_page_size
|
|
23
24
|
from mcp_combiner.middleware import ( # noqa: F401 (ToolProcessingMiddleware re-export)
|
|
24
25
|
ToolErrorPassthroughMiddleware,
|
|
25
26
|
ToolProcessingMiddleware,
|
|
@@ -445,6 +446,8 @@ def create_combiner(
|
|
|
445
446
|
"server's tools online."
|
|
446
447
|
),
|
|
447
448
|
dereference_schemas=False, # Disabled: circular $ref causes infinite recursion
|
|
449
|
+
# Large aggregate lists are paged (mcp_combiner.listpaging).
|
|
450
|
+
list_page_size=list_page_size(),
|
|
448
451
|
middleware=[
|
|
449
452
|
# Outermost: catch-all safety net for any unhandled exception
|
|
450
453
|
# (tool-visible errors pass through as isError results).
|
|
@@ -458,6 +461,8 @@ def create_combiner(
|
|
|
458
461
|
retry_exceptions=(ConnectionError, TimeoutError),
|
|
459
462
|
logger=logger,
|
|
460
463
|
),
|
|
464
|
+
# Later pages of a resources/list walk come from its first page's listing.
|
|
465
|
+
ResourceListPagingMiddleware(),
|
|
461
466
|
# Innermost: caching, filtering, sanitization, domain error handling
|
|
462
467
|
ToolProcessingMiddleware(),
|
|
463
468
|
],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "mcp-combiner"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.21.0-dev.1"
|
|
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"
|
|
@@ -72,6 +72,22 @@ def free_port() -> int:
|
|
|
72
72
|
return port
|
|
73
73
|
|
|
74
74
|
|
|
75
|
+
def free_port_pair() -> int:
|
|
76
|
+
"""A free port whose successor is free too: a combiner also serves its UI
|
|
77
|
+
relay on port + 1, which tests reach directly."""
|
|
78
|
+
for _ in range(50):
|
|
79
|
+
port = free_port()
|
|
80
|
+
probe = socket.socket()
|
|
81
|
+
try:
|
|
82
|
+
probe.bind(("127.0.0.1", port + 1))
|
|
83
|
+
except OSError:
|
|
84
|
+
continue
|
|
85
|
+
finally:
|
|
86
|
+
probe.close()
|
|
87
|
+
return port
|
|
88
|
+
raise RuntimeError("no free port pair found")
|
|
89
|
+
|
|
90
|
+
|
|
75
91
|
def mockserver_argv(
|
|
76
92
|
name: str,
|
|
77
93
|
transport: str,
|
|
@@ -325,7 +341,7 @@ class ProcFactory:
|
|
|
325
341
|
env: dict[str, str] | None = None,
|
|
326
342
|
wait: bool = True,
|
|
327
343
|
) -> CombinerHandle:
|
|
328
|
-
port = port or
|
|
344
|
+
port = port or free_port_pair()
|
|
329
345
|
argv = [
|
|
330
346
|
sys.executable,
|
|
331
347
|
"-m",
|
|
@@ -27,7 +27,7 @@ from conftest import (
|
|
|
27
27
|
OAuthMockFactory,
|
|
28
28
|
ProcFactory,
|
|
29
29
|
ServedOAuthMock,
|
|
30
|
-
|
|
30
|
+
free_port_pair,
|
|
31
31
|
poll_until,
|
|
32
32
|
write_servers_config,
|
|
33
33
|
)
|
|
@@ -399,7 +399,7 @@ class TestCombinerPublicUrlFlow:
|
|
|
399
399
|
env: dict[str, str] | None = None,
|
|
400
400
|
protocol: str | None = None,
|
|
401
401
|
) -> str:
|
|
402
|
-
port =
|
|
402
|
+
port = free_port_pair()
|
|
403
403
|
entry: dict[str, Any] = {"url": mock.mcp_url, "transport": "http", "auth": "oauth"}
|
|
404
404
|
if protocol is not None:
|
|
405
405
|
entry["protocol"] = protocol
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Paginated list responses (mcp_combiner.listpaging)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
from conftest import ProcFactory, http_mock_entry, write_servers_config
|
|
9
|
+
from fastmcp import Client
|
|
10
|
+
from fastmcp.resources import Resource
|
|
11
|
+
|
|
12
|
+
from mcp_combiner import listpaging
|
|
13
|
+
from mcp_combiner.listpaging import PAGE_SIZE_ENV, ResourceListSnapshots, list_page_size
|
|
14
|
+
from mcp_combiner.runtime import CLIENT_CONNECT_MODE
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TestPageSize:
|
|
18
|
+
def test_default_and_overrides(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
19
|
+
monkeypatch.delenv(PAGE_SIZE_ENV, raising=False)
|
|
20
|
+
assert list_page_size() == listpaging.DEFAULT_PAGE_SIZE
|
|
21
|
+
monkeypatch.setenv(PAGE_SIZE_ENV, "50")
|
|
22
|
+
assert list_page_size() == 50
|
|
23
|
+
monkeypatch.setenv(PAGE_SIZE_ENV, "0")
|
|
24
|
+
assert list_page_size() is None
|
|
25
|
+
monkeypatch.setenv(PAGE_SIZE_ENV, "lots")
|
|
26
|
+
assert list_page_size() == listpaging.DEFAULT_PAGE_SIZE
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class TestSnapshots:
|
|
30
|
+
def _resources(self, n: int) -> list[Resource]:
|
|
31
|
+
return [
|
|
32
|
+
Resource.from_function(lambda: "x", uri=f"mem://r/{i}", name=f"r{i}") for i in range(n)
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
def test_keeps_per_walk_and_expires(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
36
|
+
snaps = ResourceListSnapshots()
|
|
37
|
+
clock = [1000.0]
|
|
38
|
+
monkeypatch.setattr("mcp_combiner.listpaging.time.monotonic", lambda: clock[0])
|
|
39
|
+
a, b = self._resources(2), self._resources(3)
|
|
40
|
+
snaps.keep("token:a", a)
|
|
41
|
+
snaps.keep("token:b", b)
|
|
42
|
+
assert snaps.get("token:a") is a and snaps.get("token:b") is b
|
|
43
|
+
clock[0] += listpaging.SNAPSHOT_TTL_S
|
|
44
|
+
assert snaps.get("token:a") is None
|
|
45
|
+
|
|
46
|
+
def test_bounded(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
47
|
+
snaps = ResourceListSnapshots()
|
|
48
|
+
clock = [0.0]
|
|
49
|
+
monkeypatch.setattr("mcp_combiner.listpaging.time.monotonic", lambda: clock[0])
|
|
50
|
+
for i in range(listpaging._MAX_SNAPSHOTS + 5):
|
|
51
|
+
clock[0] += 0.01
|
|
52
|
+
snaps.keep(f"token:{i}", [])
|
|
53
|
+
assert snaps.get("token:0") is None
|
|
54
|
+
assert snaps.get(f"token:{listpaging._MAX_SNAPSHOTS + 4}") == []
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@pytest.mark.e2e
|
|
58
|
+
async def test_lists_page_and_clients_get_everything(procs: ProcFactory, tmp_path: Path) -> None:
|
|
59
|
+
mock = await procs.start_http_mock("mockup")
|
|
60
|
+
config = write_servers_config(tmp_path / "servers.json", {"mockup": http_mock_entry(mock.port)})
|
|
61
|
+
combiner = await procs.start_combiner(config, env={PAGE_SIZE_ENV: "1"})
|
|
62
|
+
await combiner.wait_server_state("mockup", ("ready",))
|
|
63
|
+
url = f"{combiner.mcp_url}/paging-0001"
|
|
64
|
+
async with Client(url, mode=CLIENT_CONNECT_MODE) as c:
|
|
65
|
+
everything = {str(r.uri) for r in await c.list_resources()}
|
|
66
|
+
assert len(everything) >= 2, everything
|
|
67
|
+
|
|
68
|
+
# Walk it by hand: one resource per page, every one once, then no cursor.
|
|
69
|
+
seen: list[str] = []
|
|
70
|
+
page = await c.list_resources_mcp()
|
|
71
|
+
while True:
|
|
72
|
+
assert len(page.resources) == 1
|
|
73
|
+
seen.extend(str(r.uri) for r in page.resources)
|
|
74
|
+
if page.next_cursor is None:
|
|
75
|
+
break
|
|
76
|
+
page = await c.list_resources_mcp(cursor=page.next_cursor)
|
|
77
|
+
assert sorted(seen) == sorted(everything)
|
|
78
|
+
|
|
79
|
+
# Tools page too, and the auto-paginating client still sees them all.
|
|
80
|
+
first = await c.list_tools_mcp()
|
|
81
|
+
assert len(first.tools) == 1 and first.next_cursor is not None
|
|
82
|
+
assert len(await c.list_tools()) > 1
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@pytest.mark.e2e
|
|
86
|
+
async def test_resource_filter_narrows_a_servers_listing(
|
|
87
|
+
procs: ProcFactory, tmp_path: Path
|
|
88
|
+
) -> None:
|
|
89
|
+
mock = await procs.start_http_mock("mockup")
|
|
90
|
+
unfiltered = write_servers_config(
|
|
91
|
+
tmp_path / "plain.json", {"mockup": http_mock_entry(mock.port)}
|
|
92
|
+
)
|
|
93
|
+
plain = await procs.start_combiner(unfiltered)
|
|
94
|
+
await plain.wait_server_state("mockup", ("ready",))
|
|
95
|
+
async with Client(f"{plain.mcp_url}/rfilter-0000", mode=CLIENT_CONNECT_MODE) as c:
|
|
96
|
+
assert "data://mockup/mock/readme" in [str(r.uri) for r in await c.list_resources()]
|
|
97
|
+
|
|
98
|
+
entry = {**http_mock_entry(mock.port), "resourceFilter": ["ui://*"]}
|
|
99
|
+
config = write_servers_config(tmp_path / "servers.json", {"mockup": entry})
|
|
100
|
+
combiner = await procs.start_combiner(config)
|
|
101
|
+
await combiner.wait_server_state("mockup", ("ready",))
|
|
102
|
+
async with Client(f"{combiner.mcp_url}/rfilter-0001", mode=CLIENT_CONNECT_MODE) as c:
|
|
103
|
+
uris = [str(r.uri) for r in await c.list_resources()]
|
|
104
|
+
assert uris and all(u.startswith("ui://") for u in uris), uris
|
|
105
|
+
hidden = "data://mockup/mock/readme"
|
|
106
|
+
# Listing only: a filtered-out resource can still be read by URI.
|
|
107
|
+
assert hidden not in uris
|
|
108
|
+
assert (await c.read_resource(hidden))[0] is not None
|
|
@@ -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"]
|
|
@@ -1,65 +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
|
-
("combiner.example.com", "http://combiner.example.com:9741"),
|
|
34
|
-
("http://[fd7a::1]", "http://[fd7a::1]:9741"),
|
|
35
|
-
("http://[fd7a::1]:80", "http://[fd7a::1]:80"),
|
|
36
|
-
("", None),
|
|
37
|
-
(None, None),
|
|
38
|
-
],
|
|
39
|
-
)
|
|
40
|
-
def test_setting_forms(setting: str | None, resolved: str | None) -> None:
|
|
41
|
-
assert resolve_public_url(setting) == resolved
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def test_the_env_var_is_a_literal_url_and_wins(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
45
|
-
monkeypatch.setenv(PUBLIC_URL_ENV, "https://auth.example.com/")
|
|
46
|
-
assert resolve_public_url("auto") == "https://auth.example.com"
|
|
47
|
-
assert OAuthConfig.from_dict({}).public_url == "https://auth.example.com"
|
|
48
|
-
monkeypatch.setenv(PUBLIC_URL_ENV, "https://{auto}") # not special in the env
|
|
49
|
-
assert resolve_public_url(None) == "https://{auto}"
|
|
50
|
-
# A bare host (as easily typed into a shell profile) is completed.
|
|
51
|
-
monkeypatch.setenv(PUBLIC_URL_ENV, "box.example.ts.net")
|
|
52
|
-
assert resolve_public_url(None) == "http://box.example.ts.net:9741"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def test_auto_without_a_tailnet_means_loopback_links(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
56
|
-
monkeypatch.setattr("mcp_combiner.ui_host.advertise._tailscale_dns_name", lambda: None)
|
|
57
|
-
monkeypatch.setattr("mcp_combiner.ui_host.advertise._tailscale_ip", lambda: None)
|
|
58
|
-
monkeypatch.setattr("mcp_combiner.ui_host.advertise._interface_scan_ip", lambda: None)
|
|
59
|
-
assert resolve_public_url("auto") is None
|
|
60
|
-
config = OAuthConfig.from_dict({"public_url": "auto"})
|
|
61
|
-
assert config.public_url is None and config.prompt is None
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def test_the_config_stores_the_resolved_url() -> None:
|
|
65
|
-
assert OAuthConfig.from_dict({"public_url": "auto"}).public_url == f"http://{NAME}:9741"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mcp_combiner-0.20.0.dev4 → mcp_combiner-0.21.0.dev1}/tests/test_visibility_and_reset_e2e.py
RENAMED
|
File without changes
|