add-mcp 1.5.1 → 1.6.0
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 +9 -0
- package/dist/index.js +55 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,6 +43,9 @@ npx add-mcp "npx -y @org/mcp-server --flag value"
|
|
|
43
43
|
# Node.js script
|
|
44
44
|
npx add-mcp "node /path/to/server.js --port 3000"
|
|
45
45
|
|
|
46
|
+
# Local stdio server with environment variables (repeatable)
|
|
47
|
+
npx add-mcp @modelcontextprotocol/server-filesystem --env "API_KEY=secret" --env "DATABASE_URL=postgres://localhost/app"
|
|
48
|
+
|
|
46
49
|
# Install for Cursor and Claude Code
|
|
47
50
|
npx add-mcp https://mcp.example.com/mcp -a cursor -a claude-code
|
|
48
51
|
|
|
@@ -68,6 +71,7 @@ npx add-mcp https://mcp.example.com/mcp -a cursor -y --gitignore
|
|
|
68
71
|
| `-t, --transport <type>` | Transport type for remote servers: `http` (default), `sse` |
|
|
69
72
|
| `--type <type>` | Alias for `--transport` |
|
|
70
73
|
| `--header <header>` | HTTP header for remote servers (repeatable, `Key: Value`) |
|
|
74
|
+
| `--env <env>` | Env var for local stdio servers (repeatable, `KEY=VALUE`) |
|
|
71
75
|
| `-n, --name <name>` | Server name (auto-inferred if not provided) |
|
|
72
76
|
| `-y, --yes` | Skip all confirmation prompts |
|
|
73
77
|
| `--all` | Install to all agents |
|
|
@@ -132,6 +136,11 @@ Note that some agents like Cursor and opencode do not require the `type` informa
|
|
|
132
136
|
Use `--header` to pass custom headers for remote servers. The flag can be repeated.
|
|
133
137
|
Header support is available for remote installs across all supported agents.
|
|
134
138
|
|
|
139
|
+
## Environment Variables
|
|
140
|
+
|
|
141
|
+
Use `--env` to pass environment variables for local stdio servers (packages/commands). The flag can be repeated and expects `KEY=VALUE`.
|
|
142
|
+
If `--env` is provided for a remote URL install, it is ignored with a warning.
|
|
143
|
+
|
|
135
144
|
## Supported Agents
|
|
136
145
|
|
|
137
146
|
MCP servers can be installed to any of these agents:
|
package/dist/index.js
CHANGED
|
@@ -946,28 +946,36 @@ function buildConfigWithKey(configKey, serverName, serverConfig) {
|
|
|
946
946
|
// src/installer.ts
|
|
947
947
|
function buildServerConfig(parsed, options = {}) {
|
|
948
948
|
if (parsed.type === "remote") {
|
|
949
|
-
const
|
|
949
|
+
const config2 = {
|
|
950
950
|
type: options.transport ?? "http",
|
|
951
951
|
url: parsed.value
|
|
952
952
|
};
|
|
953
953
|
if (options.headers && Object.keys(options.headers).length > 0) {
|
|
954
|
-
|
|
954
|
+
config2.headers = options.headers;
|
|
955
955
|
}
|
|
956
|
-
return
|
|
956
|
+
return config2;
|
|
957
957
|
}
|
|
958
958
|
if (parsed.type === "command") {
|
|
959
959
|
const parts = parsed.value.split(" ");
|
|
960
960
|
const command = parts[0];
|
|
961
961
|
const args = parts.slice(1);
|
|
962
|
-
|
|
962
|
+
const config2 = {
|
|
963
963
|
command,
|
|
964
964
|
args
|
|
965
965
|
};
|
|
966
|
+
if (options.env && Object.keys(options.env).length > 0) {
|
|
967
|
+
config2.env = options.env;
|
|
968
|
+
}
|
|
969
|
+
return config2;
|
|
966
970
|
}
|
|
967
|
-
|
|
971
|
+
const config = {
|
|
968
972
|
command: "npx",
|
|
969
973
|
args: ["-y", parsed.value]
|
|
970
974
|
};
|
|
975
|
+
if (options.env && Object.keys(options.env).length > 0) {
|
|
976
|
+
config.env = options.env;
|
|
977
|
+
}
|
|
978
|
+
return config;
|
|
971
979
|
}
|
|
972
980
|
function updateGitignoreWithPaths(paths, options = {}) {
|
|
973
981
|
const cwd = options.cwd || process.cwd();
|
|
@@ -1069,7 +1077,7 @@ function installServer(serverName, serverConfig, agentTypes, options = {}) {
|
|
|
1069
1077
|
// package.json
|
|
1070
1078
|
var package_default = {
|
|
1071
1079
|
name: "add-mcp",
|
|
1072
|
-
version: "1.
|
|
1080
|
+
version: "1.6.0",
|
|
1073
1081
|
description: "Add MCP servers to your favorite coding agents with a single command.",
|
|
1074
1082
|
author: "Andre Landgraf <andre@neon.tech>",
|
|
1075
1083
|
license: "Apache-2.0",
|
|
@@ -1205,6 +1213,25 @@ function parseHeaders(values) {
|
|
|
1205
1213
|
}
|
|
1206
1214
|
return { headers, invalid };
|
|
1207
1215
|
}
|
|
1216
|
+
function parseEnv(values) {
|
|
1217
|
+
const env = {};
|
|
1218
|
+
const invalid = [];
|
|
1219
|
+
for (const entry of values) {
|
|
1220
|
+
const separatorIndex = entry.indexOf("=");
|
|
1221
|
+
if (separatorIndex <= 0) {
|
|
1222
|
+
invalid.push(entry);
|
|
1223
|
+
continue;
|
|
1224
|
+
}
|
|
1225
|
+
const key = entry.slice(0, separatorIndex).trim();
|
|
1226
|
+
const value = entry.slice(separatorIndex + 1);
|
|
1227
|
+
if (!key) {
|
|
1228
|
+
invalid.push(entry);
|
|
1229
|
+
continue;
|
|
1230
|
+
}
|
|
1231
|
+
env[key] = value;
|
|
1232
|
+
}
|
|
1233
|
+
return { env, invalid };
|
|
1234
|
+
}
|
|
1208
1235
|
program.name("add-mcp").description(
|
|
1209
1236
|
"Install MCP servers for coding agents (Claude Code, Cursor, VS Code, OpenCode, Codex, and more \u2014 run list-agents for the full list)"
|
|
1210
1237
|
).version(version).argument("[target]", "MCP server URL (remote) or package name (local stdio)").option(
|
|
@@ -1221,6 +1248,11 @@ program.name("add-mcp").description(
|
|
|
1221
1248
|
"HTTP header for remote servers (repeatable, 'Key: Value')",
|
|
1222
1249
|
collect,
|
|
1223
1250
|
[]
|
|
1251
|
+
).option(
|
|
1252
|
+
"--env <env>",
|
|
1253
|
+
"Environment variable for local stdio servers (repeatable, 'KEY=VALUE')",
|
|
1254
|
+
collect,
|
|
1255
|
+
[]
|
|
1224
1256
|
).option("-y, --yes", "Skip confirmation prompts").option("--all", "Install to all agents").option("--gitignore", "Add generated project config files to .gitignore").action(async (target, options) => {
|
|
1225
1257
|
await main(target, options);
|
|
1226
1258
|
});
|
|
@@ -1321,6 +1353,21 @@ async function main(target, options) {
|
|
|
1321
1353
|
if (hasHeaderValues && !isRemote) {
|
|
1322
1354
|
p2.log.warn("--header is only used for remote URLs, ignoring");
|
|
1323
1355
|
}
|
|
1356
|
+
const envValues = options.env ?? [];
|
|
1357
|
+
const envResult = parseEnv(envValues);
|
|
1358
|
+
if (envResult.invalid.length > 0) {
|
|
1359
|
+
p2.log.error(
|
|
1360
|
+
`Invalid --env value(s): ${envResult.invalid.join(", ")}. Use "KEY=VALUE" format.`
|
|
1361
|
+
);
|
|
1362
|
+
process.exit(1);
|
|
1363
|
+
}
|
|
1364
|
+
const envKeys = Object.keys(envResult.env);
|
|
1365
|
+
const hasEnvValues = envKeys.length > 0;
|
|
1366
|
+
if (hasEnvValues && isRemote) {
|
|
1367
|
+
p2.log.warn(
|
|
1368
|
+
"--env is only used for local/package/command installs, ignoring"
|
|
1369
|
+
);
|
|
1370
|
+
}
|
|
1324
1371
|
const serverName = options.name || parsed.inferredName;
|
|
1325
1372
|
p2.log.info(`Server name: ${chalk.cyan(serverName)}`);
|
|
1326
1373
|
const transportValue = options.transport || options.type;
|
|
@@ -1340,7 +1387,8 @@ async function main(target, options) {
|
|
|
1340
1387
|
}
|
|
1341
1388
|
const serverConfig = buildServerConfig(parsed, {
|
|
1342
1389
|
transport: resolvedTransport,
|
|
1343
|
-
headers: isRemote && hasHeaderValues ? headerResult.headers : void 0
|
|
1390
|
+
headers: isRemote && hasHeaderValues ? headerResult.headers : void 0,
|
|
1391
|
+
env: !isRemote && hasEnvValues ? envResult.env : void 0
|
|
1344
1392
|
});
|
|
1345
1393
|
let targetAgents;
|
|
1346
1394
|
const allAgentTypes = getAgentTypes();
|