Skip to content

Commit 38abbf7

Browse files
committed
feat(core): add completion support for MCP tools and refactor related classes
- Add completion field to AgentTool class - Update McpFunctionProvider to include completion data - Refactor CustomMcpServerManager to use a single Client instance - Modify DevInsCompiler to use codeText() instead of text - Update ToolchainCommandCompletion to handle MCP tools differently
1 parent 7ce703c commit 38abbf7

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

core/src/main/kotlin/cc/unitmesh/devti/agent/tool/AgentTool.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import kotlinx.serialization.Serializable
77
data class AgentTool(
88
override val name: String, override val description: String,
99
val example: String,
10-
val isMcp: Boolean = false
10+
val isMcp: Boolean = false,
11+
val completion: String = "",
1112
) : Tool {
1213
override fun toString(): String {
1314
val string = if (description.isEmpty()) "" else """desc: $description"""

core/src/main/kotlin/cc/unitmesh/devti/mcp/client/CustomMcpServerManager.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@ class CustomMcpServerManager(val project: Project) {
4444
return@mapNotNull null
4545
}
4646

47-
val client = Client(
48-
clientInfo = Implementation(
49-
name = it.key,
50-
version = "1.0.0"
51-
)
52-
)
47+
val client = Client(clientInfo = Implementation(name = it.key, version = "1.0.0"))
5348

5449
val processBuilder = ProcessBuilder(it.value.command, *it.value.args.toTypedArray())
5550
val process = processBuilder.start()

core/src/main/kotlin/cc/unitmesh/devti/mcp/client/McpFunctionProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class McpFunctionProvider : ToolchainFunctionProvider {
2424
it.name,
2525
it.description ?: "",
2626
"Here is command and JSON schema\n/${it.name}\n```json\n$encodeToString\n```",
27-
isMcp = true
27+
isMcp = true,
28+
completion = encodeToString
2829
)
2930
}
3031
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ class DevInsCompiler(
347347
prop: String,
348348
provider: ToolchainFunctionProvider
349349
): PrintInsCommand {
350-
val codeContent: String? = lookupNextCode(used)?.text
350+
val codeContent: String? = lookupNextCode(used)?.codeText()
351351
val args = if (codeContent != null) {
352352
val code = CodeFence.parse(codeContent).text
353353
listOf(code)

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/provider/ToolchainCommandCompletion.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ class ToolchainCommandCompletion : CompletionProvider<CompletionParameters>() {
2424
}
2525

2626
private fun createCommandCompletionCandidate(tool: AgentTool): LookupElement {
27-
val icon = if (tool.isMcp) {
28-
AutoDevIcons.MCP
29-
} else {
30-
AutoDevIcons.TOOLCHAIN
27+
if (!tool.isMcp) {
28+
val element = LookupElementBuilder.create(tool.name).withIcon(AutoDevIcons.TOOLCHAIN)
29+
return PrioritizedLookupElement.withPriority(element, 98.0)
3130
}
3231

33-
return PrioritizedLookupElement.withPriority(LookupElementBuilder.create(tool.name).withIcon(icon), 98.0)
32+
val element = LookupElementBuilder.create(tool.name).withIcon(AutoDevIcons.MCP)
33+
.withTailText(tool.description)
34+
.withInsertHandler { context, _ ->
35+
context.editor.caretModel.moveToOffset(context.tailOffset)
36+
context.editor.document.insertString(context.tailOffset, tool.completion)
37+
}
38+
39+
return PrioritizedLookupElement.withPriority(element, 97.0)
3440
}
3541
}

0 commit comments

Comments
 (0)