troxy-cli 1.3.3 → 1.3.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/init.js +70 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "troxy-cli",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "AI payment control — protect your agent's payments with policies",
5
5
  "type": "module",
6
6
  "bin": {
package/src/init.js CHANGED
@@ -15,6 +15,7 @@ function prompt(question) {
15
15
  const MCP_CLIENTS = [
16
16
  {
17
17
  name: 'Claude Desktop',
18
+ type: 'standard',
18
19
  path: {
19
20
  darwin: path.join(os.homedir(), 'Library/Application Support/Claude/claude_desktop_config.json'),
20
21
  win32: path.join(process.env.APPDATA || os.homedir(), 'Claude/claude_desktop_config.json'),
@@ -23,6 +24,7 @@ const MCP_CLIENTS = [
23
24
  },
24
25
  {
25
26
  name: 'Cursor',
27
+ type: 'standard',
26
28
  path: {
27
29
  darwin: path.join(os.homedir(), '.cursor/mcp.json'),
28
30
  win32: path.join(os.homedir(), '.cursor/mcp.json'),
@@ -31,12 +33,31 @@ const MCP_CLIENTS = [
31
33
  },
32
34
  {
33
35
  name: 'Windsurf',
36
+ type: 'standard',
34
37
  path: {
35
38
  darwin: path.join(os.homedir(), '.codeium/windsurf/mcp_config.json'),
36
39
  win32: path.join(os.homedir(), '.codeium/windsurf/mcp_config.json'),
37
40
  linux: path.join(os.homedir(), '.codeium/windsurf/mcp_config.json'),
38
41
  },
39
42
  },
43
+ {
44
+ name: 'Zed',
45
+ type: 'zed',
46
+ path: {
47
+ darwin: path.join(os.homedir(), 'Library/Application Support/Zed/settings.json'),
48
+ win32: path.join(process.env.APPDATA || os.homedir(), 'Zed/settings.json'),
49
+ linux: path.join(os.homedir(), '.config/zed/settings.json'),
50
+ },
51
+ },
52
+ {
53
+ name: 'Continue',
54
+ type: 'continue',
55
+ path: {
56
+ darwin: path.join(os.homedir(), '.continue/config.json'),
57
+ win32: path.join(os.homedir(), '.continue/config.json'),
58
+ linux: path.join(os.homedir(), '.continue/config.json'),
59
+ },
60
+ },
40
61
  ];
41
62
 
42
63
  export async function runInit({ key } = {}) {
@@ -89,8 +110,15 @@ export async function runInit({ key } = {}) {
89
110
  return fs.existsSync(p);
90
111
  });
91
112
 
92
- if (detected.length === 0) {
93
- console.log('\n No MCP clients detected (Claude Desktop, Cursor, Windsurf).');
113
+ // Detect OpenClaw via CLI
114
+ let hasOpenClaw = false;
115
+ try {
116
+ execSync('openclaw --version', { stdio: 'ignore' });
117
+ hasOpenClaw = true;
118
+ } catch {}
119
+
120
+ if (detected.length === 0 && !hasOpenClaw) {
121
+ console.log('\n No MCP clients detected (Claude Desktop, Cursor, Windsurf, OpenClaw).');
94
122
  console.log(' Troxy MCP server config:\n');
95
123
  console.log(JSON.stringify(mcpEntry(key), null, 4));
96
124
  console.log('\n Add the above to your MCP client\'s config under "mcpServers".\n');
@@ -99,12 +127,23 @@ export async function runInit({ key } = {}) {
99
127
  for (const client of detected) {
100
128
  const configPath = client.path[platform] ?? client.path.linux;
101
129
  try {
102
- patchMcpConfig(configPath, key);
130
+ if (client.type === 'zed') patchZedConfig(configPath, key);
131
+ else if (client.type === 'continue') patchContinueConfig(configPath, key);
132
+ else patchMcpConfig(configPath, key);
103
133
  console.log(` • ${client.name} ✓`);
104
134
  } catch (err) {
105
135
  console.log(` • ${client.name} ✗ (${err.message})`);
106
136
  }
107
137
  }
138
+ if (hasOpenClaw) {
139
+ try {
140
+ const entry = JSON.stringify({ command: 'npx', args: ['troxy-cli', 'mcp'], env: { TROXY_API_KEY: key } });
141
+ execSync(`openclaw mcp set troxy '${entry}'`, { stdio: 'ignore' });
142
+ console.log(` • OpenClaw ✓`);
143
+ } catch (err) {
144
+ console.log(` • OpenClaw ✗ (${err.message})`);
145
+ }
146
+ }
108
147
  console.log('\n Restart your MCP client to activate Troxy.');
109
148
  }
110
149
 
@@ -205,14 +244,36 @@ function mcpEntry(apiKey) {
205
244
 
206
245
  function patchMcpConfig(configPath, apiKey) {
207
246
  let config = {};
208
- try {
209
- config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
210
- } catch {
211
- // file exists but is empty or malformed — start fresh
212
- }
213
-
247
+ try { config = JSON.parse(fs.readFileSync(configPath, 'utf8')); } catch {}
214
248
  if (!config.mcpServers) config.mcpServers = {};
215
249
  config.mcpServers.troxy = mcpEntry(apiKey).troxy;
250
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
251
+ }
216
252
 
253
+ function patchZedConfig(configPath, apiKey) {
254
+ let config = {};
255
+ try { config = JSON.parse(fs.readFileSync(configPath, 'utf8')); } catch {}
256
+ if (!config.context_servers) config.context_servers = {};
257
+ config.context_servers.troxy = {
258
+ source: 'custom',
259
+ command: 'npx',
260
+ args: ['troxy-cli', 'mcp'],
261
+ env: { TROXY_API_KEY: apiKey },
262
+ };
263
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
264
+ }
265
+
266
+ function patchContinueConfig(configPath, apiKey) {
267
+ let config = {};
268
+ try { config = JSON.parse(fs.readFileSync(configPath, 'utf8')); } catch {}
269
+ if (!config.modelContextProtocolServers) config.modelContextProtocolServers = [];
270
+ // Remove existing troxy entry if present, then add fresh
271
+ config.modelContextProtocolServers = config.modelContextProtocolServers.filter(
272
+ s => !(s.transport?.command === 'npx' && s.transport?.args?.includes('troxy-cli')),
273
+ );
274
+ config.modelContextProtocolServers.push({
275
+ transport: { type: 'stdio', command: 'npx', args: ['troxy-cli', 'mcp'] },
276
+ env: { TROXY_API_KEY: apiKey },
277
+ });
217
278
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
218
279
  }