Repository navigation
Description
Summary
Add an optional cache option to the mcp · proxy binding. When configured, the proxy hydrates a federated catalog at bring-up via a long-lived session downstream, serves agent list operations from the cached catalog, and continues to pass invocations (tools/call, resources/read, prompts/get) straight through to its exits as a regular proxy does. One configured mcp.proxy per Zilla deployment, optionally with cache enabled, replaces the original two-binding mcp.cache → mcp.proxy pipeline; every original topology has an exact equivalent.
Per-user identity handling at invocation time remains the responsibility of each mcp · client via token exchange.
Stream type
- Accepts:
mcp - Produces:
mcp
Pipeline position
agent → mcp server → mcp proxy (options.cache) → { mcp_client_github, mcp_client_slack, mcp_kafka_orders, ... }
Responsibilities by MCP method
| Method | Handled by cache | Passed to exits |
|---|---|---|
initialize |
responds from cached capabilities | — |
tools/list |
served from cache | — |
resources/list |
served from cache | — |
prompts/list |
served from cache | — |
tools/call |
— | passed through — proxy routes to exit; exit performs token exchange |
resources/read |
— | passed through — per-user auth at exit |
prompts/get |
— | passed through — per-user auth at exit |
notifications/tools/list_changed |
(deferred) | — |
Hydrate — federated catalog populated at bring-up
At binding-graph bring-up, the proxy with options.cache opens a long-lived hydrate session downstream using the configured cache.authorization (any oauth guard with a grant type without a user subject — client-credentials or jwt-bearer — or omitted entirely for an unauthenticated downstream). Hydrate drives a full federated enumeration:
- Cache issues
initialize, thentools/list/resources/list/prompts/listdownstream - The proxy's own routing fans out to every configured exit; each exit responds with its lifecycle and primitives
- Cache stores the aggregate catalog (proxy already applies toolkit prefixes)
The hydrate session stays alive to receive future change notifications and to keep the downstream connection warm. On bring-up of a fresh node, the cache reads the keys from the store and exits hydrate early if the entries are still fresh — avoiding redundant downstream traversal when another worker or replica has already populated.
Store — required, shared by logical equivalence
The cache.store reference picks one of the installed store implementations (memory, redis, hazelcast, etc.). store-memory is process-wide shared across all workers on the node; the others span nodes. The operator's store: choice is the sharing scope.
Invariant: a store referenced by one cache-enabled proxy binding may only be shared with other cache-enabled proxy bindings that are logically equivalent (same upstream catalog).
Keys (flat, no prefix — operator controls scope via store choice):
| Key | Purpose |
|---|---|
capabilities |
cached initialize response |
tools |
aggregate tools catalog |
resources |
aggregate resources catalog |
prompts |
aggregate prompts catalog |
capabilities.lock |
hydrate lease |
tools.lock |
refresh lease |
resources.lock |
refresh lease |
prompts.lock |
refresh lease |
Refresh — per-method TTL with lease coordination
cache.ttl.{tools,resources,prompts} configures the refresh interval per method type. When a worker's tick fires, it CAS-acquires the per-method <method>.lock lease via StoreHandler.putIfAbsent(key, workerId, leaseMillis, completion):
putIfAbsent("tools.lock", workerId, leaseMillis, existing -> {
if (existing == null) {
// won the lease — issue tools/list downstream, write result to store, delete lock
} else {
// another worker is refreshing this slice — skip this tick
}
})
The TTL on the lease guarantees forward progress even if the holder crashes — the lease auto-expires and the next tick races again. Same pattern applies at hydrate (against capabilities.lock) so only one worker performs the bring-up enumeration.
Notification-driven refresh (notifications/{tools,resources,prompts}/list_changed) is deferred until those notification flows are supported by the existing proxy/client kinds.
Configuration
stores:
catalog_store0:
type: memory # or redis / hazelcast
bindings:
mcp_proxy0:
type: mcp
kind: proxy
options:
cache:
store: catalog_store0
ttl:
tools: PT1H
resources: PT1H
prompts: PT1H
authorization: # optional
oauth_hydrate0:
credentials: "Bearer {credentials}"
routes:
- exit: mcp_client_github
when:
- toolkit: github
- exit: mcp_client_slack
when:
- toolkit: slackoptions.cache is entirely optional — mcp.proxy without it behaves exactly as before. cache.store is required when cache is present. cache.authorization is optional (unauthenticated hydrate is supported).
Session model
The cache maintains two session kinds with the configured exits:
- Hydrate session — opened at binding bring-up using
cache.authorization; long-lived; drives initial enumeration and remains open thereafter - Per-agent sessions — one per inbound agent stream; uses the agent's authz; serves cached list operations and passes through invocations
Agent-session termination does not affect the hydrate session, which lives for the binding's lifetime.
Acceptance criteria
mcp · proxywithoptions.cacheconfigured: pipelinemcp server → mcp proxy → mcp clientwith one or more exits functions end-to-end forinitialize,tools/list,tools/call, session termination- Hydrate populates the store at bring-up; agent
initializeresponds from cache with zero downstream round-trip - Federation: cache above a proxy with multiple exits produces a federated aggregate catalog with toolkit prefixes correctly applied
- Refresh: when a method-type TTL elapses, the cache re-issues that one list call downstream; entries for the other methods are untouched
- Lease: two workers reaching the refresh tick simultaneously coordinate via
putIfAbsent— only one issues the downstream call; the other skips - Store sharing: a
store-memoryreference shared across workers on the same node serves the hydrated catalog without each worker re-hydrating
Dependencies
binding-mcp: implement mcp · proxy binding(existing — cache option extends it; closed)binding-mcp: implement mcp · client binding(exit; closed)binding-mcp: implement mcp · server binding(upstream; closed)engine: add Store conceptandstore-memory(closed)
Activity
test(binding-mcp): split cache ITs by group and add Group B list scri…
test(binding-mcp): add downstream-error warmup scenario, drop Group D (…
test(binding-mcp): regroup cache ITs by MCP method kind (#1737)
test(binding-mcp): fold cache into mcp.proxy with options.cache (#1737)
test(binding-mcp): flatten cache scenario + method names (#1737)
[-]binding-mcp: implement mcp · cache binding[/-][+]binding-mcp: add cache option to mcp · proxy binding[/+]test(binding-mcp): add cache refresh scenarios + tests (#1737)
test(binding-mcp): add hydrating scenarios per list method (#1737)
test(binding-mcp): scaffold cache refresh contention test (#1737)
test(binding-mcp): proper contention scripts with multi-worker engine (…
feat(binding-mcp): add McpCacheConfig POJO + JSON adapter (#1737)
feat(binding-mcp): originate hydrate lifecycle session at bring-up (#…
feat(binding-mcp): hydrate per-method list enumeration (#1737)
feat(binding-mcp): persist hydrate response bodies to store (#1737)
feat(binding-mcp): serve list responses from cache (#1737)
refactor(binding-mcp): introduce McpListCache; hydrate kinds in paral…
feat(binding-mcp): mcp · proxy cache option (#1737) (#1774)