autologin-mcp 以本機憑證協助 AI Agent 登入測試網站
Stop Pasting Passwords Into Your AI Coding Agent
olgay sezgin 開發並開源 autologin-mcp,讓 AI Agent 使用儲存在本機的憑證登入測試網站,密碼不會進入模型對話。工具以 bridge 模式或 Chrome 的 CDP 模式填寫登入表單,並只向設定檔所屬網站傳送憑證;用戶名稱和已登入工作階段仍會對 Agent 可見。
autologin-mcp is an open-source MCP server that logs your AI agent's browser tab into the app it is testing. The password stays on your machine and never reaches the model.
You ask Claude Code to test the checkout flow on staging. It opens Chrome, clicks through a few pages, and then the app shows a login form: the session has expired.
From there, the run goes one of two ways. The agent stops and waits for you, or it asks you for the password. Neither is what you wanted from an autonomous test run.
Every workaround leaks the password
The obvious fixes all put the password somewhere it does not belong.
- Paste it into the chat. Everything in the conversation is sent to the model provider. It stays in transcripts and logs, and it can resurface in context summaries.
-
Put it in a project
.envthe agent can read. Same problem: once the agent reads the file, the password is in the context. And a project.envhas a way of ending up in git. - Type it in yourself. That works, but you are now babysitting a run that was supposed to be autonomous. Long runs hit expired sessions more than once.
I wanted the agent to get past the login screen on its own, without the password ever entering the conversation. So I built autologin-mcp.
What autologin-mcp does
autologin-mcp is a small Model Context Protocol server with one job. When the tab under test shows a login form, a "session expired" message, a 401/403 or a redirect to a login page, the agent calls its login tool. The tab gets signed in with credentials stored on your machine, and the agent only sees the outcome.
You: "Test the checkout flow on staging"
Agent: ...navigates... the session has expired, the app shows a login form
Agent: calls autologin.login({ url }) <- no password in the request
autologin-mcp: returns a one-time script <- no password in the response
Agent: runs it in the tab -> { "status": "success" } <- the page got the password from your machine
Agent: continues the checkout test
The agent decides when to log in by itself. The server ships its own instructions with the tools, so even a fresh agent with no memory of your project calls login when it meets a login form, then carries on with its task. Besides login, the agent gets list_profiles (names, URLs and usernames, never passwords), login_status and open_config.
How the password stays out of the model
There are two ways to fill the form. In neither does the password pass through the agent.
Bridge mode is the default and needs no browser setup:
- The agent calls
login({ url }). - autologin-mcp returns a small loader script that contains only a one-time URL on
127.0.0.1, valid for 60 seconds. - The agent runs it in the tab with the JavaScript tool it already has.
- The loader fetches the filler from the local bridge, and the filler looks for the login form.
- Only when it is about to type does the page ask the bridge for the credentials. The bridge releases them only if the request's
Originheader belongs to the profile's site. Browsers set that header themselves; a page's scripts cannot fake it. - The filler fills the form, submits it, waits for the outcome and returns it:
success,submitted, orfailedwith the page's own error message.
The only hop that carries the password is step 5, from your machine straight to the page, and only to the profile's own site.
CDP mode kicks in when Chrome remote debugging is on (chrome://inspect/#remote-debugging, Chrome 144+). autologin-mcp connects to Chrome over the DevTools Protocol, finds the tab and fills it itself. The agent runs nothing.
In both modes the filler handles React, Vue and Angular inputs, forms that render late, identifier-first pages that ask for the email and then swap in the password field, and submit buttons in many languages.
It knows when to stop
Some logins need a person: single sign-on, passkeys, captchas, or a one-time code after the password. autologin-mcp recognises them and returns needs_human with a reason (sso, passkey, captcha, mfa_required) instead of failing or retrying, and the agent hands the login to you. Those pages never receive the credentials.
Three failed logins in five minutes pause the profile until you check the credentials, so an agent stuck in a loop cannot lock your test account.
The security model, and its limits
Several layers keep the password away from the model:
-
One global file. Credentials live in a single file in your home folder with permissions
600, outside every project, so they never end up in git. -
A guard hook.
installadds a Claude Code PreToolUse hook and deny rules that block the agent from reading the credentials folder, also in skip-permissions mode. - Redacted results. Every tool result and error is scrubbed of each configured password before the agent sees it.
- Origin lock. Credentials go only to pages on the profile's own site. A prompt-injected page on another site that asks the agent to "log in here" gets nothing.
-
One-time and loopback only. The bridge listens on
127.0.0.1, and each script works once, for 60 seconds.
The honest part: autologin-mcp prevents accidental exposure, not a deliberately hostile agent. The username and the logged-in session are visible to the agent; only the password is kept out. Use dedicated test accounts, never production credentials.
Getting started
You need Node.js 22.12+, Claude Code, and a browser tool for the agent, for example Claude in Chrome.
# 1. Register the MCP server, the skill and the guard hook in Claude Code
npx autologin-mcp install
# 2. Add a login profile. Run this in a normal terminal, not in the AI chat.
npx autologin-mcp add
# Profile name (e.g. staging): staging
# Root URL (e.g. example.com or localhost:3000): staging.example.com
# Username: qa@example.com
# Password (hidden):
Then restart Claude Code and test as usual. When the app asks for a login, the agent calls login by itself.
You can add as many profiles as you need, including several accounts for the same app (say admin and viewer). A profile only fills pages whose host matches its root URL, such as example.com, *.example.com or localhost:3000.
It works with the browser tool you already use
autologin-mcp does not replace your browser automation. The agent keeps its own browser tool; autologin-mcp only handles the login, then hands the tab back. The one-time loader comes in three forms, one per kind of tool:
-
Claude in Chrome runs the
scriptfield withjavascript_tool. This is the primary setup, tested end to end on real apps. -
Playwright MCP and chrome-devtools-mcp take the
functionfield withbrowser_evaluateandevaluate_script. -
Puppeteer takes the
expressionfield withpage.evaluate.
It also reaches beyond Claude Code:
-
Other agents.
npx autologin-mcp print-config --client codexprints the configuration for Codex CLI. It also knows Gemini CLI, Cursor, VS Code, Claude Desktop and Hermes Agent. The server is in the official MCP Registry asio.github.olgaysezgin/autologin-mcp. The guard hook is a Claude Code feature, so with other agents, deny the credentials folder in their own permission settings. -
Scripts and CI.
add --password-stdincreates a profile without any questions, reading the password from a pipe:
printf '%s' "$STAGING_PASSWORD" | npx autologin-mcp add staging \
--url staging.example.com --username qa@example.com --password-stdin -y
There is deliberately no --password <value> option, because it would leave the password in your shell history and the process list.
What building it taught me
The agent's JavaScript call often never comes back. In my Chrome profile, submitting any login form made another extension take over the tab, most likely a password manager offering to save the password. Claude in Chrome then failed with "Detached while handling command", although the login had worked. So the page also reports the outcome to the server, and a login_status tool hands it to the agent.
A memoryless agent has to find its own way. I ran five fresh Claude Code sessions (Opus, Sonnet and Haiku) on tasks that never mentioned logging in. All five called login on their own. The JavaScript call failed every time; four went straight to login_status, and one re-ran the script and got the first run's outcome. That is why the server's instructions spell out the whole recovery path.
"Run this script" means three different things. Claude in Chrome's javascript_tool supports top-level await but does not wait for a returned Promise. Puppeteer's page.evaluate waits for a Promise but has no top-level await, so it fails with "await is not defined". Playwright MCP wants a function. A friend hit the Puppeteer case in a real test, and that report became a release.
A good guard is annoying. The hook blocks any shell command that so much as mentions the credentials folder, including my own test commands while I was building this. That is exactly the point.
What's next
- TOTP codes, generated on your machine so the secret never reaches the page or the agent
- Logins that move between documents, and login forms inside iframes
- Opt-in auto-login in CDP mode, which watches a profile's URL and logs in without the agent asking
-
doctorandtest <profile>commands - Installers that write the configuration for Codex CLI, Gemini CLI and Cursor
autologin-mcp is free and MIT licensed. If it saves you a babysat test run, a star on GitHub helps other people find it. Issues and pull requests are welcome, especially reports from agents other than Claude Code.
- GitHub: github.com/olgaysezgin/autologin-mcp
- Website and docs: olgaysezgin.github.io/autologin-mcp
- npm: npmjs.com/package/autologin-mcp
來源:DEV Community · dev.to
