Skip to content

Split servers (path routing) from server (deployment target) on openapi/asyncapi client/server kinds #2069

Description

@jfallows

Blocked by / depends on #2067 — land that first. #2067 settles the spec/operation vocabulary and whether openapi/asyncapi client/server kinds gain real generation-time route filtering at all; this issue's selector mechanism builds directly on that decision.

Context

Follow-on design discussion from #2067. OpenapiView/OpenapiOperationView (and the asyncapi equivalents) currently cross-join every document-declared server (root/path/operation-level servers: in the OpenAPI/AsyncAPI doc) with every configured options.specs.<label>.servers[] override, and hand the same resulting list to two different consumers of OpenapiClientGenerator/AsyncapiClientGenerator:

  • injectHttpRequests iterates every entry to build one HTTP request path-matcher per server variant (legitimately multi-valued — different servers can imply different base paths, e.g. /v1 vs /v2).
  • injectTcpClient/injectTlsClient take .findFirst() over the same list to pick the actual TCP/TLS dial target (must be singular — a client only ever opens one connection).

For kind: server, this asymmetry is already handled correctly without anyone deciding it explicitly: injectTcpServer binds host="0.0.0.0" unconditionally (the doc's declared hostname is never authoritative for what a server binds to) while pulling every distinct port and path from every declared server (correctly multi-valued, since a server can and does listen on multiple ports/paths). kind: client has no equivalent discipline — it silently collapses to whichever server happens to be first in iteration order, without any explicit signal that a choice was made, and without any way to narrow which document servers/paths are even in scope.

Proposed model — two orthogonal concerns

  1. servers (plural) — path-routing/structural concern. Describes which base-path variants exist and are in scope for this binding. Stays document-driven and legitimately multi-valued. Gains a subset-selection capability: pick which of the document's declared servers are activated (e.g. "only /v1"), consulted once at config-generation time — the same idiom mcp-openapi's own when/with already use (its selectors are evaluated once by McpOpenapiCompositeGenerator to decide what to generate, not matched per-stream at runtime). Omitting the selector activates every document server, same as today's behavior — same "inclusive when omitted" convention as Align route when/with naming (api-id/operation-id → spec/operation) and add tag/glob bulk selection across openapi, openapi-asyncapi, asyncapi #2067.
  2. server (singular) — deployment concern, kind: client only. An explicit override that always wins as the actual dial target, decoupled entirely from how many path variants are structurally active, mirroring mcp-openapi's existing scalar server: field.

Scope decision (confirmed)

Client side is a unified single remote host. A given openapi/asyncapi kind: client binding instance always represents exactly one physical backend; multiple servers only ever produce multiple recognized path variants against that one host (e.g. one backend serving both /v1 and /v2), never multiple simultaneous dial targets. Dispatching to genuinely distinct hosts from one client binding instance is explicitly out of scope here — if that's ever needed, compose multiple single-host openapi/asyncapi client bindings behind an outer router/proxy rather than teaching one binding to be a multi-host client internally.

Proposed changes

  1. Add a singular server override to openapi/asyncapi kind: client options. When set, it is the dial target, full stop, regardless of what the document declares.
  2. Add subset selection over document-declared servers to openapi and asyncapi (both client and server kinds), so a binding can restrict itself to e.g. only the /v1 variant instead of always activating every declared server.
  3. Selector shape differs by protocol and needs its own decision per binding, not one shared shape: AsyncAPI 3.x's servers is a named map (production, staging) — natural to select by name (servers: [production]). OpenAPI's servers is a positional, anonymous array ({url, description, variables}, no name field) — nothing to select by name; the selector has to match by url/path instead (e.g. servers: [{ path: /v1 }]), or the config introduces a synthetic label. Decide and document each independently.
  4. kind: server keeps binding host="0.0.0.0" unconditionally (unaffected by this — host was already correctly non-authoritative there); port/path continue to be derived from whichever servers survive the subset filter.
  5. Decide whether kind: client should require exactly one distinct host across whatever servers survive the subset filter when server: is not explicitly set (fail fast / warn), rather than today's silent .findFirst().

Open questions

References

  • runtime/binding-openapi/.../internal/config/composite/{OpenapiClientGenerator,OpenapiServerGenerator}.java
  • runtime/binding-asyncapi/.../internal/config/composite/{AsyncapiClientGenerator,AsyncapiServerGenerator}.java
  • runtime/common-openapi/.../view/{OpenapiView,OpenapiOperationView,OpenapiServerView}.java (the servers × configs cross-join)
  • runtime/binding-mcp-openapi/.../config/McpOpenapiSpecificationConfig.java (server: scalar override — the reference pattern for point 1) and internal/config/composite/McpOpenapiCompositeGenerator.java (isBulk() / tag-glob selectors — the reference pattern for "when/with evaluated once at generation time, not per stream")
  • Align route when/with naming (api-id/operation-id → spec/operation) and add tag/glob bulk selection across openapi, openapi-asyncapi, asyncapi #2067 — must land first
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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions