@icoretech/warden-mcp 0.2.4 → 0.2.6

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 CHANGED
@@ -69,7 +69,9 @@ not continuously proven in CI without a real Bitwarden tenant.
69
69
  This repository's compose smoke now exercises both direct `bw` auth flows and
70
70
  the MCP/SDK layers with username/password auth plus user API-key auth against a
71
71
  real local Vaultwarden, so `@bitwarden/cli` bumps do not rely on unit coverage
72
- alone.
72
+ alone. The bundled postinstall compatibility shim rewrites the affected
73
+ `build/bw.js` login strategies in place so the same Vaultwarden fallback can
74
+ survive compatible CLI bumps without a version-stamped patch artifact.
73
75
 
74
76
  ## Install And Run
75
77
 
@@ -508,6 +510,10 @@ raw CLI plus MCP/SDK layers:
508
510
  - user/password login from `.env.test`
509
511
  - api-key login from `tmp/vaultwarden-bootstrap/apikey.env`, generated by the bootstrap step and kept out of git via `tmp/`
510
512
 
513
+ The compose bootstrap step depends on the Playwright Docker image matching the
514
+ `playwright` npm package version. If either moves, update the other in the same
515
+ change.
516
+
511
517
  Run session flood regression locally (guardrail sanity):
512
518
 
513
519
  ```bash
@@ -1,12 +1,10 @@
1
- import { spawnSync } from 'node:child_process';
2
- import { existsSync, rmSync, writeFileSync } from 'node:fs';
1
+ import { readFileSync, writeFileSync } from 'node:fs';
3
2
  import { createRequire } from 'node:module';
4
- import { dirname, isAbsolute, relative, resolve } from 'node:path';
3
+ import { dirname, join } from 'node:path';
5
4
  import { fileURLToPath } from 'node:url';
6
5
 
7
6
  const require = createRequire(import.meta.url);
8
- const __dirname = dirname(fileURLToPath(import.meta.url));
9
- const defaultPackageDir = resolve(__dirname, '..');
7
+ const compatMarker = 'icoretech-vaultwarden-compat';
10
8
 
11
9
  function isModuleNotFoundFor(specifier, error) {
12
10
  if (!(error instanceof Error)) return false;
@@ -14,134 +12,101 @@ function isModuleNotFoundFor(specifier, error) {
14
12
  return error.message.includes(specifier);
15
13
  }
16
14
 
17
- export function findInstallRoot(packageJsonPath) {
18
- let currentDir = dirname(packageJsonPath);
19
-
20
- while (true) {
21
- const parentDir = dirname(currentDir);
22
- if (parentDir === currentDir) break;
23
- if (
24
- currentDir.endsWith('/node_modules') ||
25
- currentDir.endsWith('\\node_modules')
26
- ) {
27
- return parentDir;
28
- }
29
- currentDir = parentDir;
30
- }
31
-
32
- throw new Error(
33
- `[warden-mcp] could not determine install root from ${packageJsonPath}`,
34
- );
35
- }
36
-
37
- export function resolvePatchPackagePlan({
38
- packageDir = defaultPackageDir,
15
+ export function resolveBundledBwCliPath({
39
16
  resolveDependency = (specifier) => require.resolve(specifier),
40
- exists = existsSync,
41
17
  } = {}) {
42
- const patchesDir = resolve(packageDir, 'patches');
43
- if (!exists(patchesDir)) {
44
- throw new Error(
45
- `[warden-mcp] patches directory not found at ${patchesDir}`,
46
- );
47
- }
48
-
49
- let cliPackageJsonPath;
50
18
  try {
51
- cliPackageJsonPath = resolveDependency('@bitwarden/cli/package.json');
19
+ const cliPackageJsonPath = resolveDependency('@bitwarden/cli/package.json');
20
+ return join(dirname(cliPackageJsonPath), 'build', 'bw.js');
52
21
  } catch (error) {
53
22
  if (isModuleNotFoundFor('@bitwarden/cli/package.json', error)) {
54
23
  return null;
55
24
  }
56
25
  throw error;
57
26
  }
27
+ }
58
28
 
59
- const installRoot = findInstallRoot(cliPackageJsonPath);
60
- const patchDir = relative(installRoot, patchesDir) || '.';
61
- if (isAbsolute(patchDir) || patchDir.startsWith('..')) {
62
- throw new Error(
63
- `[warden-mcp] patch directory ${patchesDir} is outside install root ${installRoot}`,
64
- );
65
- }
66
-
67
- return {
68
- cwd: installRoot,
69
- args: [
70
- resolveDependency('patch-package/dist/index.js'),
71
- '--patch-dir',
72
- patchDir,
73
- '--error-on-fail',
74
- ],
75
- };
29
+ function buildCompatBlock(indent) {
30
+ return [
31
+ `${indent}/* ${compatMarker} */`,
32
+ `${indent}if (response.accountKeysResponseModel) {`,
33
+ `${indent} yield this.accountCryptographicStateService.setAccountCryptographicState(response.accountKeysResponseModel.toWrappedAccountCryptographicState(), userId);`,
34
+ `${indent}}`,
35
+ `${indent}else if (response.privateKey) {`,
36
+ `${indent} yield this.accountCryptographicStateService.setAccountCryptographicState({`,
37
+ `${indent} V1: {`,
38
+ `${indent} private_key: response.privateKey,`,
39
+ `${indent} },`,
40
+ `${indent} }, userId);`,
41
+ `${indent}}`,
42
+ ].join('\n');
76
43
  }
77
44
 
78
- const bootstrapPackageJson = `${JSON.stringify(
79
- { name: 'warden-mcp-postinstall-bootstrap', private: true },
80
- null,
81
- 2,
82
- )}\n`;
45
+ const strategyMethodRegex =
46
+ /(setAccountCryptographicState\(response, userId\) \{\n\s+return [^\n]+\(\s*this, void 0, void 0, function\* \(\) \{\n)(\s*)yield this\.accountCryptographicStateService\.setAccountCryptographicState\(response\.accountKeysResponseModel\.toWrappedAccountCryptographicState\(\), userId\);\n(\s*\}\);\n\s*\})/g;
83
47
 
84
- export function ensurePatchPackageAppRoot({
85
- appRoot,
86
- exists = existsSync,
87
- writeFile = writeFileSync,
88
- } = {}) {
89
- const packageJsonPath = resolve(appRoot, 'package.json');
90
- if (exists(packageJsonPath)) return null;
91
- writeFile(packageJsonPath, bootstrapPackageJson);
92
- return packageJsonPath;
48
+ export function patchBundledBwSource(source) {
49
+ let replacements = 0;
50
+
51
+ const patchedSource = source.replace(
52
+ strategyMethodRegex,
53
+ (_match, prefix, indent, suffix) => {
54
+ replacements += 1;
55
+ return `${prefix}${buildCompatBlock(indent)}\n${suffix}`;
56
+ },
57
+ );
58
+
59
+ if (replacements > 0) {
60
+ return { source: patchedSource, replacements };
61
+ }
62
+
63
+ if (source.includes(compatMarker)) {
64
+ return { source, replacements: 0 };
65
+ }
66
+
67
+ throw new Error(
68
+ '[warden-mcp] could not locate the expected setAccountCryptographicState blocks in @bitwarden/cli/build/bw.js',
69
+ );
93
70
  }
94
71
 
95
72
  export function applyBundledBwPatch({
96
- packageDir = defaultPackageDir,
97
73
  resolveDependency,
98
- exists,
99
- spawn = spawnSync,
100
- nodeExecPath = process.execPath,
101
- writeFile,
102
- removeFile = (path) => rmSync(path, { force: true }),
74
+ readFile = (path) => readFileSync(path, 'utf8'),
75
+ writeFile = (path, contents) => writeFileSync(path, contents),
103
76
  logError = (message) => console.error(message),
104
77
  } = {}) {
105
- let plan;
78
+ let bwCliPath;
106
79
  try {
107
- plan = resolvePatchPackagePlan({ packageDir, resolveDependency, exists });
80
+ bwCliPath = resolveBundledBwCliPath({ resolveDependency });
108
81
  } catch (error) {
109
82
  const message =
110
83
  error instanceof Error
111
84
  ? error.message
112
- : '[warden-mcp] failed to prepare patch-package';
85
+ : '[warden-mcp] failed to resolve @bitwarden/cli';
113
86
  logError(message);
114
87
  return 1;
115
88
  }
116
89
 
117
- if (!plan) return 0;
90
+ if (!bwCliPath) return 0;
118
91
 
119
- const temporaryPackageJsonPath = ensurePatchPackageAppRoot({
120
- appRoot: plan.cwd,
121
- exists,
122
- writeFile,
123
- });
124
-
125
- let result;
126
92
  try {
127
- result = spawn(nodeExecPath, plan.args, {
128
- cwd: plan.cwd,
129
- stdio: 'inherit',
130
- });
131
- } finally {
132
- if (temporaryPackageJsonPath) {
133
- removeFile(temporaryPackageJsonPath);
93
+ const currentSource = readFile(bwCliPath);
94
+ const { source: patchedSource, replacements } =
95
+ patchBundledBwSource(currentSource);
96
+
97
+ if (replacements > 0) {
98
+ writeFile(bwCliPath, patchedSource);
134
99
  }
135
- }
136
100
 
137
- if (result.error) {
138
- logError(
139
- `[warden-mcp] failed to execute patch-package: ${result.error.message}`,
140
- );
101
+ return 0;
102
+ } catch (error) {
103
+ const message =
104
+ error instanceof Error
105
+ ? error.message
106
+ : '[warden-mcp] failed to patch bundled @bitwarden/cli';
107
+ logError(message);
141
108
  return 1;
142
109
  }
143
-
144
- return result.status ?? 1;
145
110
  }
146
111
 
147
112
  export function isDirectRun(importMetaUrl, argv = process.argv) {
@@ -170,6 +170,19 @@ export class BwSessionManager {
170
170
  }).catch(() => { });
171
171
  }
172
172
  }
173
+ async currentServerUrl() {
174
+ try {
175
+ const { stdout } = await runBw(['status'], {
176
+ env: this.baseEnv(),
177
+ timeoutMs: 30_000,
178
+ });
179
+ const parsed = JSON.parse(stdout);
180
+ return typeof parsed.serverUrl === 'string' ? parsed.serverUrl : null;
181
+ }
182
+ catch {
183
+ return null;
184
+ }
185
+ }
173
186
  async ensureUnlockedInternal() {
174
187
  // Ensure server config points to BW_HOST.
175
188
  await this.ensureServerConfigured();
@@ -271,6 +284,11 @@ export class BwSessionManager {
271
284
  async ensureServerConfigured() {
272
285
  if (this.configuredHost === this.env.host)
273
286
  return;
287
+ const currentHost = await this.currentServerUrl();
288
+ if (currentHost === this.env.host) {
289
+ this.configuredHost = currentHost;
290
+ return;
291
+ }
274
292
  // bw requires logout before config server update.
275
293
  await runBw(['logout'], { env: this.baseEnv(), timeoutMs: 30_000 }).catch(() => { });
276
294
  try {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@icoretech/warden-mcp",
4
- "version": "0.2.4",
4
+ "version": "0.2.6",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "Vaultwarden/Bitwarden MCP server backed by Bitwarden CLI (bw).",
@@ -29,7 +29,6 @@
29
29
  "files": [
30
30
  "dist/",
31
31
  "bin/",
32
- "patches/",
33
32
  "!dist/**/*.test.js",
34
33
  "!dist/integration/"
35
34
  ],
@@ -40,24 +39,23 @@
40
39
  "start": "node dist/server.js",
41
40
  "test": "npm run build && node --test \"dist/**/*.test.js\"",
42
41
  "test:coverage": "npm run build && node --test --experimental-test-coverage \"dist/**/*.test.js\"",
43
- "test:integration": "npm run build && node --test --test-timeout=45000 \"dist/integration/**/*.test.js\"",
42
+ "test:integration": "npm run build && node --test --test-concurrency=1 --test-timeout=45000 \"dist/integration/**/*.test.js\"",
44
43
  "test:session-regression": "node scripts/session-flood-regression.mjs",
45
44
  "lint": "biome check --write --assist-enabled=true . && tsc --noEmit"
46
45
  },
47
46
  "dependencies": {
48
- "@modelcontextprotocol/sdk": "^1.28.0",
47
+ "@modelcontextprotocol/sdk": "^1.29.0",
49
48
  "express": "^5.2.1",
50
- "patch-package": "^8.0.1",
51
49
  "zod": "^4.3.6"
52
50
  },
53
51
  "optionalDependencies": {
54
- "@bitwarden/cli": "2026.2.0"
52
+ "@bitwarden/cli": "2026.3.0"
55
53
  },
56
54
  "devDependencies": {
57
- "@biomejs/biome": "^2.4.9",
55
+ "@biomejs/biome": "^2.4.10",
58
56
  "@types/express": "^5.0.6",
59
- "@types/node": "^25.5.0",
60
- "playwright": "1.58.2",
57
+ "@types/node": "^25.5.2",
58
+ "playwright": "1.59.1",
61
59
  "tsx": "^4.21.0",
62
60
  "typescript": "^6.0.2"
63
61
  },
@@ -1,80 +0,0 @@
1
- diff --git a/node_modules/@bitwarden/cli/build/bw.js b/node_modules/@bitwarden/cli/build/bw.js
2
- index 6b02f68..2085f5e 100755
3
- --- a/node_modules/@bitwarden/cli/build/bw.js
4
- +++ b/node_modules/@bitwarden/cli/build/bw.js
5
- @@ -27093,7 +27093,17 @@ class AuthRequestLoginStrategy extends LoginStrategy {
6
- }
7
- setAccountCryptographicState(response, userId) {
8
- return auth_request_login_strategy_awaiter(this, void 0, void 0, function* () {
9
- - yield this.accountCryptographicStateService.setAccountCryptographicState(response.accountKeysResponseModel.toWrappedAccountCryptographicState(), userId);
10
- + /* icoretech-vaultwarden-compat */
11
- + if (response.accountKeysResponseModel) {
12
- + yield this.accountCryptographicStateService.setAccountCryptographicState(response.accountKeysResponseModel.toWrappedAccountCryptographicState(), userId);
13
- + }
14
- + else if (response.privateKey) {
15
- + yield this.accountCryptographicStateService.setAccountCryptographicState({
16
- + V1: {
17
- + private_key: response.privateKey,
18
- + },
19
- + }, userId);
20
- + }
21
- });
22
- }
23
- exportCache() {
24
- @@ -27203,7 +27213,17 @@ class PasswordLoginStrategy extends LoginStrategy {
25
- }
26
- setAccountCryptographicState(response, userId) {
27
- return password_login_strategy_awaiter(this, void 0, void 0, function* () {
28
- - yield this.accountCryptographicStateService.setAccountCryptographicState(response.accountKeysResponseModel.toWrappedAccountCryptographicState(), userId);
29
- + /* icoretech-vaultwarden-compat */
30
- + if (response.accountKeysResponseModel) {
31
- + yield this.accountCryptographicStateService.setAccountCryptographicState(response.accountKeysResponseModel.toWrappedAccountCryptographicState(), userId);
32
- + }
33
- + else if (response.privateKey) {
34
- + yield this.accountCryptographicStateService.setAccountCryptographicState({
35
- + V1: {
36
- + private_key: response.privateKey,
37
- + },
38
- + }, userId);
39
- + }
40
- });
41
- }
42
- encryptionKeyMigrationRequired(response) {
43
- @@ -28327,7 +28347,17 @@ class UserApiLoginStrategy extends LoginStrategy {
44
- }
45
- setAccountCryptographicState(response, userId) {
46
- return user_api_login_strategy_awaiter(this, void 0, void 0, function* () {
47
- - yield this.accountCryptographicStateService.setAccountCryptographicState(response.accountKeysResponseModel.toWrappedAccountCryptographicState(), userId);
48
- + /* icoretech-vaultwarden-compat */
49
- + if (response.accountKeysResponseModel) {
50
- + yield this.accountCryptographicStateService.setAccountCryptographicState(response.accountKeysResponseModel.toWrappedAccountCryptographicState(), userId);
51
- + }
52
- + else if (response.privateKey) {
53
- + yield this.accountCryptographicStateService.setAccountCryptographicState({
54
- + V1: {
55
- + private_key: response.privateKey,
56
- + },
57
- + }, userId);
58
- + }
59
- });
60
- }
61
- // Overridden to save client ID and secret to token service
62
- @@ -28457,7 +28487,17 @@ class WebAuthnLoginStrategy extends LoginStrategy {
63
- }
64
- setAccountCryptographicState(response, userId) {
65
- return webauthn_login_strategy_awaiter(this, void 0, void 0, function* () {
66
- - yield this.accountCryptographicStateService.setAccountCryptographicState(response.accountKeysResponseModel.toWrappedAccountCryptographicState(), userId);
67
- + /* icoretech-vaultwarden-compat */
68
- + if (response.accountKeysResponseModel) {
69
- + yield this.accountCryptographicStateService.setAccountCryptographicState(response.accountKeysResponseModel.toWrappedAccountCryptographicState(), userId);
70
- + }
71
- + else if (response.privateKey) {
72
- + yield this.accountCryptographicStateService.setAccountCryptographicState({
73
- + V1: {
74
- + private_key: response.privateKey,
75
- + },
76
- + }, userId);
77
- + }
78
- });
79
- }
80
- exportCache() {