Class McpCompletionResult

java.lang.Object
org.apache.juneau.rest.server.mcp.McpCompletionResult

public class McpCompletionResult extends Object
Revision-neutral, as-returned-by-the-application result of an McpCompleter invocation.

Supersedes the wire-level CompleteResult/Completion beans. An instance of this class is the completer's raw, unvalidated output; call normalize(McpCompletionResult) exactly once per completion dispatch to obtain the McpCompletionResult.Normalized shape both dated adapters map to their wire result.

Normalization contract:

Applied by normalize(McpCompletionResult) before wire mapping:

  • null values normalizes to an empty list;
  • order is preserved (application-owned ranking) and duplicates are preserved;
  • a null element within values is an internal handler failure;
  • the first 100 values are emitted; truncation forces hasMore=true;
  • a supplied non-negative total is preserved; a negative total is an internal handler failure;
  • without truncation, a nullable hasMore is passed through unchanged; and
  • a completer returning null itself (rather than an McpCompletionResult with null fields) is also an internal handler failure.
Internal handler failure representation:

Each of the three "internal handler failure" cases above is surfaced identically: as an McpException carrying CODE_INTERNAL_ERROR (-32603), the JSON-RPC 2.0 standard "Internal error" code. That code is fixed by the JSON-RPC specification, not chosen per revision, which is why it is a local constant here rather than routed through McpRevision#errorCode(McpErrorKind) - the same reasoning McpParamUtils documents for its -32602 constant. Both dated adapters' existing top-level catch (McpException e) dispatch handling (see McpRevision#dispatch) already converts any McpException thrown during completion/complete handling straight into a JSON-RPC error response with this code, so adapters do not need any additional mapping step beyond calling normalize(McpCompletionResult) and letting a thrown McpException propagate.