Skip to content

binding-mcp: add cache option to mcp · proxy binding #1737

Closed

Description

@jfallows

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:

  1. Cache issues initialize, then tools/list / resources/list / prompts/list downstream
  2. The proxy's own routing fans out to every configured exit; each exit responds with its lifecycle and primitives
  3. 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: slack

options.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 · proxy with options.cache configured: pipeline mcp server → mcp proxy → mcp client with one or more exits functions end-to-end for initialize, tools/list, tools/call, session termination
  • Hydrate populates the store at bring-up; agent initialize responds 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-memory reference 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 concept and store-memory (closed)

Activity

  1. self-assigned this
    on Apr 24, 2026
  2. added theissue type on Apr 24, 2026
  3. changed the title [-]binding-mcp: implement mcp · cache binding[/-] [+]binding-mcp: add cache option to mcp · proxy binding[/+] on May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions