Repository navigation
Description
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:
injectHttpRequestsiterates every entry to build one HTTP request path-matcher per server variant (legitimately multi-valued — different servers can imply different base paths, e.g./v1vs/v2).injectTcpClient/injectTlsClienttake.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
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 idiommcp-openapi's ownwhen/withalready use (its selectors are evaluated once byMcpOpenapiCompositeGeneratorto 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.server(singular) — deployment concern,kind: clientonly. An explicit override that always wins as the actual dial target, decoupled entirely from how many path variants are structurally active, mirroringmcp-openapi's existing scalarserver: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
- Add a singular
serveroverride toopenapi/asyncapikind: clientoptions. When set, it is the dial target, full stop, regardless of what the document declares. - Add subset selection over document-declared servers to
openapiandasyncapi(bothclientandserverkinds), so a binding can restrict itself to e.g. only the/v1variant instead of always activating every declared server. - Selector shape differs by protocol and needs its own decision per binding, not one shared shape: AsyncAPI 3.x's
serversis a named map (production,staging) — natural to select by name (servers: [production]). OpenAPI'sserversis a positional, anonymous array ({url, description, variables}, no name field) — nothing to select by name; the selector has to match byurl/path instead (e.g.servers: [{ path: /v1 }]), or the config introduces a synthetic label. Decide and document each independently. kind: serverkeeps bindinghost="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.- Decide whether
kind: clientshould require exactly one distinct host across whatever servers survive the subset filter whenserver:is not explicitly set (fail fast / warn), rather than today's silent.findFirst().
Open questions
- Where does the selector live structurally — nested under
options.specs.<label>, or does it needopenapi/asyncapiclient/server kinds to gain a realroutes[]for the first time (the same open question already sitting in Align route when/with naming (api-id/operation-id → spec/operation) and add tag/glob bulk selection across openapi, openapi-asyncapi, asyncapi #2067, from a second independent motivating direction)? - Exact selector property name per binding (see point 3 above).
- Should an unset
server:with multiple surviving hosts be a hard config error, a warning, or stay silently first-wins for backward compatibility?
References
runtime/binding-openapi/.../internal/config/composite/{OpenapiClientGenerator,OpenapiServerGenerator}.javaruntime/binding-asyncapi/.../internal/config/composite/{AsyncapiClientGenerator,AsyncapiServerGenerator}.javaruntime/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) andinternal/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
Activity
feat(binding-openapi): enable real per-operation routing for kind: se…