@@ -6,6 +6,7 @@ import cc.unitmesh.devti.custom.schema.CUSTOM_PROMPTS_FILE_NAME
6
6
import cc.unitmesh.devti.custom.schema.MCP_SERVERS_FILE_NAME
7
7
import cc.unitmesh.devti.fullHeight
8
8
import cc.unitmesh.devti.fullWidthCell
9
+ import cc.unitmesh.devti.mcp.client.CustomMcpServerManager
9
10
import cc.unitmesh.devti.provider.local.JsonTextProvider
10
11
import cc.unitmesh.devti.settings.locale.LanguageChangedCallback.componentStateChanged
11
12
import cc.unitmesh.devti.settings.locale.LanguageChangedCallback.jBLabel
@@ -16,7 +17,20 @@ import com.intellij.openapi.components.service
16
17
import com.intellij.openapi.options.BoundConfigurable
17
18
import com.intellij.openapi.project.Project
18
19
import com.intellij.openapi.ui.DialogPanel
19
- import com.intellij.ui.dsl.builder.*
20
+ import com.intellij.openapi.ui.DialogWrapper
21
+ import com.intellij.ui.components.JBLoadingPanel
22
+ import com.intellij.ui.dsl.builder.bindSelected
23
+ import com.intellij.ui.dsl.builder.panel
24
+ import com.intellij.ui.dsl.builder.toMutableProperty
25
+ import com.intellij.ui.table.JBTable
26
+ import io.modelcontextprotocol.kotlin.sdk.Tool
27
+ import kotlinx.coroutines.CoroutineScope
28
+ import kotlinx.coroutines.Dispatchers
29
+ import kotlinx.coroutines.launch
30
+ import kotlinx.coroutines.withContext
31
+ import java.awt.BorderLayout
32
+ import javax.swing.JComponent
33
+ import javax.swing.table.DefaultTableModel
20
34
21
35
class CustomizeConfigurable (val project : Project ) : BoundConfigurable(AutoDevBundle .message("customize.title")),
22
36
Disposable {
@@ -85,6 +99,11 @@ class CustomizeConfigurable(val project: Project) : BoundConfigurable(AutoDevBun
85
99
}
86
100
row {
87
101
cell(jBLabel(" counit.mcp.services.placeholder" , 1 ))
102
+
103
+ button(AutoDevBundle .message(" settings.autodev.coder.testConnectionButton.tips" )) {
104
+ val dialog = McpServicesTestDialog (project)
105
+ dialog.show()
106
+ }
88
107
}
89
108
90
109
row {
@@ -115,6 +134,64 @@ class CustomizeConfigurable(val project: Project) : BoundConfigurable(AutoDevBun
115
134
}
116
135
}
117
136
137
+ class McpServicesTestDialog (private val project : Project ) : DialogWrapper(project) {
138
+ private val loadingPanel = JBLoadingPanel (BorderLayout (), this .disposable)
139
+ private val tableModel = DefaultTableModel (arrayOf(" Server" , " Tool Name" , " Description" ), 0 )
140
+ private val table = JBTable (tableModel)
141
+
142
+ init {
143
+ title = " MCP Services Test Results"
144
+ init ()
145
+ loadServices()
146
+ }
147
+
148
+ override fun createCenterPanel (): JComponent {
149
+ loadingPanel.add(table, BorderLayout .CENTER )
150
+ loadingPanel.setLoadingText(" Loading MCP services..." )
151
+ return loadingPanel
152
+ }
153
+
154
+ private fun loadServices () {
155
+ loadingPanel.startLoading()
156
+
157
+ CoroutineScope (Dispatchers .IO ).launch {
158
+ try {
159
+ val serverManager = CustomMcpServerManager .instance(project)
160
+ val serverInfos = serverManager.collectServerInfos()
161
+
162
+ withContext(Dispatchers .IO ) {
163
+ updateTable(serverInfos)
164
+ loadingPanel.stopLoading()
165
+ }
166
+ } catch (e: Exception ) {
167
+ withContext(Dispatchers .IO ) {
168
+ tableModel.addRow(arrayOf(" Error" , e.message, " " ))
169
+ loadingPanel.stopLoading()
170
+ }
171
+ }
172
+ }
173
+ }
174
+
175
+ private fun updateTable (serverInfos : Map <String , List <Tool >>) {
176
+ tableModel.rowCount = 0
177
+
178
+ if (serverInfos.isEmpty()) {
179
+ tableModel.addRow(arrayOf(" No servers found" , " " , " " ))
180
+ return
181
+ }
182
+
183
+ serverInfos.forEach { (server, tools) ->
184
+ if (tools.isEmpty()) {
185
+ tableModel.addRow(arrayOf(server, " No tools found" , " " ))
186
+ } else {
187
+ tools.forEach { tool ->
188
+ tableModel.addRow(arrayOf(server, tool.name, tool.description))
189
+ }
190
+ }
191
+ }
192
+ }
193
+ }
194
+
118
195
override fun dispose () {
119
196
120
197
}
0 commit comments