feat(android): add mobile_logcat_dump mcp tool#257
feat(android): add mobile_logcat_dump mcp tool#257singhsume123 wants to merge 8 commits intomobile-next:mainfrom
Conversation
WalkthroughIntroduces a new logcat diagnostic tool for Android devices that enables dumping recent Android logcat entries with optional filtering by package name, buffers, priority levels, and regex patterns. The feature is integrated into the MCP server and includes comprehensive metadata in responses. Changes
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/android.ts`:
- Around line 595-602: Wrap each RegExp construction for opts.includeRegex and
opts.excludeRegex in a try-catch so invalid patterns don't crash the process:
when constructing new RegExp(opts.includeRegex) or new RegExp(opts.excludeRegex)
catch SyntaxError, log a clear user-facing message that includes the bad pattern
and error.message, and skip applying that particular filter (leave lines
unchanged) instead of letting the exception propagate; reference the existing
variables opts.includeRegex, opts.excludeRegex and lines when locating where to
add the try-catch.
In `@test/android.ts`:
- Around line 181-261: Remove the duplicated test blocks by deleting the second
copies of the two it(...) tests named "should be able to dump logcat for a
package" and "should support includeRegex / excludeRegex filtering in logcat
dump" (the repeated it(...) blocks starting after the first occurrences); keep
the original first instances (the initial it(...) with those exact names) and
remove the duplicated copies so each test appears only once in test/android.ts.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/android.ts`:
- Around line 642-657: The current fallback uses
this.silentAdb("shell","ps","-A") and finds a line with l.includes(packageName),
which can match partial package names; update the matching to require an exact
process name match (e.g., use a RegExp word-boundary match or compare the
process NAME column exactly to packageName) when selecting the line from
out.split("\n").find(...), and ensure you still parse PID from cols[1] only
after confirming the exact NAME match; use the existing silentAdb and
packageName symbols in the change.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/android.ts`:
- Around line 588-592: The client-side PID filter (using pidResolved,
pidFilterMode, pidRe and lines.filter) incorrectly assumes threadtime format and
can silently drop or mis-match lines; change the logic to only apply the
client-side filter when the log format is explicitly "threadtime" (reject or
skip filtering for "time", "brief", etc.), and implement a robust match for the
PID column instead of a loose /\s${pidResolved}\s/ regex — e.g. for threadtime
parse the whitespace-delimited columns (or target the PID column index) and
compare that column to pidResolved before keeping the line; ensure pidFilterMode
=== "client-side" still checks the format and falls back to no-op (or an
explicit error/warn) for non-threadtime formats.
|
Hey @singhsume123 Thank you for this pull request. We had such a PR in the past, and it didn't work. I will have to check it manually. When you use 2000 rows, does it work? I found that on real android devices 99% of the logs are just wifi and 5G signal logs, so it requires additional filtering. Can you share some prompts you have used this with? Thank you! 🚀 |
|
Hey @gmegidish , thanks for the review, you are correct. With 2000 lines, the output was ~52k tokens which exceeds the LLM's context limit. The tool returned successfully but the agent couldn't process the full output. I've pushed fixes:
Sample prompts tested: Prompt 1: Prompt 2: Prompt 3: For the noise issue you mentioned (wifi/5G logs), the tool supports filtering on multiple dimensions: Let me know what do you think ? |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@pinch_zoom_implementation_plan.md`:
- Around line 221-232: The fenced code block containing the touch script
starting with "d 0 300 800 50" and the separate example block that starts with
"Zoom in 2x on the center of a map:" are missing language identifiers and
trigger MD040; add an appropriate language tag (e.g., ```text or ```bash for the
touch script block and ```markdown for the explanatory example) immediately
after each opening triple-backtick so both fenced blocks include a language
identifier.
In `@src/android.ts`:
- Around line 14-18: Update the documentation comment for the
LogcatDumpOptions.lines field to reflect the actual enforced maximum (500)
instead of 2000 so users aren't misled; locate the LogcatDumpOptions interface
and change the comment on the lines property (currently "default 200, max 2000")
to state "default 200, max 500" (or similar) to match the clampInt behavior used
when parsing/validating lines.
- Around line 565-603: The code may set pidFilterMode = "client-side" even when
client-side filtering is skipped for non-"threadtime" formats; update the logic
around pidFilterMode (the variable used alongside pidResolved and format in the
conditional that performs client-side filtering) so that when format !==
"threadtime" and you skip filtering you change pidFilterMode to "none" (or a new
explicit "skipped" state) before returning/continuing, and ensure any downstream
uses of pidFilterMode reflect that change; modify the branch that currently only
logs the warning to also set pidFilterMode = "none" (or "skipped") to accurately
represent that no PID filtering was applied.
🧹 Nitpick comments (1)
src/Untitled (1)
1-1: Remove stray placeholder file.
A single-word file insrc/provides no functional value and may confuse tooling or reviewers. If this isn’t intentional, please delete it.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/android.ts`:
- Around line 90-93: The truncateText implementation slices the original text to
maxChars and then appends the truncation message, which can exceed the hard
limit; modify truncateText to reserve space for the truncation suffix (the
literal "[OUTPUT TRUNCATED - Use packageName, minPriority, includeRegex, or
excludeRegex filters to reduce output]\n\n") and if maxChars is smaller than the
suffix length, return a truncated suffix clipped to fit; ensure the returned
string length is always <= maxChars and that the function still returns
truncated: true when any truncation occurs.
|
Also happy to contribute to roadmap items. Happy to do non urgent requests if there are any |
|
Hey @gmegidish , I thought about this more and wanted to share a use case that I think really shows the value here. Consider Jetpack Compose recomposition debugging. A developer adds That's the general pattern: devs instrument their code with specific log tags, and the agent filters on those tags to get signal instead of noise. The |
What
Adds a new Android-only MCP tool:
mobile_logcat_dump, which allows agents to fetch recent logcat output for debugging mobile automation runs.Why
When UI automation fails (taps ignored, deep links not handled, permission issues, crashes), there is currently no observability. Logcat provides the missing signal needed to diagnose these failures.
Features
logcat --pidwhen supported, with safe client-side fallbackmain,crash,system)I,W,E, etc.)Tests
Also did some manual testing with running prompts . Attaching Screen shots for the same
Prompt 1
Prompt 2

Notes
Summary by CodeRabbit
New Features
Documentation