Class McpParamUtils

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

public final class McpParamUtils extends Object
Shared internal plumbing for revision 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 Details

    • asMap

      public static Map<String,Object> asMap(Object params)
      Coerces a JSON-RPC params value to a string-keyed map.
      Parameters:
      params - The raw params value. Can be null.
      Returns:
      The params as a map; an empty map when params is null. Never null.
      Throws:
      McpException - If params is present but is not a JSON object.
    • strParam

      public static String strParam(Map<String,Object> args, String key)
      Reads a parameter as a string.
      Parameters:
      args - The params map. Never null.
      key - The parameter name.
      Returns:
      The value's toString(), or null if absent.
    • mapParam

      public static Map<String,Object> mapParam(Map<String,Object> args, String key)
      Reads a parameter as a nested string-keyed map.
      Parameters:
      args - The params map. Never null.
      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

      public static String strictStrParam(Map<String,Object> args, String key)
      Reads a parameter as a string, rejecting any non-string JSON value rather than coercing it via toString().

      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 a completion/complete argument value, where a numeric or boolean value must be rejected outright, not silently stringified. Shared identically by both dated completion/complete dispatch arms.

      Parameters:
      args - The params map. Never null.
      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

      public static Map<String,String> 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.

      Shared identically by both dated completion/complete dispatch arms to parse context.arguments.

      Parameters:
      args - The params map. Never null.
      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.