ToolArgsParser
Parser for MCP tool arguments with soft assertion-style validation. Collects all errors and reports them together instead of failing on the first error.
Usage:
val parser = ToolArgsParser(args)
val previewId = parser.requireString("previewId")
val label = parser.requireString("label")
val index = parser.requireInt("index")
parser.validate() // throws if any errors occurredContent copied to clipboard
Functions
Link copied to clipboard
Returns an error message string if there are errors, or null if validation passed. Useful for returning error results without throwing exceptions.
Link copied to clipboard
Gets an optional integer argument with a default value.
Link copied to clipboard
Gets an optional string argument with a default value.
Link copied to clipboard
Requires an integer argument. Returns the value if present and valid, or 0 if missing/invalid (error is collected).
Link copied to clipboard
Requires a string argument. Returns the value if present, or an empty string if missing (error is collected).
Link copied to clipboard
Validates all collected arguments. Throws ToolArgsValidationException if any errors were collected.