| name | login-cdp |
| description | Use when user says "login", "登录", "fix expired sessions", "refresh login", or needs to re-authenticate CDP browser sessions for any platform. Auto-detects expired platforms and guides interactive re-login via MCP browser tools. Triggers: "login", "登录", "CDP login", "refresh login", "expired session", "re-authenticate" |
CDP Platform Login
Auto-detect expired CDP browser sessions and re-authenticate interactively via MCP browser tools. Supports multiple CDP ports for multi-account setups.
When to Use
- Sessions on RedNote, Twitter, LinkedIn, Weibo, etc. have expired and need re-login
- Multi-account CDP setup needs re-authentication on a specific port (9222 vs 9223)
- Chrome MCP / Playwright MCP returns login pages instead of expected content
- User asks to "login", "登录", or "refresh sessions" before running a scraping/posting workflow
Prerequisites
- Chrome running with
--remote-debugging-port=<port>
- MCP browser tools available (Playwright MCP or Chrome MCP)
CDP Port Configuration
Two CDP ports, two independent Chrome instances, each with its own login sessions:
| Port | Account | Session Directory | Purpose |
|---|
| 9222 | Account 1 (default) | $HOME/chrome-debug-v2 | General browsing, Twitter scraping, posting |
| 9223 | Account 2 | $HOME/chrome-debug2 | RedNote publishing (secondary account) |
Startup commands:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
--remote-debugging-port=9222 \
--user-data-dir="$HOME/chrome-debug-v2"
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
--remote-debugging-port=9223 \
--user-data-dir="$HOME/chrome-debug2"
Quick check:
curl -s --noproxy '*' http://127.0.0.1:9222/json/version
curl -s --noproxy '*' http://127.0.0.1:9223/json/version
ps aux | grep "[G]oogle Chrome" | grep -v "Helper\|GPU\|Renderer" | grep -o 'user-data-dir=[^ ]*'
Arguments
| Arg | Default | Description |
|---|
--port | 9222 | CDP port to check/fix |
| platform names | rednote, twitter | Comma-separated or space-separated platform names |
Examples:
/login-cdp — check rednote + twitter on port 9222
/login-cdp twitter — check only twitter
/login-cdp --port 9223 rednote — check rednote on port 9223
Flow
Step 0: Verify CDP is Running
curl -s --noproxy '*' http://127.0.0.1:<port>/json/version
If connection refused → print the exact Chrome startup command as a fenced bash block for the user to paste into their own terminal, then STOP. Do NOT try to run it yourself — Chrome must be launched from the user's shell so it stays attached to their session.
Format the output like this (fill in the port/profile that matches the request):
CDP <port> is not running. Paste this into your terminal:
```bash
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
--remote-debugging-port=<port> \
--user-data-dir="$HOME/<profile-dir>"
```
Then re-run /login-cdp.
Port → profile mapping: 9222 → chrome-debug-v2, 9223 → chrome-debug2.
If CDP is reachable, also check which --user-data-dir is being used:
ps aux | grep "[G]oogle Chrome" | grep -v "Helper\|GPU\|Renderer\|Utility\|Plugin" | grep -o 'user-data-dir=[^ ]*'
Report: "CDP running, profile: "
Step 1: Detect Expired Sessions
Check login status by navigating to each platform's check URL.
For each platform:
- Navigate to the platform's
check_url via MCP browser tools
- Take a screenshot or snapshot
- If redirected to a login page (URL contains "login", "flow/login", or page shows sign-in form) → expired
- If page shows logged-in content (dashboard, feed, profile, account name) → healthy
- Close the tab immediately after checking
If all healthy → "All platforms healthy, nothing to do." → STOP.
Step 2: Present Expired Platforms
CDP <port> (<user-data-dir>)
Expired sessions:
1. RedNote Creator — expired
2. Twitter/X — expired
Healthy:
✓ (none)
Which to fix? (e.g., "1,2" or "all")
Step 3: Sequential Login Loop
For each selected platform:
a) Open login page via MCP browser tools.
b) Notify user:
- "Opened [platform] login page in Chrome (CDP ). Please log in, then say 'done'."
- For QR-code platforms: add "Requires QR code scanning — check your Chrome window."
c) Wait for user to say "done", "ok", or "next".
d) Verify — navigate to check_url again, confirm logged-in state.
e) Handle failure — "Still not logged in. Try again or skip?"
f) Close tab — ALWAYS close after each platform.
Step 4: Summary
Login refresh complete (CDP <port>):
✓ RedNote Creator — logged in
✗ Twitter/X — still expired
Platform Reference
MCP Tool Selection
This skill works with either MCP browser tool:
- Chrome MCP (
chrome-devtools-mcp) — connects to existing CDP Chrome via --browserUrl
- Playwright MCP (
@playwright/mcp) — needs --cdp-endpoint to connect to existing Chrome
Prefer whichever is configured to connect to the target CDP port. If both available, use Chrome MCP (it connects to CDP by default).
Key Rules
- Always verify CDP is running first (Step 0) — don't assume
- Never launch Chrome yourself — if CDP is down, print the startup command as a copy-paste bash block and stop. The user runs it in their own terminal.
- Report the user-data-dir — so user knows which Chrome profile is being checked
- No hardcoded selectors — read snapshots/screenshots to identify login state
- Always close tabs — CDP tabs accumulate
- Sequential only — one platform at a time
- Use
--noproxy '*' for all curl commands to localhost — machine may have proxy configured
Anti-Patterns
| Anti-Pattern | What goes wrong | Fix |
|---|
| Launching Chrome via the assistant's own Bash | Chrome detaches from user's terminal session, may not pick up keychain/GUI | Print the startup command and stop; user pastes into their own terminal |
| Skipping Step 0 (CDP reachability check) | Later MCP calls fail with cryptic errors | Always curl http://127.0.0.1:<port>/json/version first |
| Hardcoding DOM selectors to detect login state | Selectors break on every platform UI update | Use snapshot/screenshot heuristics (URL + visible text) |
| Leaving check tabs open | Tabs accumulate, slowing CDP and leaking state | Close after every check (Step 1 step 5, Step 3 step f) |
| Parallel login across platforms | User can only authenticate in one tab at a time, QR codes overlap | Sequential loop only |
Curl to localhost without --noproxy '*' | System proxy intercepts loopback, false negatives | Add --noproxy '*' to every loopback curl |
| Silently falling back to WebFetch when CDP is down | Hides the real failure; scrapes wrong (logged-out) view | Stop and surface the failure; print startup command |
See Also
tmux — Companion shell setup; tmux pane is where the user pastes the Chrome startup command
claude-code-config — Global Chrome CDP configuration (ports, profiles)
github-cli — Authenticate gh in a similar interactive way for GitHub flows
fail-fast-ml-engineering — Same "no silent fallbacks" discipline applied here (fail loudly when CDP is down)