Skip to content

Commit 654e3d7

Browse files
jpicklykclaude
andcommitted
refactor: unify parameter extraction with shared helpers
Add extractItemBoolean to ItemFieldExtractors for handler-context boolean extraction. Replace inline jsonObject["key"]?.jsonPrimitive ?.booleanOrNull patterns with optionalBoolean() across 5 tool files. Replace inline offset extraction with optionalInt() in QueryItemsTool. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cac064a commit 654e3d7

File tree

8 files changed

+20
-9
lines changed

8 files changed

+20
-9
lines changed

current/src/main/kotlin/io/github/jpicklyk/mcptask/current/application/tools/items/CreateItemHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class CreateItemHandler(
5050
val statusLabel = extractItemString(itemObj, "statusLabel")
5151
val priorityStr = extractItemString(itemObj, "priority")
5252
val complexity = extractItemInt(itemObj, "complexity")
53-
val requiresVerification = itemObj["requiresVerification"]?.let { (it as? JsonPrimitive)?.booleanOrNull } ?: false
53+
val requiresVerification = extractItemBoolean(itemObj, "requiresVerification") ?: false
5454
val metadata = extractItemString(itemObj, "metadata")
5555
val tags = extractItemString(itemObj, "tags")
5656

current/src/main/kotlin/io/github/jpicklyk/mcptask/current/application/tools/items/ItemFieldExtractors.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ internal fun extractItemStringAllowNull(obj: JsonObject, name: String, existing:
3535
return if (content.isBlank()) null else content
3636
}
3737

38+
/**
39+
* Extracts an integer field from a JsonObject item. Returns null if absent or not parseable.
40+
*/
41+
/**
42+
* Extracts a boolean field from a JsonObject item. Returns null if absent or not parseable.
43+
*/
44+
internal fun extractItemBoolean(obj: JsonObject, name: String): Boolean? {
45+
val value = obj[name] as? JsonPrimitive ?: return null
46+
return value.booleanOrNull ?: value.content.toBooleanStrictOrNull()
47+
}
48+
3849
/**
3950
* Extracts an integer field from a JsonObject item. Returns null if absent or not parseable.
4051
*/

current/src/main/kotlin/io/github/jpicklyk/mcptask/current/application/tools/items/ManageItemsTool.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Unified write operations for WorkItems (create, update, delete).
143143
)
144144
"delete" -> deleteHandler.execute(
145145
requireJsonArray(params, "ids"),
146-
params.jsonObject["recursive"]?.jsonPrimitive?.booleanOrNull ?: false,
146+
optionalBoolean(params, "recursive", false),
147147
context
148148
)
149149
else -> errorResponse("Invalid operation: $operation", ErrorCodes.VALIDATION_ERROR)

current/src/main/kotlin/io/github/jpicklyk/mcptask/current/application/tools/items/QueryItemsTool.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ Operations: get, search, overview
237237

238238
private suspend fun executeGet(params: JsonElement, context: ToolExecutionContext): JsonElement {
239239
val idStr = requireString(params, "id")
240-
val includeAncestors = params.jsonObject["includeAncestors"]?.jsonPrimitive?.booleanOrNull ?: false
240+
val includeAncestors = optionalBoolean(params, "includeAncestors", false)
241241

242242
// Try parsing as a full UUID first (fast path — avoids prefix resolution overhead)
243243
val item = if (idStr.length == 36) {
@@ -340,8 +340,8 @@ Operations: get, search, overview
340340
val sortBy = optionalString(params, "sortBy")
341341
val sortOrder = optionalString(params, "sortOrder")
342342
val limit = optionalInt(params, "limit") ?: 50
343-
val offset = params.jsonObject["offset"]?.jsonPrimitive?.intOrNull?.coerceAtLeast(0) ?: 0
344-
val includeAncestors = params.jsonObject["includeAncestors"]?.jsonPrimitive?.booleanOrNull ?: false
343+
val offset = (optionalInt(params, "offset") ?: 0).coerceAtLeast(0)
344+
val includeAncestors = optionalBoolean(params, "includeAncestors", false)
345345

346346
// Parse role
347347
val role = roleStr?.let {

current/src/main/kotlin/io/github/jpicklyk/mcptask/current/application/tools/items/UpdateItemHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class UpdateItemHandler(
7777
val newStatusLabel = extractItemStringAllowNull(itemObj, "statusLabel", existing.statusLabel)
7878
val newPriorityStr = extractItemString(itemObj, "priority")
7979
val newComplexity = extractItemInt(itemObj, "complexity")
80-
val newRequiresVerification = itemObj["requiresVerification"]?.let { (it as? JsonPrimitive)?.booleanOrNull }
80+
val newRequiresVerification = extractItemBoolean(itemObj, "requiresVerification")
8181
val newMetadata = extractItemStringAllowNull(itemObj, "metadata", existing.metadata)
8282
val newTags = extractItemStringAllowNull(itemObj, "tags", existing.tags)
8383

current/src/main/kotlin/io/github/jpicklyk/mcptask/current/application/tools/workflow/GetBlockedItemsTool.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Items in TERMINAL role are never included.
101101
override suspend fun execute(params: JsonElement, context: ToolExecutionContext): JsonElement {
102102
val parentId = extractUUID(params, "parentId", required = false)
103103
val includeDetails = optionalBoolean(params, "includeItemDetails", false)
104-
val includeAncestors = params.jsonObject["includeAncestors"]?.jsonPrimitive?.booleanOrNull ?: false
104+
val includeAncestors = optionalBoolean(params, "includeAncestors", false)
105105

106106
val workItemRepo = context.workItemRepository()
107107
val depRepo = context.dependencyRepository()

current/src/main/kotlin/io/github/jpicklyk/mcptask/current/application/tools/workflow/GetContextTool.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Parameters:
9191
override suspend fun execute(params: JsonElement, context: ToolExecutionContext): JsonElement {
9292
val itemId = extractUUID(params, "itemId", required = false)
9393
val sinceInstant = parseInstant(params, "since")
94-
val includeAncestors = params.jsonObject["includeAncestors"]?.jsonPrimitive?.booleanOrNull ?: false
94+
val includeAncestors = optionalBoolean(params, "includeAncestors", false)
9595
val transitionLimit = params.jsonObject["limit"]?.jsonPrimitive?.intOrNull?.coerceIn(1, 200) ?: 50
9696

9797
return when {

current/src/main/kotlin/io/github/jpicklyk/mcptask/current/application/tools/workflow/GetNextItemTool.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Parameters:
7878
val parentId = extractUUID(params, "parentId", required = false)
7979
val limit = optionalInt(params, "limit") ?: 1
8080
val includeDetails = optionalBoolean(params, "includeDetails", defaultValue = false)
81-
val includeAncestors = params.jsonObject["includeAncestors"]?.jsonPrimitive?.booleanOrNull ?: false
81+
val includeAncestors = optionalBoolean(params, "includeAncestors", false)
8282

8383
val workItemRepo = context.workItemRepository()
8484
val dependencyRepo = context.dependencyRepository()

0 commit comments

Comments
 (0)