Skip to content

Commit 4866eb8

Browse files
committed
refactor(devti): introduce JSON instance for efficient serialization
- Add a private val json instance with prettyPrint = true in CustomMcpServerManager - Replace the existing Json instance creation within the execute function - This change improves code readability and potentially enhances performance by reusing the same Json instance
1 parent 9a17d0d commit 4866eb8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

core/src/main/kotlin/cc/unitmesh/devti/mcp/client/CustomMcpServerManager.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class CustomMcpServerManager(val project: Project) {
7474
return toolsMap
7575
}
7676

77+
private val json = Json { prettyPrint = true }
78+
7779
fun execute(project: Project, tool: Tool, map: String): String {
7880
toolClientMap[tool]?.let {
7981
val future = CompletableFuture<String>()
@@ -90,7 +92,7 @@ class CustomMcpServerManager(val project: Project) {
9092
if (result?.content.isNullOrEmpty()) {
9193
future.complete("No result from tool ${tool.name}")
9294
} else {
93-
val result = Json { prettyPrint = true }.encodeToString(result.content)
95+
val result = json.encodeToString(result.content)
9496
val text = "Execute ${tool.name} tool's result\n"
9597
future.complete(text + result)
9698
}

0 commit comments

Comments
 (0)