Package com.tnsai.mcp.model
Class McpToolArgs
java.lang.Object
com.tnsai.mcp.model.McpToolArgs
Type-safe builder and accessor for MCP tool arguments.
MCP tool arguments are JSON objects represented as Map<String, Object>.
This class provides:
- Null-safe argument construction (unlike
Map.of()which rejects nulls) - Typed accessor methods for reading argument values
- Fluent builder API
- Immutable result map
Usage
// Build arguments
Map<String, Object> args = McpToolArgs.builder()
.put("path", "/tmp/test.txt")
.put("recursive", true)
.put("maxDepth", 5)
.build();
// Read arguments with type safety
McpToolArgs toolArgs = McpToolArgs.wrap(args);
String path = toolArgs.getString("path");
boolean recursive = toolArgs.getBoolean("recursive", false);
int maxDepth = toolArgs.getInt("maxDepth", 10);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFluent builder for constructing MCP tool arguments. -
Method Summary
Modifier and TypeMethodDescriptionstatic McpToolArgs.Builderbuilder()Creates a new builder.booleangetBoolean(String key, boolean defaultValue) Gets a boolean value.doubleGets a double value.intGets an integer value.<T> List<T> Gets a list value.longGets a long value.Gets a nested map value.Gets a string value.Gets a string value with default.booleanChecks if a key exists.Creates a single-argument map.Creates a two-argument map.Creates a three-argument map.intsize()Returns the number of arguments.toMap()Returns the raw argument map.toString()static McpToolArgsWraps an existing argument map for typed access.
-
Method Details
-
wrap
Wraps an existing argument map for typed access.- Parameters:
args- the argument map (may be null)- Returns:
- a McpToolArgs wrapper
-
builder
Creates a new builder.- Returns:
- new builder instance
-
of
Creates a single-argument map. Null values are permitted.- Parameters:
key- the argument namevalue- the argument value (may be null)- Returns:
- unmodifiable argument map
-
of
Creates a two-argument map. Null values are permitted. -
of
public static Map<String,Object> of(String k1, Object v1, String k2, Object v2, String k3, Object v3) Creates a three-argument map. Null values are permitted. -
getString
Gets a string value.- Parameters:
key- the argument name- Returns:
- the value, or null if absent or not a string
-
getString
Gets a string value with default. -
getInt
Gets an integer value.- Parameters:
key- the argument namedefaultValue- fallback if absent or not a number- Returns:
- the integer value
-
getLong
Gets a long value. -
getDouble
Gets a double value. -
getBoolean
Gets a boolean value. -
getList
Gets a list value. -
getMap
Gets a nested map value. -
has
Checks if a key exists. -
toMap
Returns the raw argument map. -
size
public int size()Returns the number of arguments. -
toString
-