Skip to content

Commit 1c4fb23

Browse files
committed
feat(mcp): enhance tool call message display #371
- Add toolName and parameters fields to McpMessage - Implement content parsing in companion object - Update UI to display tool info in separate sections - Improve tool call parsing from response
1 parent 56e9609 commit 1c4fb23

File tree

4 files changed

+85
-13
lines changed

4 files changed

+85
-13
lines changed

core/src/main/kotlin/cc/unitmesh/devti/mcp/ui/McpChatResultPanel.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,14 @@ class McpChatResultPanel(private val project: Project, val config: McpChatConfig
175175
"{}"
176176
}
177177

178+
val requestContent = "Tool: ${toolCall.name}\nParameters: $params"
178179
val requestMessage = McpMessage(
179180
type = MessageType.REQUEST,
180181
method = toolCall.name,
181182
timestamp = LocalDateTime.now(),
182-
content = "Tool: ${toolCall.name}\nParameters: $params"
183+
content = requestContent,
184+
toolName = toolCall.name,
185+
parameters = params
183186
)
184187
messageLogPanel.addMessage(requestMessage)
185188

@@ -317,11 +320,14 @@ class McpChatResultPanel(private val project: Project, val config: McpChatConfig
317320
}
318321

319322
// Log request message
323+
val requestContent = "Tool: ${toolCall.name}\nParameters: $params"
320324
val requestMessage = McpMessage(
321325
type = MessageType.REQUEST,
322326
method = toolCall.name,
323327
timestamp = LocalDateTime.now(),
324-
content = "Tool: ${toolCall.name}\nParameters: $params"
328+
content = requestContent,
329+
toolName = toolCall.name,
330+
parameters = params
325331
)
326332
messageLogPanel.addMessage(requestMessage)
327333

core/src/main/kotlin/cc/unitmesh/devti/mcp/ui/McpMessageLogPanel.kt

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cc.unitmesh.devti.mcp.ui
33
import cc.unitmesh.devti.mcp.ui.model.McpMessage
44
import cc.unitmesh.devti.mcp.ui.model.MessageType
55
import com.intellij.ui.JBColor
6+
import com.intellij.ui.components.JBLabel
67
import com.intellij.ui.components.JBScrollPane
78
import com.intellij.ui.table.JBTable
89
import com.intellij.util.ui.JBUI
@@ -27,20 +28,48 @@ class McpMessageLogPanel : JPanel(BorderLayout()) {
2728
autoCreateRowSorter = true
2829
}
2930

30-
private val detailTextArea = JTextArea().apply {
31+
private val toolNameLabel = JBLabel("Tool Name:").apply {
32+
font = font.deriveFont(java.awt.Font.BOLD)
33+
border = JBUI.Borders.empty(10, 10, 5, 10)
34+
}
35+
36+
private val toolNameTextArea = JTextArea().apply {
37+
isEditable = false
38+
wrapStyleWord = true
39+
lineWrap = true
40+
border = JBUI.Borders.empty(5, 10, 10, 10)
41+
}
42+
43+
private val parametersLabel = JBLabel("Parameters:").apply {
44+
font = font.deriveFont(java.awt.Font.BOLD)
45+
border = JBUI.Borders.empty(10, 10, 5, 10)
46+
}
47+
48+
private val parametersTextArea = JTextArea().apply {
3149
isEditable = false
3250
wrapStyleWord = true
3351
lineWrap = true
34-
border = JBUI.Borders.empty(10)
52+
border = JBUI.Borders.empty(5, 10, 10, 10)
3553
}
54+
55+
private val detailPanel = JPanel(BorderLayout()).apply {
56+
add(toolNameLabel, BorderLayout.NORTH)
57+
val centerPanel = JPanel(BorderLayout()).apply {
58+
add(toolNameTextArea, BorderLayout.NORTH)
59+
add(parametersLabel, BorderLayout.CENTER)
60+
add(parametersTextArea, BorderLayout.SOUTH)
61+
}
62+
add(centerPanel, BorderLayout.CENTER)
63+
}
64+
65+
private val detailScrollPane = JBScrollPane(detailPanel)
3666

3767
init {
3868
table.getColumnModel().getColumn(0).cellRenderer = TypeColumnRenderer()
3969

40-
// Create split pane
4170
val splitPane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT).apply {
4271
leftComponent = JBScrollPane(table)
43-
rightComponent = JBScrollPane(detailTextArea)
72+
rightComponent = detailScrollPane
4473
dividerLocation = 600
4574
resizeWeight = 0.5
4675
}
@@ -50,8 +79,20 @@ class McpMessageLogPanel : JPanel(BorderLayout()) {
5079
if (!e.valueIsAdjusting && table.selectedRow >= 0) {
5180
val selectedIndex = table.convertRowIndexToModel(table.selectedRow)
5281
if (selectedIndex >= 0 && selectedIndex < messages.size) {
53-
detailTextArea.text = messages[selectedIndex].content
54-
detailTextArea.caretPosition = 0
82+
val message = messages[selectedIndex]
83+
84+
// Parse content if toolName and parameters are not explicitly set
85+
val (toolName, params) = if (message.toolName != null && message.parameters != null) {
86+
Pair(message.toolName, message.parameters)
87+
} else {
88+
McpMessage.parseContent(message.content)
89+
}
90+
91+
toolNameTextArea.text = toolName ?: "N/A"
92+
toolNameTextArea.caretPosition = 0
93+
94+
parametersTextArea.text = params ?: "N/A"
95+
parametersTextArea.caretPosition = 0
5596
}
5697
}
5798
}
@@ -68,7 +109,8 @@ class McpMessageLogPanel : JPanel(BorderLayout()) {
68109
fun clear() {
69110
messages.clear()
70111
tableModel.fireTableDataChanged()
71-
detailTextArea.text = ""
112+
toolNameTextArea.text = ""
113+
parametersTextArea.text = ""
72114
}
73115

74116
private inner class MessageTableModel : DefaultTableModel() {

core/src/main/kotlin/cc/unitmesh/devti/mcp/ui/model/McpMessage.kt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,26 @@ data class McpMessage(
1212
val method: String,
1313
val timestamp: LocalDateTime,
1414
val duration: Long? = null,
15-
val content: String
16-
)
15+
val content: String,
16+
val toolName: String? = null,
17+
val parameters: String? = null
18+
) {
19+
companion object {
20+
fun parseContent(content: String): Pair<String?, String?> {
21+
val toolNamePrefix = "Tool: "
22+
val paramsPrefix = "Parameters: "
23+
24+
val toolName = content.lineSequence()
25+
.find { it.startsWith(toolNamePrefix) }
26+
?.substringAfter(toolNamePrefix)
27+
?.trim()
28+
29+
val params = content.lineSequence()
30+
.find { it.startsWith(paramsPrefix) }
31+
?.substringAfter(paramsPrefix)
32+
?.trim()
33+
34+
return Pair(toolName, params)
35+
}
36+
}
37+
}

core/src/main/kotlin/cc/unitmesh/devti/mcp/ui/model/ToolCall.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ data class ToolCall(
1414
fun fromString(response: String): List<ToolCall> {
1515
val toolCalls = mutableListOf<ToolCall>()
1616

17-
val codeblock = CodeFence.Companion.parse(response)
18-
if (codeblock.originLanguage != "xml") {
17+
val codeFences = CodeFence.Companion.parseAll(response)
18+
val codeblock = codeFences.firstOrNull {
19+
it.originLanguage == "xml"
20+
} ?: codeFences.firstOrNull()
21+
if (codeblock?.originLanguage != "xml") {
1922
return emptyList()
2023
}
2124

0 commit comments

Comments
 (0)