@icoretech/warden-mcp 0.2.8 → 0.2.9
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 +3 -1
- package/dist/bw/bwCli.js +57 -34
- package/dist/bw/bwSession.js +8 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -403,9 +403,11 @@ The server executes `bw` commands on your behalf:
|
|
|
403
403
|
|
|
404
404
|
- In HTTP mode, Bitwarden/Vaultwarden connection + credentials are provided via **HTTP headers** per request. Env-var fallback is disabled by default; set `KEYCHAIN_ALLOW_ENV_FALLBACK=true` to enable it for single-tenant HTTP deployments.
|
|
405
405
|
- In stdio mode, Bitwarden/Vaultwarden credentials are loaded once from `BW_*` env vars at startup.
|
|
406
|
-
- The server maintains per-profile `bw` state under `KEYCHAIN_BW_HOME_ROOT`
|
|
406
|
+
- The server maintains per-profile `bw` state under `KEYCHAIN_BW_HOME_ROOT` and pins `BITWARDENCLI_APPDATA_DIR` inside that profile so the Bitwarden CLI keeps a stable local device/app identity across restarts instead of looking like a fresh client every time.
|
|
407
407
|
- Writes can optionally call `bw sync` (internal; not exposed as an MCP tool).
|
|
408
408
|
|
|
409
|
+
Timeout handling is also process-tree aware: if a `bw` command hangs, `warden-mcp` kills the full spawned process group rather than only the direct parent process. That prevents timed-out auth attempts from leaving orphaned `bw`/shell child processes behind.
|
|
410
|
+
|
|
409
411
|
### Required Headers
|
|
410
412
|
|
|
411
413
|
- `X-BW-Host` (must be an HTTPS origin, for example `https://vaultwarden.example.com`)
|
package/dist/bw/bwCli.js
CHANGED
|
@@ -52,9 +52,11 @@ export async function runBw(args, opts = {}) {
|
|
|
52
52
|
const rendered = safeRenderedArgs(finalArgs);
|
|
53
53
|
console.log(`[bw] start: ${bwBin} ${rendered}`);
|
|
54
54
|
}
|
|
55
|
+
const detached = process.platform !== 'win32';
|
|
55
56
|
const child = spawn(bwBin, finalArgs, {
|
|
56
57
|
env,
|
|
57
58
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
59
|
+
detached,
|
|
58
60
|
});
|
|
59
61
|
const stdoutChunks = [];
|
|
60
62
|
const stderrChunks = [];
|
|
@@ -64,54 +66,75 @@ export async function runBw(args, opts = {}) {
|
|
|
64
66
|
child.stdin.write(opts.stdin);
|
|
65
67
|
}
|
|
66
68
|
child.stdin.end();
|
|
67
|
-
let timeout;
|
|
68
69
|
const timeoutMs = opts.timeoutMs ?? 60_000;
|
|
69
|
-
const
|
|
70
|
-
|
|
70
|
+
const killChildProcessTree = () => {
|
|
71
|
+
if (typeof child.pid === 'number' && detached) {
|
|
71
72
|
try {
|
|
72
|
-
|
|
73
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
74
|
+
return;
|
|
73
75
|
}
|
|
74
76
|
catch {
|
|
75
|
-
//
|
|
77
|
+
// Fallback to direct child kill below.
|
|
76
78
|
}
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
child.kill('SIGKILL');
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// ignore
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
let settled = false;
|
|
89
|
+
const settle = (fn) => {
|
|
90
|
+
if (settled)
|
|
91
|
+
return;
|
|
92
|
+
settled = true;
|
|
93
|
+
if (timeout)
|
|
94
|
+
clearTimeout(timeout);
|
|
95
|
+
fn();
|
|
96
|
+
};
|
|
97
|
+
const timeout = setTimeout(() => {
|
|
98
|
+
killChildProcessTree();
|
|
77
99
|
if (debug) {
|
|
78
100
|
console.log(`[bw] timeout after ${timeoutMs}ms`);
|
|
79
101
|
}
|
|
80
|
-
|
|
102
|
+
settle(() => {
|
|
103
|
+
reject(new Error(`bw command timed out after ${timeoutMs}ms`));
|
|
104
|
+
});
|
|
81
105
|
}, timeoutMs);
|
|
82
|
-
});
|
|
83
|
-
const completed = new Promise((resolve, reject) => {
|
|
84
106
|
child.on('error', (error) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
107
|
+
settle(() => {
|
|
108
|
+
const safeCmd = `${bwBin} ${safeRenderedArgs(finalArgs)}`;
|
|
109
|
+
if (error.code === 'ENOENT') {
|
|
110
|
+
reject(new Error(`bw CLI not available for ${safeCmd}. Install @bitwarden/cli or set BW_BIN to a valid bw binary.`));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
reject(new Error(`Failed to start ${safeCmd}: ${error.message}`));
|
|
114
|
+
});
|
|
91
115
|
});
|
|
92
116
|
child.on('close', (code) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
117
|
+
settle(() => {
|
|
118
|
+
const stdout = Buffer.concat(stdoutChunks).toString('utf8');
|
|
119
|
+
const stderr = Buffer.concat(stderrChunks).toString('utf8');
|
|
120
|
+
const exitCode = code ?? 1;
|
|
121
|
+
if (exitCode !== 0) {
|
|
122
|
+
if (debug) {
|
|
123
|
+
console.log(`[bw] fail: exit=${exitCode} ms=${Date.now() - startedAt}`);
|
|
124
|
+
}
|
|
125
|
+
const safeCmd = `${bwBin} ${safeRenderedArgs(finalArgs)}`;
|
|
126
|
+
reject(new BwCliError(`${safeCmd} failed with exit code ${exitCode}`, {
|
|
127
|
+
exitCode,
|
|
128
|
+
stdout,
|
|
129
|
+
stderr,
|
|
130
|
+
}));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
99
133
|
if (debug) {
|
|
100
|
-
console.log(`[bw]
|
|
134
|
+
console.log(`[bw] ok: ms=${Date.now() - startedAt}`);
|
|
101
135
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
exitCode,
|
|
105
|
-
stdout,
|
|
106
|
-
stderr,
|
|
107
|
-
}));
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (debug) {
|
|
111
|
-
console.log(`[bw] ok: ms=${Date.now() - startedAt}`);
|
|
112
|
-
}
|
|
113
|
-
resolve({ stdout, stderr });
|
|
136
|
+
resolve({ stdout, stderr });
|
|
137
|
+
});
|
|
114
138
|
});
|
|
115
139
|
});
|
|
116
|
-
return Promise.race([completed, timedOut]);
|
|
117
140
|
}
|
package/dist/bw/bwSession.js
CHANGED
|
@@ -50,12 +50,18 @@ export class BwSessionManager {
|
|
|
50
50
|
keepaliveTimer = null;
|
|
51
51
|
configuredHost = null;
|
|
52
52
|
homeDir;
|
|
53
|
+
appDataDir;
|
|
53
54
|
constructor(env) {
|
|
54
55
|
this.env = env;
|
|
55
56
|
this.homeDir = env.homeDir ?? process.env.HOME ?? '/data';
|
|
57
|
+
this.appDataDir = join(this.homeDir, '.bitwarden-cli');
|
|
56
58
|
}
|
|
57
59
|
baseEnv(extra) {
|
|
58
|
-
return {
|
|
60
|
+
return {
|
|
61
|
+
HOME: this.homeDir,
|
|
62
|
+
BITWARDENCLI_APPDATA_DIR: this.appDataDir,
|
|
63
|
+
...(extra ?? {}),
|
|
64
|
+
};
|
|
59
65
|
}
|
|
60
66
|
// Must be called while holding `this.lock` (i.e. from within `withSession`).
|
|
61
67
|
async getTemplateItemLocked(session) {
|
|
@@ -157,6 +163,7 @@ export class BwSessionManager {
|
|
|
157
163
|
await runBw(['logout'], { env: this.baseEnv(), timeoutMs: 30_000 }).catch(() => { });
|
|
158
164
|
const home = this.homeDir;
|
|
159
165
|
const cliStateDirs = [
|
|
166
|
+
this.appDataDir,
|
|
160
167
|
join(home, '.config', 'Bitwarden CLI'),
|
|
161
168
|
join(home, 'Library', 'Application Support', 'Bitwarden CLI'),
|
|
162
169
|
join(home, 'AppData', 'Roaming', 'Bitwarden CLI'),
|
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
|
+
"version": "0.2.9",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Vaultwarden/Bitwarden MCP server backed by Bitwarden CLI (bw).",
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
"@bitwarden/cli": "2026.3.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@biomejs/biome": "^2.4.
|
|
55
|
+
"@biomejs/biome": "^2.4.12",
|
|
56
56
|
"@types/express": "^5.0.6",
|
|
57
|
-
"@types/node": "^25.
|
|
57
|
+
"@types/node": "^25.6.0",
|
|
58
58
|
"playwright": "1.59.1",
|
|
59
59
|
"tsx": "^4.21.0",
|
|
60
|
-
"typescript": "^6.0.
|
|
60
|
+
"typescript": "^6.0.3"
|
|
61
61
|
},
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"registry": "https://registry.npmjs.org",
|