Skip to content

Commit dedce93

Browse files
authored
chore(devx): allow running vsix with local mcp proxy when building
point `MCPOWER_LOCAL_PROXY_PATH` env to the local directory containing mcpower proxy. For example: `MCPOWER_LOCAL_PROXY_PATH=/users/user/workspace/mcpower-proxy npm run package:vsc-extension` NOTE: the script replaces cursor hooks in-place. Need to make sure not to commit them once done working locally
1 parent 9ffc58f commit dedce93

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

targets/vsc-extension/.vscodeignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ tsconfig.json
99
__mocks__/**
1010
jest.config.js
1111
webpack.config.js
12+
scripts/clean-build.js
13+
scripts/update-gitleaks-rules.mjs
1214

1315
# Dependencies (bundled by webpack)
1416
node_modules/**

targets/vsc-extension/src/uvRunner.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ export class UvRunner {
3737
}
3838

3939
getCommand(): UvCommand {
40+
// If MCPOWER_LOCAL_PROXY_PATH is set, use the local proxy path
41+
if (process.env["MCPOWER_LOCAL_PROXY_PATH"]) {
42+
return {
43+
executable: "uv",
44+
args: ["run", "--directory", process.env["MCPOWER_LOCAL_PROXY_PATH"], "mcpower-proxy"],
45+
};
46+
}
47+
4048
if (!this.uvxCommand) {
4149
throw new Error("uvx command not available; initialize() first");
4250
}

targets/vsc-extension/webpack.config.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
const path = require("path");
22
const CopyWebpackPlugin = require("copy-webpack-plugin");
33
const TerserPlugin = require("terser-webpack-plugin");
4+
const { DefinePlugin } = require("webpack");
5+
6+
function getSafeEnvs() {
7+
const safeKeys = new Set(["CI", "NODE_ENV", "WEBPACK_MODE"]);
8+
const safePrefixes = ["MCPOWER_"];
9+
10+
return Object.entries(process.env).reduce((res, [key, value]) => {
11+
if (safeKeys.has(key) || safePrefixes.some(prefix => key.startsWith(prefix))) {
12+
console.log(`Defining env ${key} = ${value}`);
13+
res[key] = JSON.stringify(value);
14+
}
15+
return res;
16+
}, {});
17+
}
18+
19+
420

521
/** @type {import('webpack').Configuration} */
622
module.exports = {
@@ -59,6 +75,9 @@ module.exports = {
5975
],
6076
},
6177
plugins: [
78+
new DefinePlugin({
79+
"process.env": getSafeEnvs(),
80+
}),
6281
new CopyWebpackPlugin({
6382
patterns: [
6483
{
@@ -67,6 +86,23 @@ module.exports = {
6786
},
6887
],
6988
}),
89+
...(process.env["MCPOWER_LOCAL_PROXY_PATH"] ? [
90+
new CopyWebpackPlugin({
91+
patterns: [
92+
{
93+
from: path.resolve(__dirname, "./scripts/cursor/hooks"),
94+
to: path.resolve(__dirname, "./scripts/cursor/hooks"),
95+
transform(content, absolutePath ) {
96+
console.log(`Transforming ${absolutePath} with ${process.env["MCPOWER_LOCAL_PROXY_PATH"]}`);
97+
let text = content.toString();
98+
text = text.replace(/uvx mcpower-proxy==[0-9]*\.[0-9]*\.[0-9]*/g, `uv run --directory ${process.env["MCPOWER_LOCAL_PROXY_PATH"]} mcpower-proxy`);
99+
return Buffer.from(text);
100+
}
101+
},
102+
],
103+
104+
}),
105+
]: []),
70106
],
71107
devtool: false,
72108
infrastructureLogging: {

0 commit comments

Comments
 (0)