Class McpRevision

java.lang.Object
org.apache.juneau.rest.server.mcp.v20250618.McpRevision
All Implemented Interfaces:
McpRevision

public final class McpRevision extends Object implements McpRevision
McpRevision implementation for MCP revision 2025-06-18.

Owns this revision's JSON-RPC method table and error-code table. Note the error-code table deliberately reproduces a known-wrong mapping: McpErrorKind.UNKNOWN_METHOD, McpErrorKind.TOOL_NOT_FOUND and McpErrorKind.PROMPT_NOT_FOUND all report -32601, which is only actually correct for the first. Preserving that is intentional — the corrective fix for those two is tracked separately and is not part of this re-layering. McpErrorKind.RESOURCE_NOT_FOUND is not part of that known-wrong grouping: it correctly reports -32002, the 2025-06-18 spec's dedicated missing-resource error code.

Constructed per binding, not shared as a singleton (Correction C8). The bound servlet or mixin builds a fresh instance on every revision() call, passing its own capabilities() hook result into the constructor — see McpRestServlet and McpEndpoint. That is how this revision learns which explicit capabilities (if any) to advertise, with no channel back into core: this class is otherwise entirely stateless, so constructing a new one per call costs nothing.

  • Field Details

  • Constructor Details

    • McpRevision

      public McpRevision(ServerCapabilities capabilities)
      Constructor.
      Parameters:
      capabilities - Explicit capabilities to advertise on initialize, or null to auto-derive from the registered tool/prompt/resource lists (today's default behavior).
  • Method Details

    • validateSchemas

      public static void validateSchemas(McpServerConfig config)
      Verifies that every registered tool's input and output schema is expressible in this revision's wire schema type.

      The neutral McpSchema is an unconstrained JSON object carrier, but this revision's JsonSchema bean supports exactly six keywords and models only object schemas. Each schema role is therefore checked twice: its root must declare "type":"object", and the complete graph reachable from that root may use only this revision's six keywords. Rather than silently dropping an unsupported keyword — or an incompatible root shape — on the wire, a config carrying one is rejected, naming the tool, the offending role (inputSchema / outputSchema), and the offending shape or keyword.

      Before walking, each schema is passed through JsonValueSafety to bound nesting depth, node count, traversal time, and cyclic/shared references, so a pathological config cannot stall or exhaust the walk.

      Note this cannot be a complete guarantee against every possible wire shape: JsonSchema is public and non-final, and Juneau's reflection-based marshalling will serialize a getter added by a subclass. No such subclass exists in this codebase, and none can be constructed through the public MCP API, but the check covers what a caller can express through McpSchema, not what reflection can reach.

      Parameters:
      config - The config to validate. Never null.
      Throws:
      IllegalArgumentException - If any tool's input or output schema has a non-object root or uses an unsupported keyword.
    • protocolVersion

      Description copied from interface: McpRevision
      The MCP protocol revision string this implementation speaks.
      Specified by:
      protocolVersion in interface McpRevision
      Returns:
      The revision token (e.g. "2025-06-18"). Never null.
    • errorCode

      public int errorCode(McpErrorKind kind)
      Description copied from interface: McpRevision
      Maps a neutral failure classification to this revision's JSON-RPC error code.
      Specified by:
      errorCode in interface McpRevision
      Parameters:
      kind - The failure classification. Never null.
      Returns:
      The JSON-RPC error code this revision reports for that kind.
    • dispatch

      Description copied from interface: McpRevision
      Dispatches one JSON-RPC request.
      Specified by:
      dispatch in interface McpRevision
      Parameters:
      exchange - The inbound envelope plus header access. Never null.
      config - The neutral handler registry and pagination strategy. Never null.
      ctx - The per-request bean store, passed through to handlers. Never null.
      Returns:
      A McpResponseResult for a normal request, a McpStreamResult (for example wrapping a Flow.Publisher produced by a v2-only method) for a request whose response is not a single JSON-RPC envelope, or null for a notification request (which the HTTP layer renders as an empty body).