Class McpCompletionResult
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 valuesnormalizes to an empty list;- order is preserved (application-owned ranking) and duplicates are preserved;
- a
null element withinvaluesis an internal handler failure; - the first 100 values are emitted; truncation forces
hasMore=true; - a supplied non-negative
totalis preserved; a negativetotalis an internal handler failure; - without truncation, a nullable
hasMoreis passed through unchanged; and - a completer returning
null itself (rather than anMcpCompletionResultwithnull 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe normalized shape of a completion result, ready for wire mapping. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intJSON-RPC error code raised bynormalize(McpCompletionResult)for any internal handler failure.static final intThe maximum number of completion values aMcpCompletionResult.Normalizedresult ever carries. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic McpCompletionResultempty()Creates the neutral empty-completion result, the shape both dated adapters map to{"completion":{"values":[]}}.Whether more completions exist beyondvalues.getTotal()The total number of completions available, if known, independent of how many values are emitted.The completion suggestions, in application-ranked order.normalize(McpCompletionResult result) Applies the normalization contract documented on this class to a completer's raw return value.setHasMore(Boolean value) Sets whether more completions exist beyondvalues.Sets the total number of completions available.Sets the completion suggestions.
-
Field Details
-
MAX_VALUES
The maximum number of completion values aMcpCompletionResult.Normalizedresult ever carries. Juneau performs no ranking, filtering, deduplication, or pagination of its own; this is strictly a truncation cap.- See Also:
-
CODE_INTERNAL_ERROR
JSON-RPC error code raised bynormalize(McpCompletionResult)for any internal handler failure. See the class Javadoc "Internal handler failure representation" section.- See Also:
-
-
Constructor Details
-
McpCompletionResult
public McpCompletionResult()
-
-
Method Details
-
empty
Creates the neutral empty-completion result, the shape both dated adapters map to{"completion":{"values":[]}}. -
getValues
The completion suggestions, in application-ranked order.- Returns:
- The values, or
null if not set. Normalized to an empty list bynormalize(McpCompletionResult).
-
setValues
Sets the completion suggestions.- Parameters:
value- The new value. Can benull to unset the property.- Returns:
- This object.
-
getTotal
The total number of completions available, if known, independent of how many values are emitted.- Returns:
- The total, or
null if not set/unknown.
-
setTotal
Sets the total number of completions available.- Parameters:
value- The new value. Must be non-negative if non-null ; seenormalize(McpCompletionResult). Can benull to unset the property.- Returns:
- This object.
-
getHasMore
Whether more completions exist beyondvalues.- Returns:
- The flag, or
null if not set/unknown.
-
setHasMore
Sets whether more completions exist beyondvalues.- Parameters:
value- The new value. Can benull to unset the property.- Returns:
- This object.
-
normalize
Applies the normalization contract documented on this class to a completer's raw return value.- Parameters:
result- The raw result returned by anMcpCompleter. Can benull .- Returns:
- The normalized shape ready for wire mapping. Never
null . - Throws:
McpException- WithCODE_INTERNAL_ERRORifresultisnull , ifresult's values contain anull element, or ifresult's total is negative.
-