Skip to content

Commit 4a21e73

Browse files
committed
feat(mcp): implement PersistentStateComponent for McpConfigService to manage tool selections
1 parent c8f8a48 commit 4a21e73

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
11
package cc.unitmesh.devti.mcp.ui
22

33
import cc.unitmesh.devti.mcp.client.CustomMcpServerManager
4+
import com.intellij.openapi.components.PersistentStateComponent
45
import com.intellij.openapi.components.Service
6+
import com.intellij.openapi.components.State
7+
import com.intellij.openapi.components.Storage
58
import com.intellij.openapi.project.Project
69
import io.modelcontextprotocol.kotlin.sdk.Tool
710
import kotlinx.coroutines.Dispatchers
811
import kotlinx.coroutines.withContext
912

1013
@Service(Service.Level.PROJECT)
11-
class McpConfigService(private val project: Project) {
14+
@State(
15+
name = "cc.unitmesh.devti.mcp.ui.McpConfigService",
16+
storages = [Storage("AutoDevmcpConfig.xml")]
17+
)
18+
class McpConfigService(private val project: Project) : PersistentStateComponent<McpConfigService.State> {
1219
private val selectedTools = mutableMapOf<String, MutableSet<String>>()
20+
data class State(
21+
var toolSelections: Map<String, Set<String>> = emptyMap()
22+
)
1323

1424
companion object {
1525
fun getInstance(project: Project): McpConfigService {
1626
return project.getService(McpConfigService::class.java)
1727
}
1828
}
1929

30+
// Implement PersistentStateComponent methods
31+
override fun getState(): State {
32+
return State(selectedTools.mapValues { it.value.toSet() })
33+
}
34+
35+
override fun loadState(state: State) {
36+
selectedTools.clear()
37+
state.toolSelections.forEach { (server, tools) ->
38+
selectedTools[server] = tools.toMutableSet()
39+
}
40+
}
41+
2042
fun addSelectedTool(serverName: String, toolName: String) {
2143
selectedTools.getOrPut(serverName) { mutableSetOf() }.add(toolName)
2244
}
@@ -79,4 +101,4 @@ class McpConfigService(private val project: Project) {
79101
fun getSelectedToolsCount(): Int {
80102
return selectedTools.values.sumOf { it.size }
81103
}
82-
}
104+
}

0 commit comments

Comments
 (0)