1
1
package cc.unitmesh.devti.mcp.ui
2
2
3
3
import cc.unitmesh.devti.mcp.client.CustomMcpServerManager
4
+ import cc.unitmesh.devti.mcp.client.MockDataGenerator
4
5
import com.intellij.openapi.project.Project
6
+ import com.intellij.openapi.ui.DialogWrapper
5
7
import com.intellij.ui.HyperlinkLabel
6
8
import com.intellij.ui.JBColor
7
9
import com.intellij.ui.components.JBLabel
10
+ import com.intellij.ui.components.JBScrollPane
8
11
import com.intellij.util.ui.JBUI
9
12
import com.intellij.util.ui.UIUtil
10
13
import io.modelcontextprotocol.kotlin.sdk.Tool
14
+ import kotlinx.serialization.encodeToString
15
+ import kotlinx.serialization.json.Json
11
16
import java.awt.BorderLayout
12
17
import java.awt.Dimension
13
18
import java.awt.FlowLayout
14
- import javax.swing.BorderFactory
15
- import javax.swing.JPanel
16
- import javax.swing.JTextPane
19
+ import javax.swing.*
17
20
import javax.swing.border.CompoundBorder
18
21
19
22
class McpToolListCardPanel (
@@ -91,8 +94,14 @@ class McpToolListCardPanel(
91
94
addHyperlinkListener { showToolDetails() }
92
95
}
93
96
94
- val linkWrapperPanel = JPanel (FlowLayout (FlowLayout .RIGHT , 0 , 0 )).apply {
97
+ val testLink = HyperlinkLabel (" Test" ).apply {
98
+ font = JBUI .Fonts .label(12.0f )
99
+ addHyperlinkListener { testTool() }
100
+ }
101
+
102
+ val linkWrapperPanel = JPanel (FlowLayout (FlowLayout .RIGHT , 4 , 0 )).apply {
95
103
background = UIUtil .getPanelBackground()
104
+ add(testLink)
96
105
add(detailsLink)
97
106
}
98
107
@@ -108,4 +117,59 @@ class McpToolListCardPanel(
108
117
val dialog = McpToolDetailDialog (project, serverName, tool, mcpServerManager)
109
118
dialog.show()
110
119
}
120
+
121
+ private fun testTool () {
122
+ val mockData = MockDataGenerator .generateMockData(tool.inputSchema)
123
+ val json = Json { prettyPrint = true }
124
+ val jsonContent = json.encodeToString(mockData)
125
+
126
+ val result = mcpServerManager.execute(project, tool, jsonContent)
127
+ val dialog = ToolTestResultDialog (project, tool, jsonContent, result)
128
+ dialog.show()
129
+ }
130
+
131
+ private class ToolTestResultDialog (
132
+ project : Project ,
133
+ private val tool : Tool ,
134
+ private val inputJson : String ,
135
+ private val result : String
136
+ ) : DialogWrapper(project) {
137
+
138
+ init {
139
+ title = " Test Result: ${tool.name} "
140
+ init ()
141
+ }
142
+
143
+ override fun createCenterPanel (): JComponent {
144
+ val panel = JPanel (BorderLayout (0 , 10 ))
145
+ panel.preferredSize = Dimension (600 , 400 )
146
+
147
+ val topPanel = JPanel (BorderLayout ())
148
+ topPanel.add(JLabel (" Input:" ), BorderLayout .NORTH )
149
+
150
+ val inputTextArea = JTextArea (inputJson).apply {
151
+ lineWrap = true
152
+ wrapStyleWord = true
153
+ isEditable = false
154
+ font = JBUI .Fonts .create(" Monospaced" , 12 )
155
+ }
156
+ topPanel.add(JBScrollPane (inputTextArea), BorderLayout .CENTER )
157
+
158
+ val bottomPanel = JPanel (BorderLayout ())
159
+ bottomPanel.add(JLabel (" Result:" ), BorderLayout .NORTH )
160
+
161
+ val resultTextArea = JTextArea (result).apply {
162
+ lineWrap = true
163
+ wrapStyleWord = true
164
+ isEditable = false
165
+ font = JBUI .Fonts .create(" Monospaced" , 12 )
166
+ }
167
+ bottomPanel.add(JBScrollPane (resultTextArea), BorderLayout .CENTER )
168
+
169
+ panel.add(topPanel, BorderLayout .NORTH )
170
+ panel.add(bottomPanel, BorderLayout .CENTER )
171
+
172
+ return panel
173
+ }
174
+ }
111
175
}
0 commit comments