Skip to content

feat(binding-mcp-openapi): support operator-declared guarded routes - #2105

Merged
jfallows merged 1 commit into
developfrom
claude/github-issue-2103-3iur1e
Jul 10, 2026
Merged

jfallows merged 1 commit into
developfrom
claude/github-issue-2103-3iur1e

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

Allows guarded: directly on mcp_openapi's own routes[], independent of the bundled OpenAPI spec's own security/securitySchemes declarations. Previously guarded: was rejected by mcp_openapi's route schema (additionalProperties: false on the route item omitted it), so the only way a tool/resource route could end up guarded was by resolving the spec's security requirements against options.specs[label].security — which doesn't help when the underlying OpenAPI spec declares no security schemes at all.

When both an operator-declared guarded: and a spec-derived guard are present, they compose rather than one replacing the other:

  • Same guard referenced by both → roles are unioned into a single entry
  • Distinct guards → both entries are emitted on the generated mcp_http0 route, which the engine already ANDs together

Changes:

  • specs/binding-mcp-openapi.spec — schema patch now allows a guarded property on the route item, matching the engine's generic $defs/binding.routes.items.properties.guarded shape
  • runtime/binding-mcp-openapi — McpOpenapiRouteConfig now carries the route's guarded list; McpOpenapiCompositeGenerator merges it with the existing spec-derived guard resolution before emitting the generated mcp_http0 route's guarded:

Testing

  • Added 3 unit tests to McpOpenapiCompositeGeneratorTest covering: operator guard with no spec security, operator guard composing with a distinct spec-derived guard, and operator guard unioning roles into the same spec-derived guard
  • ./mvnw clean verify -pl specs/binding-mcp-openapi.spec,runtime/binding-mcp-openapi — all green (schema tests, unit tests, k3po ITs including the pre-existing spec-derived proxy.guarded.yaml scenarios)
  • ./mvnw clean install -DskipTests from the repo root — all modules build successfully (the only unrelated failure is cloud::docker-image, which requires a Docker daemon not present in the build environment)

Fixes #2103


Generated by Claude Code

Allow guarded: directly on mcp_openapi's own routes[], independent of
OpenAPI security scheme resolution. Composes with (rather than replaces)
the existing spec-derived guarding: same-guard roles union into one
entry, distinct guards add an additional AND'd entry on the generated
mcp_http0 route.

Fixes #2103

@jfallows jfallows left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jfallows
jfallows merged commit 80d224e into develop Jul 10, 2026
42 checks passed
jfallows pushed a commit to aklivity/zilla-docs that referenced this pull request Jul 10, 2026
Reflects aklivity/zilla#2105: an mcp_openapi route can now declare its own
guarded: roles independent of OpenAPI security-scheme resolution. Same-guard
roles union into one entry; a different guard adds a separate AND'd entry.
jfallows pushed a commit that referenced this pull request Jul 10, 2026
Allow operators to scope and guard individual tools via routes[], on
top of #2103/#2105's new mcp_openapi routes[].guarded support:

- routes[].when[].tool accepts a tool name or glob pattern (mirrors
  mcp_openapi's own when.tool schema - a singular string, not an
  array, since when[] is already the "match any of several"
  mechanism)
- routes[].guarded threads through to the generated mcp_openapi0
  route, resolved to an absolute namespace-qualified guard qname
  since the guard is declared in the operator's outer namespace but
  the generated route lives in the nested composite namespace
- with omitting routes entirely still exposes all 10 tools ungated
  (unchanged default); declaring routes narrows exposure to only the
  tools matched by a when.tool entry

routes[].with stays disallowed - the operation mapping is still
synthesized internally from the tool name, never operator-declared.
jfallows pushed a commit that referenced this pull request Jul 10, 2026
…g-consistency-65bxs2

Reconciles our shared OpenapiGuardResolver refactor (binding-mcp-openapi's
guard resolution moved off its own guardedRefs/resolveAlternative) with
develop's concurrently-landed #2105, which added operator-declared guarded:
composition (combineGuarded) on top of the pre-refactor code shape. Keeps
combineGuarded (genuinely new behavior) wired onto the shared resolver's
output instead of the removed local methods.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GkL1aVsaRHSPe4dCfd7kWK
jfallows added a commit that referenced this pull request Jul 22, 2026
…inding (#2068)

* feat(binding-mcp-schema-registry): scaffold spec-first module for issue #1672

Adds specs/binding-mcp-schema-registry.spec/ (schema patch, 20 mcp/http
.rpt scenario pairs for the 10 bundled tools, config fixtures, self
consistency ITs — all green) and runtime/binding-mcp-schema-registry/
module scaffold, wired into runtime/specs/docker-image poms. No Java
implementation yet by design: the runtime IT currently fails with an
unrecognized binding type, the expected checkpoint before implementation
begins per the repo's test-first discipline.

Design: kind: proxy emitting the real OpenapiBeginEx wire extension to an
operator-declared `type: openapi, kind: client` exit, mirroring the
binding-openapi-asyncapi precedent, using an internally-bundled spec to
resolve tool -> operationId with zero operator catalog boilerplate.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HL4h3tkf4oYSdjEgK4zffn

* feat(binding-mcp-schema-registry): implement mcp_schema_registry proxy binding

Adds the BindingFactorySpi, config adapters, and stream handler
(McpSchemaRegistryProxyFactory) that map the 10 bundled MCP tools onto
Schema Registry OpenAPI operations, forwarding through an operator-declared
openapi client exit per the mcp-natural design in #1672.

Also fixes escaping bugs in the .rpt fixtures: k3po strips a single
backslash-quote in single-quoted write/read literals, so scripts embedding
a JSON-quoted string value (the "schema" field) need \\" to produce a
literal \" on the wire. This was silently truncating declared contentLength
and corrupting response bodies for get_schema/register_schema/
check_compatibility. Also fixes the request-body flush to respect
initial-window flow-control credit instead of writing the full body
unconditionally on the first WINDOW frame.

Fixes #1672

* fix(docker-image): add binding-mcp-schema-registry to zpm.json.template

The module was already wired into runtime/pom.xml, specs/pom.xml, and
cloud/docker-image/pom.xml, but missing from the zpm packaging manifest,
so it would not have been installed into the published Docker image.

* refactor(binding-mcp-schema-registry): rewrite as thin composite wrapper around mcp_openapi

Replace the hand-rolled MCP proxy implementation with a kind:client
composite generator that inlines a bundled schema-registry OpenAPI spec
into a generated catalog and drives it through an mcp_openapi kind:client
binding, mirroring how binding-openapi's own kind:client generates its
downstream bindings. The 10 tools are fixed and author-controlled, so
routes and tool naming are synthesized internally rather than exposed as
operator-facing config; the only remaining option is options.server.

McpSchemaRegistryClientFactory is now a pure pass-through relay (no
protocol awareness), matching McpOpenapiClientFactory. Spec fixtures were
rewritten to the zilla://streams/http0 k3po transport (required for the
external-exit test double to intercept nested composite-generated
streams) and structuredContent shapes corrected to match mcp_openapi's
verbatim JSON passthrough behavior.

* fix(binding-mcp-schema-registry): wrap structuredContent under result key

mcp_openapi/mcp_http on current develop always wraps tool-call
structuredContent under a top-level "result" key, regardless of the
underlying HTTP response shape (object, array, or scalar) - a behavior
change picked up by merging develop (most likely from the common-json
parsson removal). Update all 10 scenarios' mcp-side fixtures to match.

* feat(binding-mcp-schema-registry): support routes[].when.tool + guarded

Allow operators to scope and guard individual tools via routes[], on
top of #2103/#2105's new mcp_openapi routes[].guarded support:

- routes[].when[].tool accepts a tool name or glob pattern (mirrors
  mcp_openapi's own when.tool schema - a singular string, not an
  array, since when[] is already the "match any of several"
  mechanism)
- routes[].guarded threads through to the generated mcp_openapi0
  route, resolved to an absolute namespace-qualified guard qname
  since the guard is declared in the operator's outer namespace but
  the generated route lives in the nested composite namespace
- with omitting routes entirely still exposes all 10 tools ungated
  (unchanged default); declaring routes narrows exposure to only the
  tools matched by a when.tool entry

routes[].with stays disallowed - the operation mapping is still
synthesized internally from the tool name, never operator-declared.

* style(binding-mcp-schema-registry): drop multi-line comments from McpSchemaRegistryClientFactory

* feat(binding-mcp-schema-registry): interpolate ${result.*} in tool summaries

Add explicit response schemas to register_schema, get_schema,
check_compatibility, get_compatibility, and set_compatibility in the bundled
OpenAPI spec, and interpolate their tool summaries with the confirmable
result value (e.g. "Registered schema with id ${result.id}").

Declaring the response schema is required, not cosmetic: without it,
McpOpenapiCompositeGenerator treats the tool output as schema-less and wraps
structuredContent as {"result": <value>}, shifting every capture path down
one level and making ${result.*} resolve empty.

* fix(binding-mcp-http): decide result wrapping from the real response shape

McpHttpResultWrap previously wrapped structuredContent as {"result": <value>}
whenever no declared object response schema existed, regardless of what the
upstream API actually returned. Any undeclared-schema operation whose real
response happened to already be an object got a spurious wrapper.

Make the decision from the real body's own first event instead: skip
wrapping when it's already an object, wrap otherwise (arrays, scalars, or
anything a declared array/scalar schema guarantees non-object). Rename
McpHttpToolConfig.outputWrapped to outputMaybeWrapped to reflect that the
field now only gates whether the transform is installed, not what it does.

Backs out the karapace-schema-registry.openapi.json response-schema
additions from the previous commit -- declaring schemas was a workaround for
this bug, not the real fix. ${result.*} interpolation in the 5 tool
summaries now works via the runtime fix alone, with no schema required.

* build(binding-mcp-schema-registry): update copyright year to 2026

Our spec and runtime modules were created before develop's bulk
copyright-year-update (#2183) landed, so their license headers still said
2021-2024 while the rest of the repo now says 2021-2026. license:format
brings both modules in line.

* fix(binding-mcp-schema-registry): remove list_contexts (Confluent-only, not in vanilla/Karapace Schema Registry)

GET /contexts ("Schema Contexts") is a Confluent Platform/Confluent Cloud
extension, absent from the Aiven-Open/karapace source and 404s against a
live Karapace instance. binding-mcp-schema-registry targets vanilla/Karapace
Schema Registry, so drop list_contexts from the bundled OpenAPI spec, the
composite generator's tool list, and all associated tests/fixtures.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HL4h3tkf4oYSdjEgK4zffn

* docs(examples/mcp.proxy): add a schemaregistry toolkit backed by real Karapace

Extends the multi-toolkit MCP gateway example with an mcp_schema_registry
kind:client binding wired against a real Karapace Schema Registry (not a
mock) sharing the example's existing Kafka broker. Adds the
south_mcp_schema_registry_client binding/routes, the karapace-registry
compose service, README documentation (architecture diagram, authorization
layering, walkthrough), and .github/test.sh assertions covering
tools/list scope filtering plus a full register -> list -> describe ->
get_schema -> set_compatibility -> get_compatibility -> check_compatibility
call sequence against the live Karapace instance.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HL4h3tkf4oYSdjEgK4zffn

* test(binding-mcp-schema-registry): add tools/list coverage

Every existing scenario only exercised tools/call by name; tools/list was
never tested for this binding. Add shouldListTools, driving a bare
mcp:beginEx().toolsList() request directly against the binding's own accept
side and asserting the full nine-tool set with correct input schemas comes
back.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HL4h3tkf4oYSdjEgK4zffn

* fix(examples/mcp.proxy): rename schemaregistry toolkit to kafka_sr, fix tools/list hydration

Renames the schema-registry toolkit's routing key from "schemaregistry" to
"kafka_sr" throughout north_mcp_proxy's routes, the eager tools.match list,
JWT scope examples, README, and .github/test.sh.

While validating this end-to-end, tools/list never surfaced any of the
toolkit's tools (not even as a cold/searchable tool), though tools/call by
name worked fine. Root cause: north_mcp_proxy.options.cache.authorization's
hardcoded hydration JWT never had its scope updated to include
kafka_sr:tools when this toolkit was added -- its guard silently rejected
the hydration stream while every other toolkit's required scope happened
to already be present in that credential. tools/call was unaffected
because real calls use the caller's own JWT, not this shared one. Minted a
new hydration credential including kafka_sr:tools and added a comment
warning that every new guarded toolkit must be added here too.

Full .github/test.sh run against the real stack (including live Karapace)
now passes 25/25 with zero failures.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HL4h3tkf4oYSdjEgK4zffn

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

binding-mcp-openapi: support operator-declared guarded routes independent of OpenAPI security schemes

2 participants