@kwonye/mcpx 0.1.75 → 0.1.77

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.
@@ -1,3 +1,6 @@
1
+ import { createRequire } from "node:module";
2
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+
1
4
  // src/types.ts
2
5
  function isServerEnabled(spec) {
3
6
  return spec.enabled !== false;
@@ -9,4 +12,4 @@ function normalizeServerSpecEnabled(spec) {
9
12
  };
10
13
  }
11
14
 
12
- export { isServerEnabled, normalizeServerSpecEnabled };
15
+ export { __require, isServerEnabled, normalizeServerSpecEnabled };
@@ -0,0 +1,187 @@
1
+ import {
2
+ getSecretNamesPath,
3
+ readJsonFile,
4
+ writeJsonAtomic
5
+ } from "./cli-fsf33sgp.js";
6
+ import {
7
+ __require,
8
+ normalizeServerSpecEnabled
9
+ } from "./cli-s4gspqdf.js";
10
+
11
+ // src/core/registry.ts
12
+ import path from "node:path";
13
+ function validateServerName(name) {
14
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,62}$/.test(name)) {
15
+ throw new Error("Invalid server name. Use 1-63 chars: letters, numbers, '.', '-', '_' and start with alphanumeric.");
16
+ }
17
+ }
18
+ function addServer(config, name, spec, force = false) {
19
+ validateServerName(name);
20
+ if (config.servers[name] && !force) {
21
+ throw new Error(`Server "${name}" already exists. Use --force to overwrite.`);
22
+ }
23
+ config.servers[name] = normalizeServerSpecEnabled(spec);
24
+ }
25
+ function removeServer(config, name, force = false) {
26
+ if (!config.servers[name] && !force) {
27
+ throw new Error(`Server "${name}" does not exist.`);
28
+ }
29
+ delete config.servers[name];
30
+ }
31
+ function updateServer(config, name, spec) {
32
+ validateServerName(name);
33
+ if (!config.servers[name]) {
34
+ throw new Error(`Server "${name}" does not exist.`);
35
+ }
36
+ config.servers[name] = normalizeServerSpecEnabled(spec);
37
+ }
38
+ function setServerEnabled(config, name, enabled) {
39
+ const existing = config.servers[name];
40
+ if (!existing) {
41
+ throw new Error(`Server "${name}" does not exist.`);
42
+ }
43
+ config.servers[name] = {
44
+ ...existing,
45
+ enabled
46
+ };
47
+ }
48
+ function getGatewayTokenSecretName(config) {
49
+ if (!config.gateway.tokenRef.startsWith("secret://")) {
50
+ return "local_gateway_token";
51
+ }
52
+ return config.gateway.tokenRef.slice("secret://".length) || "local_gateway_token";
53
+ }
54
+ function ensureGatewayToken(config, secrets) {
55
+ const secretName = getGatewayTokenSecretName(config);
56
+ const existing = secrets.getSecret(secretName);
57
+ if (existing) {
58
+ return existing;
59
+ }
60
+ return secrets.rotateLocalToken(secretName);
61
+ }
62
+ function registerProject(globalConfig, projectPath, name) {
63
+ if (!globalConfig.projects) {
64
+ globalConfig.projects = {};
65
+ }
66
+ const projectName = name?.trim() || path.basename(projectPath);
67
+ globalConfig.projects[projectPath] = {
68
+ name: projectName,
69
+ path: projectPath
70
+ };
71
+ }
72
+ function unregisterProject(globalConfig, projectPath) {
73
+ if (globalConfig.projects) {
74
+ delete globalConfig.projects[projectPath];
75
+ }
76
+ }
77
+
78
+ // src/core/secrets.ts
79
+ import crypto from "node:crypto";
80
+ import fs from "node:fs";
81
+ var keytarSync = null;
82
+ try {
83
+ const keytar = (()=>{throw new Error("Cannot require module "+"../node_modules/keytar/lib/keytar.js");})();
84
+ keytarSync = keytar;
85
+ } catch {
86
+ keytarSync = null;
87
+ }
88
+ function parseSecretRef(ref) {
89
+ if (!ref.startsWith("secret://")) {
90
+ return null;
91
+ }
92
+ const name = ref.slice("secret://".length);
93
+ return name.length > 0 ? name : null;
94
+ }
95
+
96
+ class SecretsManager {
97
+ service;
98
+ nameIndexPath;
99
+ constructor(service = "mcpx", nameIndexPath = getSecretNamesPath()) {
100
+ this.service = service;
101
+ this.nameIndexPath = nameIndexPath;
102
+ }
103
+ loadNameIndex() {
104
+ return readJsonFile(this.nameIndexPath, { names: [] });
105
+ }
106
+ saveNameIndex(index) {
107
+ const deduped = Array.from(new Set(index.names)).sort();
108
+ writeJsonAtomic(this.nameIndexPath, { names: deduped });
109
+ }
110
+ trackSecretName(name) {
111
+ const index = this.loadNameIndex();
112
+ if (!index.names.includes(name)) {
113
+ index.names.push(name);
114
+ this.saveNameIndex(index);
115
+ }
116
+ }
117
+ untrackSecretName(name) {
118
+ const index = this.loadNameIndex();
119
+ index.names = index.names.filter((entry) => entry !== name);
120
+ this.saveNameIndex(index);
121
+ }
122
+ listSecretNames() {
123
+ return this.loadNameIndex().names;
124
+ }
125
+ setSecret(name, value) {
126
+ if (keytarSync) {
127
+ keytarSync.setPassword(this.service, name, value);
128
+ } else {
129
+ throw new Error("Secret storage is unavailable: keytar native addon failed to load. " + "Install libsecret (Linux) or ensure Xcode CLI tools (macOS), then reinstall dependencies.");
130
+ }
131
+ this.trackSecretName(name);
132
+ }
133
+ removeSecret(name) {
134
+ if (keytarSync) {
135
+ try {
136
+ keytarSync.deletePassword(this.service, name);
137
+ } catch {}
138
+ }
139
+ this.untrackSecretName(name);
140
+ }
141
+ getSecret(name) {
142
+ const envOverride = process.env[`MCPX_SECRET_${name}`];
143
+ if (envOverride && envOverride.length > 0) {
144
+ return envOverride;
145
+ }
146
+ if (!keytarSync) {
147
+ return null;
148
+ }
149
+ try {
150
+ const value = keytarSync.getPassword(this.service, name);
151
+ if (typeof value === "string" && value.length > 0) {
152
+ return value;
153
+ }
154
+ return null;
155
+ } catch {
156
+ return null;
157
+ }
158
+ }
159
+ resolveMaybeSecret(value) {
160
+ const secretName = parseSecretRef(value);
161
+ if (!secretName) {
162
+ return value;
163
+ }
164
+ const secret = this.getSecret(secretName);
165
+ if (!secret) {
166
+ throw new Error(`Secret not found: ${secretName}`);
167
+ }
168
+ return secret;
169
+ }
170
+ rotateLocalToken(secretName = "local_gateway_token") {
171
+ const token = crypto.randomBytes(32).toString("base64url");
172
+ this.setSecret(secretName, token);
173
+ return token;
174
+ }
175
+ }
176
+ function readSecretValueFromStdin() {
177
+ if (process.stdin.isTTY) {
178
+ throw new Error("No value provided. Use --value or pipe a value via stdin.");
179
+ }
180
+ const content = fs.readFileSync(process.stdin.fd, "utf8").trim();
181
+ if (content.length === 0) {
182
+ throw new Error("Empty secret value provided.");
183
+ }
184
+ return content;
185
+ }
186
+
187
+ export { SecretsManager, readSecretValueFromStdin, validateServerName, addServer, removeServer, updateServer, setServerEnabled, getGatewayTokenSecretName, ensureGatewayToken, registerProject, unregisterProject };
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAm/CA,wBAAsB,MAAM,CAAC,IAAI,WAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAkE/D"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AA00DA,wBAAsB,MAAM,CAAC,IAAI,WAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAmE/D"}