Coming soon ChenAIle — agentic microservices: agents, AI tool calls, machine learning and a metrics-driven rules engine Learn more →
How it works · Polymorphic contracts for OpenAPI 3.1 and MCP in Java

One operation, many shapes, one contract

A workflow's PATCH /order/{id}/{eventID} takes a different payload for each event, and each event may need different authorities. Most frameworks describe it as one call that takes Object. Chenile lists its variants once, publishes the same variants to AI agents, OpenAPI and the service registry, and uses them to type and guard every request.

Java 25 · Spring Boot 4 · OpenAPI 3.1 · MCP · JSON Schema 2020-12

A polymorphic Chenile operation: one contract at startup, the right variant per request At startup, the workflow's body type selector lists one variant per event of PATCH /order/{id}/{eventID}: its name, payload type and authorities. chenile-core stores them on the operation, and MCP, OpenAPI and the service registry publish the same variants. Per request, the client calls the operation; the entry point builds an exchange; the typing step matches the eventID to a variant and the selector picks the payload type; the transformer converts the JSON body; the security interceptor checks the variant's authorities; and the service runs the workflow event, or the caller gets 403 Forbidden. At startup · the contract, decided once StmBodyTypeSelector getVariants() states XML submit · acls order.submit cancel · acls order.cancel note · no payload type OperationDefinition.variants PATCH /order/{id}/{eventID} · contract order_processById order_processById_submit eventID=submit · SubmitPayload · [order.submit] order_processById_cancel eventID=cancel · CancelPayload · [order.cancel] MCP tools order_processById_submit, …_cancel OpenAPI PATCH /order/{id}/submit, …/cancel Service registry JSON Schema contract · aggregated OpenAPI Per request · the chenile-highway ClientPATCH …/submit HttpEntryPointor MCP, events… headerscopied to context typing stepvariant + body type transformersJSON by default securityoperation interceptor variant: … bodyType: … needs: … user has: … order-serviceevent: submit response: the workflow's new state, or 403 Forbidden reads the variants
event
caller
view
Step 1

Exchange

Payload

Before and after

What you write, and what Chenile publishes from it

The source on the left is all there is. The OpenAPI 3.1 document and the MCP tools on the right are generated from it at startup, from the same variants and the same schema generator.

One PATCH /order/{id}/{eventID}, typed per event.

You write
<!-- who may raise each event -->
<event-information eventId="submit" meta-acls="order.submit"/>
<event-information eventId="cancel" meta-acls="order.cancel"/>

<flow id="order-flow" default="true">
  <manual-state id="DRAFT" initialState="true">
    <on eventId="submit" newStateId="SUBMITTED"
        meta-description="Submit the order for approval"/>
    <on eventId="cancel" newStateId="CANCELLED"
        meta-description="Cancel the order"/>
  </manual-state>
  <manual-state id="SUBMITTED"/>
  <manual-state id="CANCELLED"/>
</flow>
Chenile publishes
paths:
  /order/{id}/submit:             # one path per event
    patch:
      operationId: order_processById_submit
      summary: Submit the order for approval
      x-chenile-variant: order_processById_submit
      x-chenile-authorities: [order.submit]
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string }
      requestBody:
        content:
          application/json:
            schema: { $ref: '#/components/schemas/SubmitPayload' }
  /order/{id}/cancel:
    patch:
      operationId: order_processById_cancel
      x-chenile-authorities: [order.cancel]
      …
components:
  schemas:
    SubmitPayload:                  # JSON Schema 2020-12
      type: object
      properties:
        comment: { type: string }
        deliveryDate: { type: string, format: date }

Abridged. Add an event to the states XML and it appears as a new path, a new MCP tool and a new guarded variant on the next start, with no Java change.

At startup

The contract is decided once

Who lists the variants

A ChenilePolymorphProvider. Usually it is the operation's own body type selector: StmBodyTypeSelector lists one variant per workflow event, SubclassBodyTypeSelector one per registered subclass. When the variants come from somewhere else, such as one per query definition, name a provider with @ChenilePolymorph("bean"). The bean that types the request is the bean that describes it, so the two cannot drift.

What a variant says

A complete name (by default <contractName>_<suffix>), a description, the payload type or JSON schema, the fixed parameter values or body field that select it, and the authorities it needs. ChenilePolymorphInitializer computes the list at startup, checks that names are unique and that no two variants are selected the same way, and stores it on the operation.

Published once, the same everywhere

MCP publishes one tool per variant. OpenAPI publishes one path per variant selected by a path variable (for example PATCH /order/{id}/submit, or POST /q/students for queries) and a oneOf body for the others, with x-chenile-authorities. The service registry stores the variants with their JSON Schemas and serves an OpenAPI document for the whole system.

The same schema generator

Every schema comes from ChenileJsonSchemaGenerator (JSON Schema Draft 2020-12, the dialect of OpenAPI 3.1), so an AI agent, an OpenAPI client and the registry see the same shape for SubmitPayload.

Not just workflows

Queries: one endpoint, a contract per query, ACLs per tenant

POST /q/{queryName} serves every query a deployable defines. QueryPolymorph makes each query a variant, so it gets its own OpenAPI path, its own MCP tool and its own guard.

A schema from the query definition

Each variant's request schema is built from the query's column metadata: filterable columns become filters (an array for contains queries, a one-or-two item array for ranges, an enum for drop-downs), sortable columns the sortCriteria names, and paging fields only when the query is paginated.

Tenant overrides, resolved per request

A tenant can redefine a query under the same name, with its own SQL and its own acls. The contract keeps one variant per name, described by the base definition. For each request, QueryPolymorph.resolveVariant looks up the caller's tenant (x-chenile-tenant-id) and returns that tenant's definition, so its ACLs are the ones checked.

Guarded by your controller

The query controller that ships with Chenile is unguarded. To enforce the ACLs, write your own query controller with @ChenilePolymorph("queryPolymorph") and a plain @SecurityConfig, as in the Query, per tenant example above.

Per request

The chenile-highway picks the variant

Every transport goes through the same highway, so an HTTP call, an MCP tool call, an event and a local proxy call are typed and guarded the same way.

1 · Which variant

Before any selector runs, the typing step matches the request against the variants: all of a variant's fixed values must equal the request's path variables and headers, and its body field (for subclasses) the body's, read with a streaming parser. The most specific match wins, and a tie is an error. A provider can resolve the variant itself, as queries do for tenant-specific definitions.

2 · Which type

The body type selector sets the payload type. If it sets none, the typing step falls back to the operation's default type (chenile.transform.selector-fallback, on by default). Then the transformers convert the body, JSON by default.

3 · Who may call it

The security interceptor runs after the typing step. A plain @SecurityConfig on the operation guards each request with its variant's authorities (a workflow event's meta-acls, a query's acls), and with the operation's own authorities when the variant has none.

Polymorphism, the concept →   Developer guide →   Every transport adapter →