autologin-mcp 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -7
- package/dist/bridge/filler.js +7 -1
- package/dist/bridge/server.js +2 -2
- package/dist/cli.js +121 -22
- package/dist/clients.js +61 -0
- package/dist/opener.js +28 -4
- package/dist/serve.js +1 -1
- package/dist/server.js +10 -2
- package/dist/templates.js +1 -1
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
|
|
12
12
|
<p align="center">
|
|
13
13
|
<a href="https://github.com/olgaysezgin/autologin-mcp/actions/workflows/ci.yml"><img src="https://github.com/olgaysezgin/autologin-mcp/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
14
|
-
<a href="https://www.npmjs.com/package/autologin-mcp"><img src="https://img.shields.io/npm/v/autologin-mcp" alt="npm"></a>
|
|
14
|
+
<a href="https://www.npmjs.com/package/autologin-mcp"><img src="https://img.shields.io/npm/v/autologin-mcp" alt="npm version"></a>
|
|
15
|
+
<a href="https://www.npmjs.com/package/autologin-mcp"><img src="https://img.shields.io/npm/dm/autologin-mcp" alt="npm downloads per month"></a>
|
|
16
|
+
<a href="https://nodejs.org"><img src="https://img.shields.io/node/v/autologin-mcp" alt="Node.js version"></a>
|
|
15
17
|
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>
|
|
16
18
|
<a href="https://olgaysezgin.github.io/autologin-mcp/"><img src="https://img.shields.io/badge/docs-website-4338ca" alt="Documentation website"></a>
|
|
17
19
|
</p>
|
|
@@ -20,7 +22,12 @@
|
|
|
20
22
|
<a href="https://olgaysezgin.github.io/autologin-mcp/">Website</a> ·
|
|
21
23
|
<a href="#quick-use">Quick use</a> ·
|
|
22
24
|
<a href="docs/README.md">Documentation</a> ·
|
|
23
|
-
<a href="#faq">FAQ</a>
|
|
25
|
+
<a href="#faq">FAQ</a> ·
|
|
26
|
+
<a href="CHANGELOG.md">Changelog</a>
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
<p align="center">
|
|
30
|
+
<img src="docs/assets/demo.gif" width="860" alt="Demo: Claude Code finds an expired session while testing a web app, calls the autologin-mcp login tool, runs the one-time script in Chrome, gets success and continues. The password never appears in the chat.">
|
|
24
31
|
</p>
|
|
25
32
|
|
|
26
33
|
**autologin-mcp** is an open-source [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server that lets AI coding agents such as **Claude Code** log in to the web app they are testing. When the agent's browser tab shows a login form, a "session expired" message, a 401/403 or a redirect to a login page, the agent calls the `login` tool, and autologin-mcp fills the form with credentials stored on your machine. The username and password never appear in the conversation, so they never reach the model. It works with **Claude in Chrome**, **Playwright MCP** and **chrome-devtools-mcp**, and needs no browser setup.
|
|
@@ -55,6 +62,20 @@ npx autologin-mcp add
|
|
|
55
62
|
|
|
56
63
|
Upgrade with `npx autologin-mcp@latest install`, remove with `npx autologin-mcp uninstall`. Step-by-step guide: [Getting started](docs/getting-started.md).
|
|
57
64
|
|
|
65
|
+
Another agent? `npx autologin-mcp print-config --client codex` (or `gemini`, `cursor`, `vscode`, `claude-desktop`, `hermes`) prints its configuration. See [Agents and browser tools](docs/clients.md).
|
|
66
|
+
|
|
67
|
+
## Features
|
|
68
|
+
|
|
69
|
+
- **Logs in when the agent needs it.** The agent calls `login` when the page shows a login form, a "session expired" message, a 401/403 or a redirect to a login URL, then carries on with its task.
|
|
70
|
+
- **The password never enters the chat.** Credentials go from a file on your machine straight into the page. Tool results are scrubbed of passwords, and a guard hook keeps the agent away from the credentials folder.
|
|
71
|
+
- **No browser setup.** Bridge mode uses the JavaScript tool the agent already has. Turn on Chrome remote debugging and CDP mode fills the tab itself.
|
|
72
|
+
- **Locked to your app's origin.** Credentials are released only to the site of the profile, so a prompt-injected page on another site gets nothing.
|
|
73
|
+
- **Real-world forms.** React, Vue and Angular inputs, forms that render late, submit buttons in many languages, and the page's own error message when a login fails.
|
|
74
|
+
- **No account lockouts.** Three failed logins in five minutes pause the profile until you check the credentials.
|
|
75
|
+
- **Several accounts and apps.** One global credentials file outside your projects, with as many profiles as you need.
|
|
76
|
+
- **One command to install.** `npx autologin-mcp install` registers the MCP server, the skill and the guard hook in Claude Code.
|
|
77
|
+
- **Other agents and CI.** `print-config` prints the setup for Codex CLI, Gemini CLI, Cursor, VS Code, Claude Desktop and Hermes Agent, and `add --password-stdin` creates profiles in scripts and CI.
|
|
78
|
+
|
|
58
79
|
## Why
|
|
59
80
|
|
|
60
81
|
- **Sessions expire in the middle of long agent runs.** The agent stops, or asks you for the password.
|
|
@@ -69,7 +90,7 @@ The full documentation is in [`docs/`](docs/README.md) and on the [website](http
|
|
|
69
90
|
|
|
70
91
|
### How it works
|
|
71
92
|
|
|
72
|
-
- **Bridge mode (default, zero setup).** `login` returns a one-time loader script containing only a 60-second URL on `127.0.0.1`. The agent runs it in the tab with the JavaScript tool it already has (`javascript_tool`, `browser_evaluate` or `
|
|
93
|
+
- **Bridge mode (default, zero setup).** `login` returns a one-time loader script containing only a 60-second URL on `127.0.0.1`. The agent runs it in the tab with the JavaScript tool it already has (`javascript_tool`, `browser_evaluate`, `evaluate_script` or Puppeteer's `page.evaluate`). The page then fetches the credentials from your machine, and they are released only if the page's browser-set `Origin` header belongs to the profile's site.
|
|
73
94
|
- **CDP mode (automatic when Chrome remote debugging is on).** autologin-mcp connects to Chrome over the DevTools Protocol and fills the tab itself; the agent runs nothing.
|
|
74
95
|
- The filler works with React, Vue and Angular forms, waits for the outcome, and returns `success`, `submitted`, or `failed` with the page's error message.
|
|
75
96
|
|
|
@@ -97,9 +118,9 @@ A profile only fills pages whose host matches its root URL (`example.com`, `*.ex
|
|
|
97
118
|
| Tool | What the agent gets back |
|
|
98
119
|
|---|---|
|
|
99
120
|
| `list_profiles` | Profile name, root URL and username for each profile. Never passwords. |
|
|
100
|
-
| `login({ url?, profile? })` | Bridge mode: `run_in_page` with a one-time `script
|
|
121
|
+
| `login({ url?, profile? })` | Bridge mode: `run_in_page` with a one-time loader to run in the tab, as `script`, `function` or `expression` for the agent's browser tool. CDP mode: the result directly (`success`, `submitted`, `failed`, `no_login_form`, `rate_limited`, …). |
|
|
101
122
|
| `login_status({ profile? })` | The latest outcome per profile, for when the agent's JavaScript call was cut off. |
|
|
102
|
-
| `open_config` | Opens the credentials file in your editor. The content is never returned. |
|
|
123
|
+
| `open_config` | Opens the credentials file in your editor, or returns its path where there is no desktop. The content is never returned. |
|
|
103
124
|
|
|
104
125
|
More: [MCP tools](docs/mcp-tools.md) and [CLI reference](docs/cli.md).
|
|
105
126
|
|
|
@@ -114,7 +135,8 @@ A Claude Code guard hook and deny rules block the agent from reading the credent
|
|
|
114
135
|
| Claude Code + Claude in Chrome | Supported and tested end to end |
|
|
115
136
|
| Claude Code + Playwright MCP | Supported (`browser_evaluate`, or CDP with a shared browser) |
|
|
116
137
|
| Claude Code + chrome-devtools-mcp | Supported (`evaluate_script`, or CDP with a shared browser) |
|
|
117
|
-
|
|
|
138
|
+
| Puppeteer-based browser tools | Supported (`expression` with `page.evaluate`, or CDP with a shared browser) |
|
|
139
|
+
| Codex CLI, Gemini CLI, Cursor, VS Code, Claude Desktop, Hermes Agent | The stdio server runs, and `print-config` prints the setup; installer, skill and guard hook are Claude Code only. Not tested yet |
|
|
118
140
|
|
|
119
141
|
More: [Agents and browser tools](docs/clients.md) and [Troubleshooting](docs/troubleshooting.md).
|
|
120
142
|
|
|
@@ -143,7 +165,7 @@ More questions: [FAQ](docs/faq.md).
|
|
|
143
165
|
- [ ] Multi-step logins (username → next → password), iframes, SSO login hosts
|
|
144
166
|
- [ ] TOTP codes
|
|
145
167
|
- [ ] `doctor` and `test <profile>` commands
|
|
146
|
-
- [ ] Installers for Codex CLI, Gemini CLI and Cursor; a Claude Code plugin
|
|
168
|
+
- [ ] Installers that write the config for Codex CLI, Gemini CLI and Cursor (`print-config` prints it today); a Claude Code plugin
|
|
147
169
|
|
|
148
170
|
## Development
|
|
149
171
|
|
|
@@ -156,6 +178,10 @@ npm run build && npm run smoke
|
|
|
156
178
|
|
|
157
179
|
The end-to-end tests start a throwaway headless Chrome (set `CHROME_PATH` if Chrome is not in a standard location). See [CONTRIBUTING.md](CONTRIBUTING.md). Security reports: [SECURITY.md](SECURITY.md).
|
|
158
180
|
|
|
181
|
+
## Releases
|
|
182
|
+
|
|
183
|
+
Every release has the same version in `package.json`, the git tag, npm and the [GitHub release](https://github.com/olgaysezgin/autologin-mcp/releases). See [CHANGELOG.md](CHANGELOG.md) for what changed in each version.
|
|
184
|
+
|
|
159
185
|
## License
|
|
160
186
|
|
|
161
187
|
[MIT](LICENSE) © Olgay Sezgin
|
package/dist/bridge/filler.js
CHANGED
|
@@ -128,5 +128,11 @@ export function agentFunction(base, token) {
|
|
|
128
128
|
"s.onerror = () => done({ status: 'error', hint: 'The page blocked the autologin-mcp bridge (Content-Security-Policy?) or the MCP server stopped' }); " +
|
|
129
129
|
'(document.head || document.documentElement).append(s); })');
|
|
130
130
|
}
|
|
131
|
-
/** Expression form, for REPL-style tools such as Claude in Chrome's javascript_tool. */
|
|
131
|
+
/** Expression form with top-level await, for REPL-style tools such as Claude in Chrome's javascript_tool. */
|
|
132
132
|
export const agentScript = (fn) => `await (${fn})()`;
|
|
133
|
+
/**
|
|
134
|
+
* Expression form without top-level await: it evaluates to a Promise of the result, for tools that
|
|
135
|
+
* evaluate a plain script and wait for its value (Puppeteer page.evaluate, CDP Runtime.evaluate with awaitPromise).
|
|
136
|
+
* There, `await (...)()` fails with "await is not defined".
|
|
137
|
+
*/
|
|
138
|
+
export const agentExpression = (fn) => `(${fn})()`;
|
package/dist/bridge/server.js
CHANGED
|
@@ -2,7 +2,7 @@ import { randomBytes } from 'node:crypto';
|
|
|
2
2
|
import http from 'node:http';
|
|
3
3
|
import { FailureLimiter } from '../ratelimit.js';
|
|
4
4
|
import { matchesUrl } from '../store/match.js';
|
|
5
|
-
import { agentFunction, agentScript, fillerScript } from './filler.js';
|
|
5
|
+
import { agentExpression, agentFunction, agentScript, fillerScript } from './filler.js';
|
|
6
6
|
export const BRIDGE_TIMING = { detectTimeoutMs: 5_000, verifyTimeoutMs: 10_000, pollMs: 250, earlyFailAfterMs: 1_500 };
|
|
7
7
|
const TOKEN_PATH = /^\/v1\/(filler|credentials|result)\/([A-Za-z0-9_-]{16,})(?:\.js)?$/;
|
|
8
8
|
const MAX_BODY = 8_192;
|
|
@@ -65,7 +65,7 @@ export class BridgeServer {
|
|
|
65
65
|
const token = randomBytes(24).toString('base64url');
|
|
66
66
|
this.tickets.set(token, { profile, expiresAt: now + this.ttlMs, released: false, result: null, waiters: [] });
|
|
67
67
|
const fn = agentFunction(base, token);
|
|
68
|
-
return { profile: profile.name, expiresInSeconds: Math.round(this.ttlMs / 1000), function: fn, script: agentScript(fn) };
|
|
68
|
+
return { profile: profile.name, expiresInSeconds: Math.round(this.ttlMs / 1000), function: fn, script: agentScript(fn), expression: agentExpression(fn) };
|
|
69
69
|
}
|
|
70
70
|
async handle(req, res) {
|
|
71
71
|
const { base } = await this.listen();
|
package/dist/cli.js
CHANGED
|
@@ -3,6 +3,7 @@ import { existsSync } from 'node:fs';
|
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { clientConfig, CLIENTS } from './clients.js';
|
|
6
7
|
import { createExec } from './exec.js';
|
|
7
8
|
import { install, uninstall } from './installer.js';
|
|
8
9
|
import { openDetached, openInEditor } from './opener.js';
|
|
@@ -23,18 +24,24 @@ Usage:
|
|
|
23
24
|
(--package: what npx runs, e.g. a local .tgz to test a build)
|
|
24
25
|
npx autologin-mcp uninstall [-y] [--dry-run] [--purge]
|
|
25
26
|
Undo install (--purge also deletes your credentials file)
|
|
26
|
-
npx autologin-mcp add [name] [--url <root-url>] [--username <user>]
|
|
27
|
+
npx autologin-mcp add [name] [--url <root-url>] [--username <user>] [-y]
|
|
27
28
|
Add or replace a login profile (the password is asked hidden)
|
|
29
|
+
npx autologin-mcp add <name> --url <root-url> --username <user> --password-stdin [-y]
|
|
30
|
+
Same, with the password piped in (scripts, CI)
|
|
28
31
|
npx autologin-mcp list List profiles (passwords are never shown)
|
|
29
32
|
npx autologin-mcp remove <name> [-y] Delete a profile
|
|
30
33
|
npx autologin-mcp edit Open the credentials file in $VISUAL / $EDITOR or the default editor
|
|
34
|
+
npx autologin-mcp print-config [--client <name>] [--package <spec>]
|
|
35
|
+
Print the MCP server config for another agent: json (default),
|
|
36
|
+
claude-desktop, cursor, vscode, gemini, codex or hermes
|
|
31
37
|
npx autologin-mcp --version | --help
|
|
32
38
|
|
|
33
39
|
Credentials file: ~/.autologin-mcp/credentials.env (override the folder with AUTOLOGIN_HOME).
|
|
34
40
|
Run add/edit in a separate terminal, never inside an AI chat.
|
|
35
41
|
`;
|
|
42
|
+
export const NO_PASSWORD_FLAG = '--password is not supported: it would leave the password in your shell history and the process list. Pipe it in with --password-stdin instead.';
|
|
36
43
|
export function parseArgs(argv) {
|
|
37
|
-
const flags = { yes: false, dryRun: false, purge: false, help: false, version: false };
|
|
44
|
+
const flags = { yes: false, dryRun: false, purge: false, help: false, version: false, passwordStdin: false };
|
|
38
45
|
const positionals = [];
|
|
39
46
|
for (let i = 0; i < argv.length; i += 1) {
|
|
40
47
|
const arg = argv[i];
|
|
@@ -49,7 +56,11 @@ export function parseArgs(argv) {
|
|
|
49
56
|
flags.help = true;
|
|
50
57
|
else if (name === '-v' || name === '--version')
|
|
51
58
|
flags.version = true;
|
|
52
|
-
else if (name === '--
|
|
59
|
+
else if (name === '--password-stdin')
|
|
60
|
+
flags.passwordStdin = true;
|
|
61
|
+
else if (name === '--password')
|
|
62
|
+
throw new Error(NO_PASSWORD_FLAG);
|
|
63
|
+
else if (name === '--url' || name === '--username' || name === '--package' || name === '--client') {
|
|
53
64
|
const value = inline ?? argv[++i];
|
|
54
65
|
if (value === undefined)
|
|
55
66
|
throw new Error(`${name} needs a value`);
|
|
@@ -86,21 +97,79 @@ async function confirmAction(ctx, yes, question) {
|
|
|
86
97
|
function credentialsFile(ctx) {
|
|
87
98
|
return credentialsPath(resolveConfigDir(ctx.env, ctx.home));
|
|
88
99
|
}
|
|
100
|
+
const invalidName = (name) => PROFILE_NAME_RE.test(name) && !name.toUpperCase().startsWith(SETTINGS_PREFIX)
|
|
101
|
+
? null
|
|
102
|
+
: `Invalid profile name "${name}": use letters, digits and _ (not starting with ${SETTINGS_PREFIX.toLowerCase()}).`;
|
|
103
|
+
/** Writes the profile, replacing an existing one with the same name. Returns an error message or null. */
|
|
104
|
+
async function saveProfile(ctx, file, profile, exists) {
|
|
105
|
+
let block;
|
|
106
|
+
try {
|
|
107
|
+
block = renderProfile(profile);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
return error.message;
|
|
111
|
+
}
|
|
112
|
+
const current = (await readText(file)) ?? ENV_TEMPLATE;
|
|
113
|
+
const base = exists ? removeProfile(current, profile.name).text : current;
|
|
114
|
+
await writeSecureFile(file, appendBlock(base, block));
|
|
115
|
+
line(ctx.stdout, `✓ Saved profile "${profile.name}" (${profile.url}) to ${file}`);
|
|
116
|
+
line(ctx.stdout, ' The password is stored only in this file and is never shown to the AI.');
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
async function readAll(stream) {
|
|
120
|
+
const chunks = [];
|
|
121
|
+
for await (const chunk of stream)
|
|
122
|
+
chunks.push(Buffer.from(chunk));
|
|
123
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
124
|
+
}
|
|
125
|
+
export const STDIN_EXAMPLE = `printf '%s' "$PASSWORD" | npx autologin-mcp add staging --url staging.example.com --username qa@example.com --password-stdin`;
|
|
126
|
+
/** `add --password-stdin`: no questions, for scripts and CI (like `docker login --password-stdin`). */
|
|
127
|
+
async function addFromStdin(ctx, args, file, fail) {
|
|
128
|
+
const name = args.positionals[0]?.toLowerCase();
|
|
129
|
+
const { url, username } = args.flags;
|
|
130
|
+
if (name === undefined || url === undefined || username === undefined) {
|
|
131
|
+
return fail(`--password-stdin needs the profile name, --url and --username, for example:\n ${STDIN_EXAMPLE}`);
|
|
132
|
+
}
|
|
133
|
+
if (ctx.stdin.isTTY === true)
|
|
134
|
+
return fail('--password-stdin reads the password from a pipe, not from the keyboard. Leave it out to type the password hidden.');
|
|
135
|
+
const nameError = invalidName(name);
|
|
136
|
+
if (nameError !== null)
|
|
137
|
+
return fail(nameError);
|
|
138
|
+
const parsed = parseRootUrl(url);
|
|
139
|
+
if (!parsed.ok)
|
|
140
|
+
return fail(parsed.error);
|
|
141
|
+
if (username === '')
|
|
142
|
+
return fail('A username is required.');
|
|
143
|
+
// One trailing newline (from echo or a here-string) is not part of the password.
|
|
144
|
+
const password = (await readAll(ctx.stdin)).replace(/\r?\n$/, '');
|
|
145
|
+
if (password === '')
|
|
146
|
+
return fail('A password is required: nothing was piped in.');
|
|
147
|
+
if (/[\r\n]/.test(password))
|
|
148
|
+
return fail('The password must be a single line.');
|
|
149
|
+
const store = await loadStore(file);
|
|
150
|
+
const exists = store.profiles.some((p) => p.name === name);
|
|
151
|
+
if (exists && !args.flags.yes)
|
|
152
|
+
return fail(`Profile "${name}" already exists. Add -y to replace it.`);
|
|
153
|
+
const error = await saveProfile(ctx, file, { name, url: parsed.normalized, username, password }, exists);
|
|
154
|
+
return error === null ? 0 : fail(error);
|
|
155
|
+
}
|
|
89
156
|
async function addCommand(ctx, args) {
|
|
90
157
|
const file = credentialsFile(ctx);
|
|
91
|
-
const prompter = ctx.prompter(ctx.stdin, ctx.stdout);
|
|
92
158
|
const fail = (text) => {
|
|
93
159
|
line(ctx.stderr, text);
|
|
94
160
|
return 1;
|
|
95
161
|
};
|
|
162
|
+
if (args.flags.passwordStdin)
|
|
163
|
+
return addFromStdin(ctx, args, file, fail);
|
|
164
|
+
const prompter = ctx.prompter(ctx.stdin, ctx.stdout);
|
|
96
165
|
try {
|
|
97
166
|
const store = await loadStore(file);
|
|
98
167
|
const name = (args.positionals[0] ?? (await prompter.ask('Profile name (e.g. staging): '))).toLowerCase();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
168
|
+
const nameError = invalidName(name);
|
|
169
|
+
if (nameError !== null)
|
|
170
|
+
return fail(nameError);
|
|
102
171
|
const exists = store.profiles.some((p) => p.name === name);
|
|
103
|
-
if (exists && !(await prompter.confirm(`Profile "${name}" already exists. Replace it?`, false)))
|
|
172
|
+
if (exists && !args.flags.yes && !(await prompter.confirm(`Profile "${name}" already exists. Replace it?`, false)))
|
|
104
173
|
return fail('Cancelled.');
|
|
105
174
|
const urlInput = args.flags.url ?? (await prompter.ask('Root URL (e.g. example.com or localhost:3000): '));
|
|
106
175
|
const parsed = parseRootUrl(urlInput);
|
|
@@ -116,19 +185,8 @@ async function addCommand(ctx, args) {
|
|
|
116
185
|
return fail('A password is required.');
|
|
117
186
|
if ((await prompter.askHidden('Repeat the password: ')) !== password)
|
|
118
187
|
return fail('The passwords do not match.');
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
block = renderProfile({ name, url: parsed.normalized, username, password });
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
return fail(error.message);
|
|
125
|
-
}
|
|
126
|
-
const current = (await readText(file)) ?? ENV_TEMPLATE;
|
|
127
|
-
const base = exists ? removeProfile(current, name).text : current;
|
|
128
|
-
await writeSecureFile(file, appendBlock(base, block));
|
|
129
|
-
line(ctx.stdout, `✓ Saved profile "${name}" (${parsed.normalized}) to ${file}`);
|
|
130
|
-
line(ctx.stdout, ' The password is stored only in this file and is never shown to the AI.');
|
|
131
|
-
return 0;
|
|
188
|
+
const error = await saveProfile(ctx, file, { name, url: parsed.normalized, username, password }, exists);
|
|
189
|
+
return error === null ? 0 : fail(error);
|
|
132
190
|
}
|
|
133
191
|
catch (error) {
|
|
134
192
|
if (error instanceof InputClosedError)
|
|
@@ -187,10 +245,49 @@ async function editCommand(ctx) {
|
|
|
187
245
|
const editor = ctx.env.VISUAL?.trim() || ctx.env.EDITOR?.trim();
|
|
188
246
|
if (editor)
|
|
189
247
|
return openInEditor(file, editor, ctx.spawn);
|
|
190
|
-
|
|
248
|
+
try {
|
|
249
|
+
await openDetached(file, ctx.platform, { spawn: ctx.spawn, env: ctx.env });
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
line(ctx.stderr, `Could not open an editor (${error.message}).`);
|
|
253
|
+
line(ctx.stderr, `Set one for this command, e.g. EDITOR=nano npx autologin-mcp edit, or open ${file} yourself.`);
|
|
254
|
+
line(ctx.stderr, 'To add a profile without an editor: npx autologin-mcp add');
|
|
255
|
+
return 1;
|
|
256
|
+
}
|
|
191
257
|
line(ctx.stdout, `Opened ${file} in your default editor.`);
|
|
192
258
|
return 0;
|
|
193
259
|
}
|
|
260
|
+
/** `~/...` for a path inside the home folder, for messages. */
|
|
261
|
+
function displayPath(target, home) {
|
|
262
|
+
const rel = path.relative(home, target);
|
|
263
|
+
return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel) ? `~/${rel.split(path.sep).join('/')}` : target;
|
|
264
|
+
}
|
|
265
|
+
/** Prints the MCP server entry for a client other than Claude Code: the config on stdout, the notes on stderr. */
|
|
266
|
+
function printConfigCommand(ctx, args) {
|
|
267
|
+
const id = (args.flags.client ?? 'json').toLowerCase();
|
|
268
|
+
const config = clientConfig(id, packageSpec(args.flags.package));
|
|
269
|
+
if (config === null) {
|
|
270
|
+
line(ctx.stderr, `Unknown client "${id}". Choose one of: ${CLIENTS.join(', ')}.`);
|
|
271
|
+
line(ctx.stderr, 'For Claude Code, run "npx autologin-mcp install": it also adds the skill and the guard hook.');
|
|
272
|
+
return 1;
|
|
273
|
+
}
|
|
274
|
+
ctx.stdout.write(config.snippet);
|
|
275
|
+
const dir = displayPath(resolveConfigDir(ctx.env, ctx.home), ctx.home);
|
|
276
|
+
line(ctx.stderr);
|
|
277
|
+
line(ctx.stderr, `Add this to ${config.where}.`);
|
|
278
|
+
if (config.command)
|
|
279
|
+
line(ctx.stderr, `Or run: ${config.command}`);
|
|
280
|
+
if (config.note)
|
|
281
|
+
line(ctx.stderr, config.note);
|
|
282
|
+
line(ctx.stderr, 'Then add a login profile in a terminal, never in the AI chat: npx autologin-mcp add');
|
|
283
|
+
line(ctx.stderr, '');
|
|
284
|
+
line(ctx.stderr, `! Only Claude Code has the guard hook that keeps the agent out of ${dir}.`);
|
|
285
|
+
line(ctx.stderr, ` ${config.name === 'your MCP client' ? 'Your client' : config.name} gets the server's instruction not to read that folder, but nothing enforces it;`);
|
|
286
|
+
line(ctx.stderr, " deny the folder in the client's permission settings if it has them.");
|
|
287
|
+
line(ctx.stderr, ` Tested with Claude Code; reports for other clients: ${ISSUES_URL}`);
|
|
288
|
+
return 0;
|
|
289
|
+
}
|
|
290
|
+
export const ISSUES_URL = 'https://github.com/olgaysezgin/autologin-mcp/issues';
|
|
194
291
|
/**
|
|
195
292
|
* A local path (e.g. ./autologin-mcp-1.0.0.tgz) becomes an absolute `file:` spec:
|
|
196
293
|
* npx would try to execute a bare path instead of installing it.
|
|
@@ -267,6 +364,8 @@ export async function main(argv, overrides = {}) {
|
|
|
267
364
|
return await removeCommand(ctx, args);
|
|
268
365
|
case 'edit':
|
|
269
366
|
return await editCommand(ctx);
|
|
367
|
+
case 'print-config':
|
|
368
|
+
return printConfigCommand(ctx, args);
|
|
270
369
|
default:
|
|
271
370
|
line(ctx.stderr, `Unknown command "${args.command}".\n`);
|
|
272
371
|
line(ctx.stderr, USAGE);
|
package/dist/clients.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { SERVER_NAME } from './installer.js';
|
|
2
|
+
export const CLIENTS = ['json', 'claude-desktop', 'cursor', 'vscode', 'gemini', 'codex', 'hermes'];
|
|
3
|
+
/** Quotes a word for POSIX shells when it needs it. */
|
|
4
|
+
export function shellQuote(word) {
|
|
5
|
+
return /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`;
|
|
6
|
+
}
|
|
7
|
+
const json = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
8
|
+
const list = (items) => `[${items.map((item) => JSON.stringify(item)).join(', ')}]`;
|
|
9
|
+
export function clientConfig(id, packageSpec) {
|
|
10
|
+
const args = ['-y', packageSpec];
|
|
11
|
+
const server = { command: 'npx', args };
|
|
12
|
+
const npx = `npx ${args.map(shellQuote).join(' ')}`;
|
|
13
|
+
switch (id) {
|
|
14
|
+
case 'json':
|
|
15
|
+
return { name: 'your MCP client', where: "your client's MCP configuration (the common mcpServers format)", snippet: json({ mcpServers: { [SERVER_NAME]: server } }) };
|
|
16
|
+
case 'claude-desktop':
|
|
17
|
+
return {
|
|
18
|
+
name: 'Claude Desktop',
|
|
19
|
+
where: 'claude_desktop_config.json (Settings > Developer > Edit Config): ~/Library/Application Support/Claude/ on macOS, %APPDATA%\\Claude\\ on Windows',
|
|
20
|
+
snippet: json({ mcpServers: { [SERVER_NAME]: server } }),
|
|
21
|
+
note: 'Quit and restart Claude Desktop after saving.',
|
|
22
|
+
};
|
|
23
|
+
case 'cursor':
|
|
24
|
+
return {
|
|
25
|
+
name: 'Cursor',
|
|
26
|
+
where: '~/.cursor/mcp.json (all projects) or .cursor/mcp.json (one project)',
|
|
27
|
+
snippet: json({ mcpServers: { [SERVER_NAME]: { type: 'stdio', ...server } } }),
|
|
28
|
+
};
|
|
29
|
+
case 'vscode':
|
|
30
|
+
return {
|
|
31
|
+
name: 'VS Code',
|
|
32
|
+
where: '.vscode/mcp.json (one workspace) or your user mcp.json (command "MCP: Open User Configuration")',
|
|
33
|
+
snippet: json({ servers: { [SERVER_NAME]: { type: 'stdio', ...server } } }),
|
|
34
|
+
command: `code --add-mcp ${shellQuote(JSON.stringify({ name: SERVER_NAME, type: 'stdio', ...server }))}`,
|
|
35
|
+
};
|
|
36
|
+
case 'gemini':
|
|
37
|
+
return {
|
|
38
|
+
name: 'Gemini CLI',
|
|
39
|
+
where: '~/.gemini/settings.json (all projects) or .gemini/settings.json (one project)',
|
|
40
|
+
snippet: json({ mcpServers: { [SERVER_NAME]: server } }),
|
|
41
|
+
command: `gemini mcp add -s user ${SERVER_NAME} npx -- ${args.map(shellQuote).join(' ')}`,
|
|
42
|
+
};
|
|
43
|
+
case 'codex':
|
|
44
|
+
return {
|
|
45
|
+
name: 'Codex CLI',
|
|
46
|
+
where: '~/.codex/config.toml',
|
|
47
|
+
snippet: `[mcp_servers.${SERVER_NAME}]\ncommand = "npx"\nargs = ${list(args)}\n`,
|
|
48
|
+
command: `codex mcp add ${SERVER_NAME} -- ${npx}`,
|
|
49
|
+
};
|
|
50
|
+
case 'hermes':
|
|
51
|
+
return {
|
|
52
|
+
name: 'Hermes Agent',
|
|
53
|
+
where: '~/.hermes/config.yaml (merge it into an existing mcp_servers: block)',
|
|
54
|
+
snippet: `mcp_servers:\n ${SERVER_NAME}:\n command: "npx"\n args: ${list(args)}\n`,
|
|
55
|
+
command: `hermes mcp add ${SERVER_NAME} --command npx --args ${args.map(shellQuote).join(' ')}`,
|
|
56
|
+
note: 'In a running session, /reload-mcp loads it.',
|
|
57
|
+
};
|
|
58
|
+
default:
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
package/dist/opener.js
CHANGED
|
@@ -6,15 +6,39 @@ export function guiOpenCommand(file, platform) {
|
|
|
6
6
|
return ['notepad.exe', [file]];
|
|
7
7
|
return ['xdg-open', [file]];
|
|
8
8
|
}
|
|
9
|
-
/**
|
|
10
|
-
export function
|
|
9
|
+
/** macOS and Windows always have a desktop; elsewhere a window needs X11 or Wayland (not over SSH, in CI or in a container). */
|
|
10
|
+
export function hasDesktop(platform, env) {
|
|
11
|
+
if (platform === 'darwin' || platform === 'win32')
|
|
12
|
+
return true;
|
|
13
|
+
return Boolean(env.DISPLAY?.trim() || env.WAYLAND_DISPLAY?.trim());
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Opens a file in the desktop's default text editor without waiting for the editor.
|
|
17
|
+
* Rejects when there is no desktop, when the opener is missing, or when it exits with an error
|
|
18
|
+
* within `settleMs` (xdg-open without a display, `open` with no GUI session).
|
|
19
|
+
*/
|
|
20
|
+
export function openDetached(file, platform, options = {}) {
|
|
21
|
+
const { spawn = nodeSpawn, env = process.env, settleMs = 1_500 } = options;
|
|
22
|
+
if (!hasDesktop(platform, env))
|
|
23
|
+
return Promise.reject(new Error('there is no desktop session here (DISPLAY and WAYLAND_DISPLAY are not set)'));
|
|
11
24
|
const [command, args] = guiOpenCommand(file, platform);
|
|
12
25
|
return new Promise((resolve, reject) => {
|
|
13
26
|
const child = spawn(command, args, { detached: true, stdio: 'ignore' });
|
|
27
|
+
let timer;
|
|
14
28
|
child.once('error', reject);
|
|
29
|
+
child.once('exit', (code) => {
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
if (code === 0)
|
|
32
|
+
resolve();
|
|
33
|
+
else
|
|
34
|
+
reject(new Error(`${command} exited with ${code === null ? 'a signal' : `code ${code}`}`));
|
|
35
|
+
});
|
|
15
36
|
child.once('spawn', () => {
|
|
16
|
-
|
|
17
|
-
|
|
37
|
+
timer = setTimeout(() => {
|
|
38
|
+
child.removeAllListeners('exit');
|
|
39
|
+
child.unref();
|
|
40
|
+
resolve();
|
|
41
|
+
}, settleMs);
|
|
18
42
|
});
|
|
19
43
|
});
|
|
20
44
|
}
|
package/dist/serve.js
CHANGED
|
@@ -40,7 +40,7 @@ export function createDefaultDeps(options = {}) {
|
|
|
40
40
|
bridge,
|
|
41
41
|
openConfig: async () => {
|
|
42
42
|
const created = await ensureEnvFile(file);
|
|
43
|
-
await openDetached(file, platform, options.spawn);
|
|
43
|
+
await openDetached(file, platform, { spawn: options.spawn, env });
|
|
44
44
|
return { created };
|
|
45
45
|
},
|
|
46
46
|
limiter,
|
package/dist/server.js
CHANGED
|
@@ -6,7 +6,8 @@ import { hostOf, matchesUrl } from './store/match.js';
|
|
|
6
6
|
import { isUsable } from './store/profiles.js';
|
|
7
7
|
export const ADD_HINT = 'Ask the user to run "npx autologin-mcp add" in a separate terminal (never in this chat), or call open_config so they can edit the credentials file.';
|
|
8
8
|
export const RUN_IN_PAGE_HINT = 'Run `script` unchanged in the tab that shows the login form, with your browser tool\'s JavaScript evaluation (Claude in Chrome: javascript_tool). ' +
|
|
9
|
-
'Tools that take a function (Playwright MCP browser_evaluate, chrome-devtools-mcp evaluate_script) take `function` instead
|
|
9
|
+
'Tools that take a function (Playwright MCP browser_evaluate, chrome-devtools-mcp evaluate_script) take `function` instead; ' +
|
|
10
|
+
'tools that evaluate a plain script without top-level await (Puppeteer page.evaluate) take `expression`. ' +
|
|
10
11
|
'The value it returns is the login result (success, submitted, failed, ...). It works once, within the expiry, and only on a page of this profile\'s site. ' +
|
|
11
12
|
'If the call itself fails or returns nothing (the page navigated, the browser tool lost the tab), call `login_status` to get the result the page reported.';
|
|
12
13
|
export const INSTRUCTIONS = [
|
|
@@ -87,6 +88,7 @@ async function loginViaBridge(deps, usable, args) {
|
|
|
87
88
|
expires_in_s: ticket.expiresInSeconds,
|
|
88
89
|
script: ticket.script,
|
|
89
90
|
function: ticket.function,
|
|
91
|
+
expression: ticket.expression,
|
|
90
92
|
};
|
|
91
93
|
}
|
|
92
94
|
export async function runLogin(deps, store, args) {
|
|
@@ -178,7 +180,13 @@ export function createServer(deps) {
|
|
|
178
180
|
});
|
|
179
181
|
}
|
|
180
182
|
catch (error) {
|
|
181
|
-
|
|
183
|
+
// No desktop (SSH, CI, a container) is a normal situation, not a tool error: tell the agent where the file is.
|
|
184
|
+
return reply({
|
|
185
|
+
file: deps.configFile,
|
|
186
|
+
opened: false,
|
|
187
|
+
hint: `Could not open an editor here (${message(error)}). Ask the user to run "npx autologin-mcp add" in a separate terminal (never in this chat), ` +
|
|
188
|
+
'or to open this file in a text editor there. Do not read this file.',
|
|
189
|
+
});
|
|
182
190
|
}
|
|
183
191
|
});
|
|
184
192
|
return server;
|
package/dist/templates.js
CHANGED
|
@@ -33,7 +33,7 @@ The \`autologin\` MCP server fills the login form for you and only tells you the
|
|
|
33
33
|
## When the app asks you to log in
|
|
34
34
|
|
|
35
35
|
1. Call \`mcp__autologin__login\` with \`url\` = the tab's current URL. Pass \`profile\` when there are several accounts for the same app (see \`mcp__autologin__list_profiles\`).
|
|
36
|
-
2. \`run_in_page\`: run the returned \`script\` **unchanged** in that tab with your JavaScript tool (Claude in Chrome: \`javascript_tool\`; Playwright MCP \`browser_evaluate\` / chrome-devtools-mcp \`evaluate_script\`: pass \`function\`). Its return value is the login result below. It contains a one-time URL, never a password. If that call fails or returns nothing (the page navigated, the browser tool lost the tab), call \`mcp__autologin__login_status\` to get the result the page reported.
|
|
36
|
+
2. \`run_in_page\`: run the returned \`script\` **unchanged** in that tab with your JavaScript tool (Claude in Chrome: \`javascript_tool\`; Playwright MCP \`browser_evaluate\` / chrome-devtools-mcp \`evaluate_script\`: pass \`function\`; Puppeteer \`page.evaluate\`: pass \`expression\`). Its return value is the login result below. It contains a one-time URL, never a password. If that call fails or returns nothing (the page navigated, the browser tool lost the tab), call \`mcp__autologin__login_status\` to get the result the page reported.
|
|
37
37
|
3. \`success\`: continue the task where you left off. \`submitted\`: the page navigated; take a look to confirm you are logged in.
|
|
38
38
|
4. \`failed\`: tell the user the \`hint\`; do not retry more than once.
|
|
39
39
|
\`no_login_form\`: the page has no login form. If it carries \`previous_login\` with \`success\` or \`submitted\`, your earlier login went through: continue the task.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autologin-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Auto-login MCP server for AI coding agents (Claude Code, Claude in Chrome, Playwright MCP, chrome-devtools-mcp). Logs your agent into the app under test; credentials stay on your machine and never reach the model.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"typecheck": "tsc --noEmit",
|
|
20
20
|
"test": "vitest run",
|
|
21
21
|
"coverage": "vitest run --coverage",
|
|
22
|
-
"prepublishOnly": "npm run typecheck && npm run coverage && npm run build && npm run smoke",
|
|
22
|
+
"prepublishOnly": "node scripts/release.mjs publish-guard && npm run typecheck && npm run coverage && npm run build && npm run smoke",
|
|
23
|
+
"version": "node scripts/release.mjs sync && git add README.md CHANGELOG.md docs",
|
|
23
24
|
"smoke": "node scripts/smoke.mjs"
|
|
24
25
|
},
|
|
25
26
|
"keywords": [
|
|
@@ -39,6 +40,11 @@
|
|
|
39
40
|
"claude-in-chrome",
|
|
40
41
|
"playwright-mcp",
|
|
41
42
|
"chrome-devtools-mcp",
|
|
43
|
+
"puppeteer",
|
|
44
|
+
"codex",
|
|
45
|
+
"gemini-cli",
|
|
46
|
+
"cursor",
|
|
47
|
+
"hermes-agent",
|
|
42
48
|
"ai-testing",
|
|
43
49
|
"session-expired",
|
|
44
50
|
"test-automation",
|