Class ToolArguments

java.lang.Object
eu.mrapik.minecraftservermcp.util.ToolArguments

public final class ToolArguments extends Object
Helpers for reading string-keyed maps: MCP McpSchema.CallToolRequest.arguments() (client JSON) and ToolAccessConfig.extra() (YAML).

Missing keys return null for strings; booleans and ints use defaults when absent. String fields use Object.toString() where applicable, matching typical JSON inputs from MCP clients.

  • Method Details

    • map

      public static Map<String,Object> map(io.modelcontextprotocol.spec.McpSchema.CallToolRequest request)
      Returns the argument map from the request, never null.
      Parameters:
      request - MCP tool call request
      Returns:
      the arguments map, or an empty map if the SDK passes null
    • string

      @Nullable public static @Nullable String string(Map<String,Object> args, String key)
      Reads a string argument; coerces non-null values with Object.toString().
      Parameters:
      args - argument map
      key - JSON property name
      Returns:
      null if the key is missing or the value is null
    • bool

      public static boolean bool(Map<String,Object> args, String key, boolean def)
      Reads a boolean argument; accepts Boolean or parses string values with Boolean.parseBoolean(String).
      Parameters:
      args - argument map
      key - JSON property name
      def - value when the key is absent
      Returns:
      resolved boolean
    • intArg

      public static int intArg(Map<String,Object> args, String key, int def)
      Reads a non-negative int from args (tool arguments or ToolAccessConfig.extra()). Negative values and parse failures yield 0 or def as described below.
      Parameters:
      args - map to read from
      key - property name
      def - value when the key is absent, null, or the value cannot be parsed as an int
      Returns:
      parsed int clamped to 0 or higher; def only when missing, null, or unparsable