[mcpServer] Drop list_available_actions, execute_action_by_id and wait

The actions are useless since they don't wait till action is complete, they can't interact with dialogs, they can't read output.

Wait is also useless since Client should get output when it's ready and it implements internal wait anyway.

GitOrigin-RevId: 14c218e7a70a48816c15d304d37a41f553a4cd86
This commit is contained in:
Maxim.Kolmakov
2025-07-01 16:44:58 +00:00
committed by intellij-monorepo-bot
parent 23a5b75360
commit ec210a9997
2 changed files with 0 additions and 132 deletions
@@ -12,21 +12,12 @@ import com.intellij.execution.runners.ProgramRunner
import com.intellij.execution.ui.RunContentDescriptor
import com.intellij.find.FindManager
import com.intellij.find.impl.FindInProjectUtil
import com.intellij.ide.DataManager
import com.intellij.mcpserver.McpServerBundle
import com.intellij.mcpserver.McpToolset
import com.intellij.mcpserver.annotations.McpDescription
import com.intellij.mcpserver.annotations.McpTool
import com.intellij.mcpserver.project
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.ActionUiKind
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.actionSystem.ex.ActionManagerEx
import com.intellij.openapi.actionSystem.impl.Utils
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.application.invokeAndWaitIfNeeded
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.progress.impl.CoreProgressManager
import com.intellij.openapi.project.guessProjectDir
@@ -253,73 +244,6 @@ class BuiltinGeneralToolset : McpToolset {
return dependencies.joinToString(",\n", prefix = "[", postfix = "]")
}
@McpTool
@McpDescription("""
Lists all available actions in JetBrains IDE editor.
Returns a JSON array of objects containing action information:
- id: The action ID
- text: The action presentation text
Use this tool to discover available actions for execution with execute_action_by_id.
""")
suspend fun list_available_actions(): String {
val project = coroutineContext.project
val actionManager = ActionManager.getInstance() as ActionManagerEx
val dataContext = invokeAndWaitIfNeeded {
DataManager.getInstance().getDataContext()
}
val actionIds = actionManager.getActionIdList("")
val presentationFactory = com.intellij.openapi.actionSystem.impl.PresentationFactory()
val visibleActions = invokeAndWaitIfNeeded {
Utils.expandActionGroup(
DefaultActionGroup(
actionIds.mapNotNull { actionManager.getAction(it) }
), presentationFactory, dataContext, "", ActionUiKind.NONE)
}
val availableActions = visibleActions.mapNotNull {
val presentation = presentationFactory.getPresentation(it)
val actionId = actionManager.getId(it)
if (presentation.isEnabledAndVisible && !presentation.text.isNullOrBlank()) {
"""{"id": "$actionId", "text": "${presentation.text.replace("\"", "\\\"")}"}"""
} else null
}
return availableActions.joinToString(",\n", prefix = "[", postfix = "]")
}
@McpTool
@McpDescription("""
Executes an action by its ID in JetBrains IDE editor.
Requires an actionId parameter containing the ID of the action to execute.
Returns one of two possible responses:
- "ok" if the action was successfully executed
- "action not found" if the action with the specified ID was not found
Note: This tool doesn't wait for the action to complete.
""")
suspend fun execute_action_by_id(
@McpDescription("ID of the action to execute")
actionId: String
): String {
val project = coroutineContext.project
val actionManager = ActionManager.getInstance()
val action = actionManager.getAction(actionId)
if (action == null) {
return "action not found"
}
ApplicationManager.getApplication().invokeLater({
val event = AnActionEvent.createFromAnAction(
action,
null,
"",
DataManager.getInstance().getDataContext()
)
action.actionPerformed(event)
}, ModalityState.nonModal())
return "ok"
}
@McpTool
@McpDescription("""
Retrieves the status of all running progress indicators in JetBrains IDE editor.
@@ -342,27 +266,4 @@ class BuiltinGeneralToolset : McpToolset {
return progressInfos.joinToString(",\n", prefix = "[", postfix = "]")
}
@McpTool
@McpDescription("""
Waits for a specified number of milliseconds (default: 5000ms = 5 seconds).
Optionally accepts a millisecond parameter to specify the wait duration.
Returns "ok" after the wait completes.
Use this tool when you need to pause before executing the next command.
""")
suspend fun wait(
@McpDescription("Number of milliseconds to wait (default: 5000)")
milliseconds: Long = 5000
): String {
val waitTime = if (milliseconds <= 0) 5000 else milliseconds
try {
TimeUnit.MILLISECONDS.sleep(waitTime)
} catch (e: InterruptedException) {
Thread.currentThread().interrupt()
return "Wait interrupted"
}
return "ok"
}
}
@@ -63,27 +63,6 @@ class BuiltinGeneralToolsetTest : McpToolsetTestBase() {
)
}
@Test
fun list_available_actions() = runBlocking {
testMcpTool(
BuiltinGeneralToolset::list_available_actions.name,
buildJsonObject {}
) {
assert(it.textContent.text?.contains(""""id": "About"""") == true) { "'About' action not found"}
}
}
@Test
fun execute_action_by_id() = runBlocking {
testMcpTool(
BuiltinGeneralToolset::execute_action_by_id.name,
buildJsonObject {
put("actionId", JsonPrimitive("SaveAll"))
},
"ok"
)
}
@Disabled("IMHO Useless tool. To remove")
@Test
fun get_progress_indicators() = runBlocking {
@@ -93,16 +72,4 @@ class BuiltinGeneralToolsetTest : McpToolsetTestBase() {
"[]"
)
}
@Test
@Disabled("Imho useless tool. To remove")
fun wait_tool() = runBlocking {
testMcpTool(
BuiltinGeneralToolset::wait.name,
buildJsonObject {
put("milliseconds", JsonPrimitive(100)) // Short wait for testing
},
"ok"
)
}
}