Skip to content

Commit 8525d2e

Browse files
authored
fix(init): register e2e mcp with the project's package manager (e2e-inc#2372)
* fix(init): register e2e mcp with the project's package manager npx exits with EBADDEVENGINES before the MCP handshake when the project's devEngines pins another manager, and finds no binary under Yarn Plug'n'Play. init now writes pnpm exec e2e mcp for pnpm and yarn run --silent e2e mcp for Yarn; npm keeps npx and Bun keeps bunx. * fix(init): run the binary under Yarn, cover the pnpm pin yarn run resolves a package.json script named e2e before the binary, so Yarn projects register yarn exec forms instead. The init integration test now starts the server a pnpm project with a devEngines pin registers. * fix(init): read the Yarn flavor from the lockfile, share the exec argv execArgv in package-manager.ts is the one argv form, mcpLaunch adds e2e mcp. detectWorkspacePackageManager returns yarnBerry with the manager and root. Yarn 2+ is also read from yarn.lock, and from a two-digit major. execCommand prints yarn exec -- so a script named e2e does not run first. * fix(init): read Yarn's version from the Yarn that started init A project with no lockfile yet got the Yarn 1 command under Yarn 4. Also read a devEngines pin as the project's manager, and keep the arguments an entry passes after mcp on a re-run. * fix(init): keep a devEngines pin from naming an install root A workspace member that repeats the pin installed in its own folder. Also keep the arguments after a versioned e2e package, read an empty yarn.lock as undecided, read the Yarn major of a devEngines pin, and read the pin in detectPackageManager too. * fix(init): leave a two-major Yarn pin to the invoking Yarn Also read a member's devEngines pin when its workspace root names no manager.
1 parent 95b13a2 commit 8525d2e

15 files changed

Lines changed: 395 additions & 68 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'e2e': patch
3+
---
4+
5+
`e2e init` now registers the MCP server with the project's own package manager: `pnpm exec e2e mcp` in a pnpm project and `yarn exec e2e mcp` in a Yarn one (`yarn --silent exec -- e2e mcp` on Yarn 1), where it wrote `npx e2e mcp` before. `npx` exits with `EBADDEVENGINES` before the MCP handshake when the project's `devEngines` pins another manager, and the client showed only `Connection closed`. Run `e2e init` again to update an existing entry; it keeps the entry's other settings and, for an entry started as `<launcher> e2e mcp ...`, the arguments after `mcp`. A project that names its manager only in `devEngines`, with no `packageManager` field and no lockfile, is read as that manager's.
6+
7+
The commands e2e prints for a Yarn project now read `yarn exec -- e2e ...`: `yarn e2e` runs a package.json script named `e2e` before the binary. `e2e init` also tells Yarn 2 or later from Yarn 1 by the lockfile when the project has no `.yarnrc.yml` and no `packageManager` field, and by the Yarn that started it when the project has no lockfile yet.

‎docs/mcp-server.mdx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ as `npx -y e2e@<version> mcp`, running the plugin's e2e release even when
2929
the project has another version installed. In Claude Code (or without the
3030
plugin), register it in your project. `e2e init` can write the config for
3131
`.mcp.json` (Claude Code), `.cursor/mcp.json` (Cursor), and
32-
`.codex/config.toml` (Codex). Install your project dependencies and launch
33-
your MCP client in the project directory so `npx` (or `bunx`) picks up the
34-
installed `e2e` version. To set it up by hand:
32+
`.codex/config.toml` (Codex), with the command of your package manager:
33+
`npx e2e mcp`, `pnpm exec e2e mcp`, `yarn exec e2e mcp`
34+
(`yarn --silent exec -- e2e mcp` on Yarn 1), or `bunx e2e mcp`. Install your project dependencies and launch your MCP client
35+
in the project directory so the command picks up the installed `e2e`
36+
version. To set it up by hand:
3537

3638
<Tabs>
3739
<Tab title="Claude Code">
@@ -87,6 +89,10 @@ installed `e2e` version. To set it up by hand:
8789
</Tab>
8890
</Tabs>
8991

92+
If the client reports `Connection closed` and the command fails in a
93+
terminal with `EBADDEVENGINES`, the project's `devEngines` pins another
94+
package manager: register that manager's command, such as `pnpm exec e2e mcp`.
95+
9096
If your target defines an `app.command`, the session starts your app and
9197
prints its URL and port. The first session on a config file starts its
9298
[services](/services), and the last one to close stops them. The config reads

‎docs/reference/cli.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ installed. pnpm gets `--no-frozen-lockfile`, and Yarn
194194
| `.gitignore` | Appends `node_modules/`, `.e2e/results/`, `.e2e/cache/`, `.e2e/sessions/`, `.e2e/report.json`, `.e2e/ai-trace.json`, `.e2e/timings.json`, `.e2e/junit.xml`, `.e2e/summary.md`, `.e2e/ctrf.json`, `.e2e/logs/`, and `.e2e/videos/`. Committing the cache is opt-in; see [commit the replay cache](/cache#commit-the-replay-cache) |
195195
| `.agents/skills/e2e/`, `.claude/skills/e2e/` | `SKILL.md` and one `references/<topic>.md` per `e2e guide` topic. With both chosen, the Claude Code directory is a relative symlink (`../../.agents/skills/e2e`) to the copy, the layout `npx skills add` produces |
196196
| `AGENTS.md`, `CLAUDE.md` | Appends `End-to-end tests use e2e; read .agents/skills/e2e/SKILL.md before writing or running one.` to `AGENTS.md` when the skill is in `.agents/skills/`, and the same line with `.claude/skills/e2e/SKILL.md` to `CLAUDE.md` when it is in `.claude/skills/`. Created when missing; the rest of an existing file is unchanged. Neither with `--skills none` |
197-
| `.mcp.json`, `.cursor/mcp.json`, `.codex/config.toml` | Registers `e2e mcp` without changing other servers |
197+
| `.mcp.json`, `.cursor/mcp.json`, `.codex/config.toml` | Registers `e2e mcp` with the project's package manager (`npx e2e mcp`, `pnpm exec e2e mcp`, `yarn exec e2e mcp`, `bunx e2e mcp`) without changing other servers |
198198
| `.github/workflows/e2e.yml`, `.gitlab-ci.yml` | With `--ci`: a job for each platform the targets run on. At the repository root, also for a project in a subfolder. See [CI pipeline](#ci-pipeline) |
199199

200200
<a id="nextjs-apps" />

‎docs/reference/mcp.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ passes `foldTools(...)` gets `fold` for a foldable device.
486486
The server ships with `e2e`. `e2e init` offers to register it in
487487
`.mcp.json` (Claude Code), `.cursor/mcp.json` (Cursor), and
488488
`.codex/config.toml` (Codex). Install dependencies and start the MCP client
489-
in the project directory so `npx` (`bunx` in a Bun project) uses the installed e2e version. By hand:
489+
in the project directory so the command uses the installed e2e version. Init
490+
writes your package manager's command; see [MCP server](/mcp-server#set-it-up). By hand:
490491

491492
<CodeGroup>
492493
```bash npm

‎packages/e2e/src/cli/init.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
installCommand,
1414
readPackageManifest,
1515
runScriptCommand,
16+
projectManager,
1617
type PackageManager,
1718
} from '../internal/package-manager.ts';
1819
import { CONFIG_NAMES, JS_CONFIG_NAMES } from '../config/names.ts';
@@ -405,11 +406,12 @@ export async function init(root: string, options: InitOptions = {}): Promise<Ini
405406
facts.mcp = mcpFiles.length > 0;
406407
// A workspace member takes its workspace root's manager when this machine has it, and is treated as a standalone project otherwise.
407408
const own = detectPackageManager(cwd, pkg.manifest.packageManager);
408-
const manager = workspace.manager === own || isInstalled(workspace.manager, workspace.root) ? workspace.manager : own;
409+
const project = workspace.manager === own || isInstalled(workspace.manager, workspace.root) ? workspace : projectManager(own, cwd);
410+
const { manager } = project;
409411
if (manager !== workspace.manager) clack.log.warn(`This workspace uses ${workspace.manager}, which was not found on this machine; continuing with ${manager}`);
410412
let mcpRegistrations: ReturnType<typeof planMcpRegistration>['registrations'];
411413
try {
412-
const plan = planMcpRegistration(cwd, mcpFiles, manager);
414+
const plan = planMcpRegistration(cwd, mcpFiles, project);
413415
mcpRegistrations = plan.registrations;
414416
for (const link of plan.links) {
415417
clack.log.warn(`Symlink, not touching: ${link.relative} -> ${link.target} (e2e mcp server)`);
@@ -684,7 +686,7 @@ function planWorkflow(input: {
684686
}): PlannedWorkflow {
685687
const { cwd, repositoryRoot } = input;
686688
// A workspace member installs and caches at the workspace root, with the root's manager.
687-
const { manager, root: installRoot } = detectWorkspacePackageManager(cwd);
689+
const { manager, root: installRoot, yarnBerry } = detectWorkspacePackageManager(cwd);
688690
const packageManagerField = readPackageManifest(installRoot)?.['packageManager'];
689691
const packageManager = typeof packageManagerField === 'string' ? packageManagerField : '';
690692
const gateways = input.existingConfigText === undefined
@@ -700,7 +702,7 @@ function planWorkflow(input: {
700702
...(nodeVersionFile === undefined ? {} : { nodeVersionFile: posixRelative(repositoryRoot, nodeVersionFile) }),
701703
...(nodeMajor === undefined ? {} : { nodeMajor }),
702704
...(manager === 'pnpm' && !packageManager.startsWith('pnpm@') ? { pnpmVersion: localPnpmMajor() } : {}),
703-
yarnBerry: existsSync(path.join(installRoot, '.yarnrc.yml')) || /^yarn@[2-9]/u.test(packageManager),
705+
yarnBerry,
704706
// Bun before 1.2 writes the binary bun.lockb.
705707
...(manager === 'bun' && !existsSync(path.join(installRoot, 'bun.lock')) && existsSync(path.join(installRoot, 'bun.lockb')) ? { lockfile: 'bun.lockb' } : {}),
706708
secrets,

‎packages/e2e/src/cli/init/mcp-config.ts‎

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99

1010
import { existsSync, lstatSync, readFileSync } from 'node:fs';
1111
import path from 'node:path';
12-
import type { PackageManager } from '../../internal/package-manager.ts';
12+
import { execArgv, type ProjectManager } from '../../internal/package-manager.ts';
13+
import { isPlainObject } from '@e2e-dev/core/lib/internal/options';
1314
import { realpathOfExisting } from '@e2e-dev/core/lib/internal/paths';
1415
import { MCP_LOCATIONS } from './choices.ts';
1516
import { readCodexConfig, updateCodexConfig } from './codex-config.ts';
1617

1718
const MCP_SERVER_NAME = 'e2e';
1819

20+
type McpProject = Pick<ProjectManager, 'manager' | 'yarnBerry'>;
21+
1922
export interface McpRegistration {
2023
/** Project-relative file, e.g. `.mcp.json`. */
2124
readonly relative: string;
@@ -97,16 +100,33 @@ export function findRegisteredMcpFiles(cwd: string): string[] {
97100
});
98101
}
99102

103+
/**
104+
* How a client starts the server from the project with e2e installed: through
105+
* the project's own package manager. `npx` exits before the handshake in a
106+
* project whose `devEngines` pins another manager, and finds no binary in a
107+
* Yarn Plug'n'Play install; a Bun project may have no Node.js for it at all.
108+
*/
109+
function mcpLaunch(project: McpProject, existing: unknown): { readonly command: string; readonly args: readonly string[] } {
110+
const { command, args } = execArgv(project);
111+
return { command, args: [...args, 'e2e', 'mcp', ...serverArguments(existing)] };
112+
}
113+
114+
/** What an existing entry passes to `e2e mcp` itself, after a launcher that names the package, as `npx -y e2e@0.25.0 mcp` does. */
115+
function serverArguments(existing: unknown): readonly string[] {
116+
const args: unknown = isPlainObject(existing) ? existing['args'] : undefined;
117+
if (!Array.isArray(args) || !args.every((arg) => typeof arg === 'string')) return [];
118+
const server = args.findIndex((arg, index) => /^e2e(?:@.+)?$/u.test(arg) && args[index + 1] === 'mcp');
119+
return server === -1 ? [] : args.slice(server + 2);
120+
}
121+
100122
/**
101123
* Plans the writes for the given files. A file without the entry gets it
102124
* merged in; one whose entry already matches needs nothing and is left out.
103-
* Extra settings on the e2e entry, other servers, other keys, and the file's
104-
* indentation are preserved. A file reached through a symlink is never read;
125+
* Extra settings on the e2e entry, the arguments it passes to `e2e mcp`,
126+
* other servers, other keys, and the file's indentation are preserved. A file reached through a symlink is never read;
105127
* it is returned among `links` for the caller to report and skip.
106128
*/
107-
export function planMcpRegistration(cwd: string, files: readonly string[], manager: PackageManager): McpPlan {
108-
// How clients start the server from the project with e2e installed; a Bun project may have no Node.js, so no npx.
109-
const launch = { command: manager === 'bun' ? 'bunx' : 'npx', args: ['e2e', 'mcp'] };
129+
export function planMcpRegistration(cwd: string, files: readonly string[], project: McpProject): McpPlan {
110130
const registrations: McpRegistration[] = [];
111131
const links: McpLink[] = [];
112132
for (const file of files) {
@@ -123,9 +143,8 @@ export function planMcpRegistration(cwd: string, files: readonly string[], manag
123143
? document[serverKey]
124144
: {};
125145
const existing = servers[MCP_SERVER_NAME];
126-
const entry = typeof existing === 'object' && existing !== null && !Array.isArray(existing)
127-
? { ...existing, ...launch }
128-
: launch;
146+
const launch = mcpLaunch(project, existing);
147+
const entry = isPlainObject(existing) ? { ...existing, ...launch } : launch;
129148
if (JSON.stringify(existing) === JSON.stringify(entry)) continue;
130149
const merged: McpConfigDocument = { ...document, mcpServers: { ...servers, [MCP_SERVER_NAME]: entry } };
131150
const original = existsSync(absolute) ? readFileSync(absolute, 'utf8') : undefined;

0 commit comments

Comments
 (0)