@icoretech/warden-mcp 0.2.0 → 0.2.2
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/bin/patch-bitwarden-cli-lib.js +36 -4
- package/bin/warden-mcp.js +24 -18
- package/dist/server.js +9 -4
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
2
|
+
import { existsSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
@@ -75,12 +75,31 @@ export function resolvePatchPackagePlan({
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
const bootstrapPackageJson = `${JSON.stringify(
|
|
79
|
+
{ name: 'warden-mcp-postinstall-bootstrap', private: true },
|
|
80
|
+
null,
|
|
81
|
+
2,
|
|
82
|
+
)}\n`;
|
|
83
|
+
|
|
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;
|
|
93
|
+
}
|
|
94
|
+
|
|
78
95
|
export function applyBundledBwPatch({
|
|
79
96
|
packageDir = defaultPackageDir,
|
|
80
97
|
resolveDependency,
|
|
81
98
|
exists,
|
|
82
99
|
spawn = spawnSync,
|
|
83
100
|
nodeExecPath = process.execPath,
|
|
101
|
+
writeFile,
|
|
102
|
+
removeFile = (path) => rmSync(path, { force: true }),
|
|
84
103
|
logError = (message) => console.error(message),
|
|
85
104
|
} = {}) {
|
|
86
105
|
let plan;
|
|
@@ -97,11 +116,24 @@ export function applyBundledBwPatch({
|
|
|
97
116
|
|
|
98
117
|
if (!plan) return 0;
|
|
99
118
|
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
119
|
+
const temporaryPackageJsonPath = ensurePatchPackageAppRoot({
|
|
120
|
+
appRoot: plan.cwd,
|
|
121
|
+
exists,
|
|
122
|
+
writeFile,
|
|
103
123
|
});
|
|
104
124
|
|
|
125
|
+
let result;
|
|
126
|
+
try {
|
|
127
|
+
result = spawn(nodeExecPath, plan.args, {
|
|
128
|
+
cwd: plan.cwd,
|
|
129
|
+
stdio: 'inherit',
|
|
130
|
+
});
|
|
131
|
+
} finally {
|
|
132
|
+
if (temporaryPackageJsonPath) {
|
|
133
|
+
removeFile(temporaryPackageJsonPath);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
105
137
|
if (result.error) {
|
|
106
138
|
logError(
|
|
107
139
|
`[warden-mcp] failed to execute patch-package: ${result.error.message}`,
|
package/bin/warden-mcp.js
CHANGED
|
@@ -8,24 +8,30 @@ import { fileURLToPath } from 'node:url';
|
|
|
8
8
|
|
|
9
9
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
prepareBwStartup(
|
|
11
|
+
async function main() {
|
|
12
|
+
const startupPath = resolve(__dirname, '../dist/startup/bwStartup.js');
|
|
13
|
+
if (!existsSync(startupPath)) {
|
|
14
|
+
console.error(
|
|
15
|
+
'[warden-mcp] ERROR: dist/startup/bwStartup.js not found. Run `npm run build` first.',
|
|
16
|
+
);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
const { prepareBwStartup } = await import(startupPath);
|
|
20
|
+
prepareBwStartup(process.env);
|
|
21
|
+
|
|
22
|
+
// Delegate to the compiled server entry, forwarding all arguments.
|
|
23
|
+
const serverPath = resolve(__dirname, '../dist/server.js');
|
|
24
|
+
if (!existsSync(serverPath)) {
|
|
25
|
+
console.error(
|
|
26
|
+
'[warden-mcp] ERROR: dist/server.js not found. Run `npm run build` first.',
|
|
27
|
+
);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
20
30
|
|
|
21
|
-
|
|
22
|
-
const serverPath = resolve(__dirname, '../dist/server.js');
|
|
23
|
-
if (!existsSync(serverPath)) {
|
|
24
|
-
console.error(
|
|
25
|
-
'[warden-mcp] ERROR: dist/server.js not found. Run `npm run build` first.',
|
|
26
|
-
);
|
|
27
|
-
process.exit(1);
|
|
31
|
+
await import(serverPath);
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
void main().catch((error) => {
|
|
35
|
+
console.error(error);
|
|
36
|
+
process.exitCode = 1;
|
|
37
|
+
});
|
package/dist/server.js
CHANGED
|
@@ -10,10 +10,11 @@ const { values } = parseArgs({
|
|
|
10
10
|
strict: false,
|
|
11
11
|
});
|
|
12
12
|
const useStdio = values.stdio === true || process.env.WARDEN_MCP_STDIO === 'true';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
async function main() {
|
|
14
|
+
if (useStdio) {
|
|
15
|
+
await runStdioTransport();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
17
18
|
const PORT = Number.parseInt(process.env.PORT ?? '3005', 10);
|
|
18
19
|
const app = createKeychainApp();
|
|
19
20
|
const server = app.listen(PORT, () => {
|
|
@@ -24,3 +25,7 @@ else {
|
|
|
24
25
|
server.once('error', reject);
|
|
25
26
|
});
|
|
26
27
|
}
|
|
28
|
+
void main().catch((error) => {
|
|
29
|
+
console.error(error);
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
});
|