Class McpParamUtils
McpRevision.dispatch(org.apache.juneau.rest.server.mcp.McpExchange, org.apache.juneau.rest.server.mcp.McpServerConfig, org.apache.juneau.commons.inject.BeanStore) implementations.
Untyped-parameter coercion and typed-argument extraction. Not a general-purpose public API: the
methods are public only because a revision adapter lives in a different package from this
one (org.apache.juneau.rest.server.mcp.v20250618 vs. org.apache.juneau.rest.server.mcp),
and Java package-private visibility does not span that boundary.
The -32602 code these methods raise is the JSON-RPC 2.0 standard "Invalid params"
code, not a per-revision choice, which is why it is fixed here rather than routed through
McpRevision.errorCode(McpErrorKind). A revision that needs a different code for malformed
parameters must coerce parameters itself instead of using these helpers.
-
Method Summary
Modifier and TypeMethodDescriptionCoerces a JSON-RPCparamsvalue to a string-keyed map.Reads a parameter as a nested string-keyed map.strictStrMapParam(Map<String, Object> args, String key) Reads a parameter as a string-to-string map, rejecting any entry whose value is not a JSON string.static StringstrictStrParam(Map<String, Object> args, String key) Reads a parameter as a string, rejecting any non-string JSON value rather than coercing it viatoString().static StringReads a parameter as a string.
-
Method Details
-
asMap
Coerces a JSON-RPCparamsvalue to a string-keyed map.- Parameters:
params- The raw params value. Can benull .- Returns:
- The params as a map; an empty map when
paramsisnull . Nevernull . - Throws:
McpException- Ifparamsis present but is not a JSON object.
-
strParam
Reads a parameter as a string.- Parameters:
args- The params map. Nevernull .key- The parameter name.- Returns:
- The value's
toString(), ornull if absent.
-
mapParam
Reads a parameter as a nested string-keyed map.- Parameters:
args- The params map. Nevernull .key- The parameter name.- Returns:
- The nested map; an empty map when the parameter is absent. Never
null . - Throws:
McpException- If the parameter is present but is not a JSON object.
-
strictStrParam
Reads a parameter as a string, rejecting any non-string JSON value rather than coercing it viatoString().Unlike
strParam(Map, String), which accepts any JSON scalar and stringifies it, this is for parameters whose protocol contract requires the wire value to already be a JSON string - for example acompletion/completeargument value, where a numeric or boolean value must be rejected outright, not silently stringified. Shared identically by both datedcompletion/completedispatch arms.- Parameters:
args- The params map. Nevernull .key- The parameter name.- Returns:
- The string value, or
null if absent. - Throws:
McpException- If the parameter is present but is not a JSON string.
-
strictStrMapParam
Reads a parameter as a string-to-string map, rejecting any entry whose value is not a JSON string.Shared identically by both dated
completion/completedispatch arms to parsecontext.arguments.- Parameters:
args- The params map. Nevernull .key- The parameter name.- Returns:
- The nested map with every value verified to be a string; an empty map when the parameter is
absent. Never
null . - Throws:
McpException- If the parameter is present but is not a JSON object, or if any of its values is not a JSON string.
-