Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions maestro-cli/src/main/java/maestro/cli/mcp/tools/TapOnTool.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,16 @@ object TapOnTool {
}
putJsonObject("text") {
put("type", "string")
put("description", "Text content to match (from 'text' field in inspect_ui output)")
put("description", "Regex matching the element text (anchored/full-match; use '.*foo.*' for partial). Often copied from the 'text' field of inspect_view_hierarchy output, but might also be 'accessibilityText' or 'hintText'")
}
putJsonObject("id") {
put("type", "string")
put("description", "Element ID to match (from 'id' field in inspect_ui output)")
put("description", "Regex matching the element ID (anchored/full-match; use '.*foo.*' for partial). Typically copied from the 'id' field of inspect_view_hierarchy output.")
}
putJsonObject("index") {
put("type", "integer")
put("description", "0-based index if multiple elements match the same criteria")
}
putJsonObject("use_fuzzy_matching") {
put("type", "boolean")
put("description", "Whether to use fuzzy/partial text matching (true, default) or exact regex matching (false)")
}
putJsonObject("enabled") {
put("type", "boolean")
put("description", "If true, only match enabled elements. If false, only match disabled elements. Omit this field to match regardless of enabled state.")
Expand All @@ -64,7 +60,6 @@ object TapOnTool {
val text = request.arguments["text"]?.jsonPrimitive?.content
val id = request.arguments["id"]?.jsonPrimitive?.content
val index = request.arguments["index"]?.jsonPrimitive?.intOrNull
val useFuzzyMatching = request.arguments["use_fuzzy_matching"]?.jsonPrimitive?.booleanOrNull ?: true
val enabled = request.arguments["enabled"]?.jsonPrimitive?.booleanOrNull
val checked = request.arguments["checked"]?.jsonPrimitive?.booleanOrNull
val focused = request.arguments["focused"]?.jsonPrimitive?.booleanOrNull
Expand Down Expand Up @@ -92,14 +87,9 @@ object TapOnTool {
deviceId = deviceId,
platform = null
) { session ->
// Escape special regex characters to prevent regex injection issues
fun escapeRegex(input: String): String {
return input.replace(Regex("[()\\[\\]{}+*?^$|.\\\\]")) { "\\${it.value}" }
}

val elementSelector = ElementSelector(
textRegex = if (useFuzzyMatching && text != null) ".*${escapeRegex(text)}.*" else text,
idRegex = if (useFuzzyMatching && id != null) ".*${escapeRegex(id)}.*" else id,
textRegex = text,
idRegex = id,
index = index?.toString(),
enabled = enabled,
checked = checked,
Expand Down
Loading