Skip to content

Commit e463a6b

Browse files
jpicklykclaude
andcommitted
chore: fix naming typos and clean up CurrentMcpServer
- Fix roleCounToJson typo → roleCountToJson in QueryItemsTool - Rename mapRowToWorkItem/mapRowToWorkItemSafe → toWorkItem/toWorkItemOrNull in SQLiteWorkItemRepository to follow Kotlin naming conventions - Replace hardcoded "13 tools" in server instructions with dynamic toolCount/toolNames derived from the registered tool list - Extract registerCommonCleanup() to deduplicate shutdown action registration between stdio and HTTP transports - Add server.onClose handler to HTTP transport for DB shutdown parity with stdio transport Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 018901f commit e463a6b

File tree

3 files changed

+49
-42
lines changed

3 files changed

+49
-42
lines changed

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
@@ -476,7 +476,7 @@ Operations: get, search, overview
476476

477477
val data = buildJsonObject {
478478
put("item", workItemToJson(item))
479-
put("childCounts", roleCounToJson(childCounts))
479+
put("childCounts", roleCountToJson(childCounts))
480480
put("children", JsonArray(children.map { workItemToMinimalJson(it) }))
481481
}
482482

@@ -508,7 +508,7 @@ Operations: get, search, overview
508508
put("title", JsonPrimitive(item.title))
509509
put("role", JsonPrimitive(item.role.name.lowercase()))
510510
put("priority", JsonPrimitive(item.priority.name.lowercase()))
511-
put("childCounts", roleCounToJson(childCounts))
511+
put("childCounts", roleCountToJson(childCounts))
512512
if (includeChildren) {
513513
val children = when (val result = context.workItemRepository().findChildren(item.id)) {
514514
is Result.Success -> result.data
@@ -567,7 +567,7 @@ Operations: get, search, overview
567567
item.tags?.let { put("tags", JsonPrimitive(it)) }
568568
}
569569

570-
private fun roleCounToJson(counts: Map<Role, Int>): JsonObject = buildJsonObject {
570+
private fun roleCountToJson(counts: Map<Role, Int>): JsonObject = buildJsonObject {
571571
for (role in Role.entries) {
572572
put(role.name.lowercase(), JsonPrimitive(counts[role] ?: 0))
573573
}

current/src/main/kotlin/io/github/jpicklyk/mcptask/current/infrastructure/repository/SQLiteWorkItemRepository.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
4242
newSuspendedTransaction(db = databaseManager.getDatabase()) {
4343
val row = WorkItemsTable.selectAll().where { WorkItemsTable.id eq id }.singleOrNull()
4444
if (row != null) {
45-
Result.Success(mapRowToWorkItem(row))
45+
Result.Success(toWorkItem(row))
4646
} else {
4747
Result.Error(RepositoryError.NotFound(id, "WorkItem not found with id: $id"))
4848
}
@@ -133,7 +133,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
133133
val items = WorkItemsTable.selectAll()
134134
.where { WorkItemsTable.parentId eq parentId }
135135
.limit(limit)
136-
.mapNotNull { mapRowToWorkItemSafe(it) }
136+
.mapNotNull { toWorkItemOrNull(it) }
137137
Result.Success(items)
138138
}
139139
} catch (e: Exception) {
@@ -145,7 +145,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
145145
val items = WorkItemsTable.selectAll()
146146
.where { WorkItemsTable.role eq role.name.lowercase() }
147147
.limit(limit)
148-
.mapNotNull { mapRowToWorkItemSafe(it) }
148+
.mapNotNull { toWorkItemOrNull(it) }
149149
Result.Success(items)
150150
}
151151
} catch (e: Exception) {
@@ -157,7 +157,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
157157
val items = WorkItemsTable.selectAll()
158158
.where { WorkItemsTable.depth eq depth }
159159
.limit(limit)
160-
.mapNotNull { mapRowToWorkItemSafe(it) }
160+
.mapNotNull { toWorkItemOrNull(it) }
161161
Result.Success(items)
162162
}
163163
} catch (e: Exception) {
@@ -169,7 +169,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
169169
val row = WorkItemsTable.selectAll()
170170
.where { WorkItemsTable.parentId.isNull() and (WorkItemsTable.depth eq 0) }
171171
.singleOrNull()
172-
Result.Success(row?.let { mapRowToWorkItemSafe(it) })
172+
Result.Success(row?.let { toWorkItemOrNull(it) })
173173
}
174174
} catch (e: Exception) {
175175
Result.Error(RepositoryError.DatabaseError("Failed to find root WorkItem: ${e.message}", e))
@@ -183,7 +183,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
183183
(WorkItemsTable.title like pattern) or (WorkItemsTable.summary like pattern)
184184
}
185185
.limit(limit)
186-
.mapNotNull { mapRowToWorkItemSafe(it) }
186+
.mapNotNull { toWorkItemOrNull(it) }
187187
Result.Success(items)
188188
}
189189
} catch (e: Exception) {
@@ -203,7 +203,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
203203
newSuspendedTransaction(db = databaseManager.getDatabase()) {
204204
val items = WorkItemsTable.selectAll()
205205
.where { WorkItemsTable.parentId eq parentId }
206-
.mapNotNull { mapRowToWorkItemSafe(it) }
206+
.mapNotNull { toWorkItemOrNull(it) }
207207
Result.Success(items)
208208
}
209209
} catch (e: Exception) {
@@ -273,7 +273,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
273273
.orderBy(sortColumn, order)
274274
.limit(limit)
275275
.offset(offset.toLong())
276-
.mapNotNull { mapRowToWorkItemSafe(it) }
276+
.mapNotNull { toWorkItemOrNull(it) }
277277

278278
Result.Success(items)
279279
}
@@ -333,7 +333,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
333333
newSuspendedTransaction(db = databaseManager.getDatabase()) {
334334
val counts = WorkItemsTable.selectAll()
335335
.where { WorkItemsTable.parentId eq parentId }
336-
.mapNotNull { mapRowToWorkItemSafe(it) }
336+
.mapNotNull { toWorkItemOrNull(it) }
337337
.groupBy { it.role }
338338
.mapValues { (_, items) -> items.size }
339339
Result.Success(counts)
@@ -347,7 +347,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
347347
val items = WorkItemsTable.selectAll()
348348
.where { WorkItemsTable.parentId.isNull() }
349349
.limit(limit)
350-
.mapNotNull { mapRowToWorkItemSafe(it) }
350+
.mapNotNull { toWorkItemOrNull(it) }
351351
Result.Success(items)
352352
}
353353
} catch (e: Exception) {
@@ -364,7 +364,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
364364
val current = queue.removeFirst()
365365
val children = WorkItemsTable.selectAll()
366366
.where { WorkItemsTable.parentId eq current }
367-
.mapNotNull { mapRowToWorkItemSafe(it) }
367+
.mapNotNull { toWorkItemOrNull(it) }
368368
results.addAll(children)
369369
queue.addAll(children.map { it.id })
370370
}
@@ -383,7 +383,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
383383
Result.Success(
384384
WorkItemsTable.selectAll()
385385
.where { WorkItemsTable.id inList entityIds }
386-
.mapNotNull { mapRowToWorkItemSafe(it) }
386+
.mapNotNull { toWorkItemOrNull(it) }
387387
)
388388
}
389389
} catch (e: Exception) {
@@ -416,7 +416,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
416416
WorkItemsTable.id.castTo<String>(VarCharColumnType(36)).like("$formattedPrefix%")
417417
}
418418
.limit(limit)
419-
.mapNotNull { mapRowToWorkItemSafe(it) }
419+
.mapNotNull { toWorkItemOrNull(it) }
420420
Result.Success(items)
421421
}
422422
} catch (e: Exception) {
@@ -452,7 +452,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
452452
val inputEntityIds = itemIds.map { EntityID(it, WorkItemsTable) }
453453
val inputItems = WorkItemsTable.selectAll()
454454
.where { WorkItemsTable.id inList inputEntityIds }
455-
.mapNotNull { mapRowToWorkItemSafe(it) }
455+
.mapNotNull { toWorkItemOrNull(it) }
456456
inputItems.forEach { cache[it.id.toString()] = it }
457457

458458
// BFS upward: collect all parentIds that need fetching
@@ -461,7 +461,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
461461
val fetchEntityIds = toFetch.map { EntityID(UUID.fromString(it), WorkItemsTable) }
462462
val fetched = WorkItemsTable.selectAll()
463463
.where { WorkItemsTable.id inList fetchEntityIds }
464-
.mapNotNull { mapRowToWorkItemSafe(it) }
464+
.mapNotNull { toWorkItemOrNull(it) }
465465
fetched.forEach { cache[it.id.toString()] = it }
466466
toFetch = fetched.mapNotNull { it.parentId }.map { it.toString() }.toSet() - cache.keys
467467
}
@@ -506,7 +506,7 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
506506
}.reduce { acc, op -> acc or op }
507507
}
508508

509-
private fun mapRowToWorkItem(row: ResultRow): WorkItem {
509+
private fun toWorkItem(row: ResultRow): WorkItem {
510510
return WorkItem(
511511
id = row[WorkItemsTable.id].value,
512512
parentId = row[WorkItemsTable.parentId],
@@ -530,15 +530,15 @@ class SQLiteWorkItemRepository(private val databaseManager: DatabaseManager) : W
530530
}
531531

532532
/**
533-
* Safe variant of [mapRowToWorkItem] for bulk-read operations.
533+
* Safe variant of [toWorkItem] that returns null on failure, for bulk-read operations.
534534
*
535535
* Returns null and logs a warning if a row contains data that fails domain validation
536536
* (e.g. an oversized title written by an older version of the server). This prevents
537537
* a single corrupt row from crashing an entire list query.
538538
*/
539-
private fun mapRowToWorkItemSafe(row: ResultRow): WorkItem? {
539+
private fun toWorkItemOrNull(row: ResultRow): WorkItem? {
540540
return try {
541-
mapRowToWorkItem(row)
541+
toWorkItem(row)
542542
} catch (e: Exception) {
543543
logger.warn(
544544
"Skipping corrupt WorkItem row (id={}): {}",

current/src/main/kotlin/io/github/jpicklyk/mcptask/current/interfaces/mcp/CurrentMcpServer.kt

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,7 @@ class CurrentMcpServer(
7979
val toolContext = ToolExecutionContext(repositoryProvider, noteSchemaService)
8080
logger.info("Repository provider and tool context initialized")
8181

82-
// Configure MCP server
83-
val serverName = System.getenv("MCP_SERVER_NAME") ?: "mcp-task-orchestrator-current"
84-
val server = configureServer(serverName)
85-
mcpSdkServer = server
86-
87-
// Register MCP tools
88-
val adapter = McpToolAdapter()
82+
// Build tool list
8983
val tools = listOf(
9084
// Phase 1: CRUD
9185
ManageItemsTool(),
@@ -106,6 +100,15 @@ class CurrentMcpServer(
106100
// Phase 3: Context
107101
GetContextTool()
108102
)
103+
104+
// Configure MCP server
105+
val serverName = System.getenv("MCP_SERVER_NAME") ?: "mcp-task-orchestrator-current"
106+
val toolNames = tools.joinToString(", ") { it.name }
107+
val server = configureServer(serverName, tools.size, toolNames)
108+
mcpSdkServer = server
109+
110+
// Register MCP tools
111+
val adapter = McpToolAdapter()
109112
adapter.registerToolsWithServer(server, tools, toolContext)
110113
logger.info("Registered ${tools.size} MCP tools")
111114

@@ -129,6 +132,15 @@ class CurrentMcpServer(
129132
mcpSdkServer?.close()
130133
}
131134

135+
private fun registerCommonCleanup(server: Server) {
136+
shutdownCoordinator?.addCleanupAction("Close MCP Server") {
137+
runBlocking { server.close() }
138+
}
139+
shutdownCoordinator?.addCleanupAction("Close Database") {
140+
databaseManager.shutdown()
141+
}
142+
}
143+
132144
private suspend fun runStdioTransport(server: Server, serverName: String, toolCount: Int) {
133145
logger.info("Starting MCP server with stdio transport...")
134146

@@ -137,12 +149,7 @@ class CurrentMcpServer(
137149
outputStream = System.out.asSink().buffered()
138150
)
139151

140-
shutdownCoordinator?.addCleanupAction("Close MCP Server") {
141-
runBlocking { server.close() }
142-
}
143-
shutdownCoordinator?.addCleanupAction("Close Database") {
144-
databaseManager.shutdown()
145-
}
152+
registerCommonCleanup(server)
146153

147154
val done = Job()
148155
server.onClose {
@@ -176,11 +183,11 @@ class CurrentMcpServer(
176183
ktorServer.stop(gracePeriodMillis = 1000, timeoutMillis = 5000)
177184
done.complete()
178185
}
179-
shutdownCoordinator?.addCleanupAction("Close MCP Server") {
180-
runBlocking { server.close() }
181-
}
182-
shutdownCoordinator?.addCleanupAction("Close Database") {
183-
databaseManager.shutdown()
186+
registerCommonCleanup(server)
187+
188+
server.onClose {
189+
logger.info("Server closed")
190+
if (shutdownCoordinator == null) databaseManager.shutdown()
184191
}
185192

186193
if (shutdownCoordinator == null) {
@@ -203,7 +210,7 @@ class CurrentMcpServer(
203210
/**
204211
* Configures the MCP SDK server with capabilities for tools, prompts, and resources.
205212
*/
206-
private fun configureServer(serverName: String): Server {
213+
private fun configureServer(serverName: String, toolCount: Int, toolNames: String): Server {
207214
return Server(
208215
serverInfo = Implementation(
209216
name = serverName,
@@ -217,7 +224,7 @@ class CurrentMcpServer(
217224
logging = JsonObject(emptyMap())
218225
)
219226
),
220-
instructions = "Current (v3) MCP Task Orchestrator — 13 tools: manage_items, query_items, manage_notes, query_notes, manage_dependencies, query_dependencies, advance_item, get_next_status, get_next_item, get_blocked_items, complete_tree, create_work_tree, get_context"
227+
instructions = "Current (v3) MCP Task Orchestrator — $toolCount tools: $toolNames"
221228
)
222229
}
223230
}

0 commit comments

Comments
 (0)