# Stop Pasting Passwords Into Your AI Coding Agent

> Source: <https://dev.to/olgay_sezgin_4cb2becaceb2/stop-pasting-passwords-into-your-ai-coding-agent-2pk2>
> Published: 2026-11-24 12:09:12+00:00

**Key takeaway:** An MCP server can keep credentials out of the model's context by having the agent call a login tool that returns a one-time script or a CDP form fill, with the password stored locally in a 600-permission file and the agent seeing only success, submitted or failed.

*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.

The obvious fixes all put the password somewhere it does not belong.

`.env` the agent can read.
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.

autologin-mcp is a small [Model Context Protocol](https://modelcontextprotocol.io) 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`.

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:

`login({ url })`.` 127.0.0.1`, valid for 60 seconds.` Origin` header belongs to the profile's site. Browsers set that header themselves; a page's scripts cannot fake it.`success`, `submitted`, or `failed` with 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.

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.

Several layers keep the password away from the model:

`600`, outside every project, so they never end up in git.` install` adds a Claude Code PreToolUse hook and deny rules that block the agent from reading the credentials folder, also in skip-permissions mode.
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.

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`.

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:

`script` field with `javascript_tool`. This is the primary setup, tested end to end on real apps.` function` field with `browser_evaluate` and `evaluate_script`.` expression` field with `page.evaluate`.
It also reaches beyond Claude Code:

`npx autologin-mcp print-config --client codex` prints 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 as `io.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.`add --password-stdin` creates 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.

**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.

`doctor` and `test <profile>` commands
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.
