override fun processStarted()

in src/main/kotlin/org/jetbrains/mcpserverplugin/general/builtinTools.kt [170:209]


                    override fun processStarted(descriptor: RunContentDescriptor?) {
                        if (descriptor == null) {
                            if (!future.isDone) {
                                future.completeExceptionally(
                                    ExecutionException("Run configuration doesn't support catching output")
                                )
                            }
                            return
                        }

                        val processHandler = descriptor.processHandler
                        if (processHandler == null) {
                            if (!future.isDone) {
                                future.completeExceptionally(
                                    IllegalStateException("Process handler is null even though RunContentDescriptor exists.")
                                )
                            }
                            return
                        }

                        processHandler.addProcessListener(object : ProcessAdapter() {
                            override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
                                synchronized(outputBuilder) {
                                    outputBuilder.append(event.text)
                                }
                            }

                            override fun processTerminated(event: ProcessEvent) {
                                val finalOutput = synchronized(outputBuilder) { outputBuilder.toString() }
                                future.complete(Pair(event.exitCode, finalOutput))
                            }

                            override fun processNotStarted() {
                                if (!future.isDone) {
                                    future.completeExceptionally(RuntimeException("Process explicitly reported as not started."))
                                }
                            }
                        })
                        processHandler.startNotify()
                    }