Skip to content

Commit 5b7d0eb

Browse files
committed
refactor(devti): improve MCP server management and error handling
- Update client version to 1.0.0 - Replace ProcessBuilder with GeneralCommandLine for better cross-platform compatibility - Add logging for MCP command execution - Improve error handling by rethrowing exceptions
1 parent 04d54a3 commit 5b7d0eb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import kotlinx.coroutines.async
2626
import kotlinx.coroutines.awaitAll
2727
import kotlinx.coroutines.coroutineScope
2828
import kotlinx.coroutines.withTimeout
29+
import com.intellij.execution.configurations.GeneralCommandLine
2930

3031
@Service(Service.Level.PROJECT)
3132
class CustomMcpServerManager(val project: Project) {
@@ -46,13 +47,18 @@ class CustomMcpServerManager(val project: Project) {
4647
async {
4748
if (entry.value.disabled == true) return@async emptyList<Tool>()
4849
val resolvedCommand = resolveCommand(entry.value.command)
49-
val client = Client(clientInfo = Implementation(name = entry.key, version = "0.3.0"))
50-
val processBuilder = ProcessBuilder(resolvedCommand, *entry.value.args.toTypedArray())
51-
val process = processBuilder.start()
50+
logger<CustomMcpServerManager>().info("Found MCP command: $resolvedCommand")
51+
val client = Client(clientInfo = Implementation(name = entry.key, version = "1.0.0"))
52+
53+
// Replaced ProcessBuilder with GeneralCommandLine
54+
val cmd = GeneralCommandLine(resolvedCommand)
55+
cmd.addParameters(*entry.value.args.toTypedArray())
56+
57+
val process = cmd.createProcess()
5258
val input = process.inputStream.asSource().buffered()
5359
val output = process.outputStream.asSink().buffered()
5460
val transport = StdioClientTransport(input, output)
55-
61+
5662
try {
5763
client.connect(transport)
5864
val listTools = client.listTools()
@@ -61,6 +67,7 @@ class CustomMcpServerManager(val project: Project) {
6167
}
6268
listTools?.tools ?: emptyList()
6369
} catch (e: Exception) {
70+
throw e
6471
logger<CustomMcpServerManager>().warn("Failed to list tools from ${entry.key}: $e")
6572
emptyList<Tool>()
6673
}

0 commit comments

Comments
 (0)