@wonderwhy-er/desktop-commander 0.2.3 → 0.2.4

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 (43) hide show
  1. package/README.md +25 -3
  2. package/dist/config-manager.d.ts +10 -0
  3. package/dist/config-manager.js +7 -1
  4. package/dist/handlers/edit-search-handlers.js +25 -6
  5. package/dist/handlers/terminal-handlers.d.ts +8 -4
  6. package/dist/handlers/terminal-handlers.js +16 -10
  7. package/dist/index-dxt.d.ts +2 -0
  8. package/dist/index-dxt.js +76 -0
  9. package/dist/index-with-startup-detection.d.ts +5 -0
  10. package/dist/index-with-startup-detection.js +180 -0
  11. package/dist/server.d.ts +5 -0
  12. package/dist/server.js +343 -42
  13. package/dist/terminal-manager.d.ts +7 -0
  14. package/dist/terminal-manager.js +93 -18
  15. package/dist/tools/client.d.ts +10 -0
  16. package/dist/tools/client.js +13 -0
  17. package/dist/tools/config.d.ts +1 -1
  18. package/dist/tools/config.js +21 -3
  19. package/dist/tools/edit.js +4 -3
  20. package/dist/tools/environment.d.ts +55 -0
  21. package/dist/tools/environment.js +65 -0
  22. package/dist/tools/feedback.d.ts +8 -0
  23. package/dist/tools/feedback.js +132 -0
  24. package/dist/tools/filesystem.js +152 -57
  25. package/dist/tools/improved-process-tools.js +170 -29
  26. package/dist/tools/schemas.d.ts +20 -2
  27. package/dist/tools/schemas.js +20 -2
  28. package/dist/tools/usage.d.ts +5 -0
  29. package/dist/tools/usage.js +24 -0
  30. package/dist/utils/capture.js +23 -1
  31. package/dist/utils/early-logger.d.ts +4 -0
  32. package/dist/utils/early-logger.js +35 -0
  33. package/dist/utils/mcp-logger.d.ts +30 -0
  34. package/dist/utils/mcp-logger.js +59 -0
  35. package/dist/utils/smithery-detector.d.ts +94 -0
  36. package/dist/utils/smithery-detector.js +292 -0
  37. package/dist/utils/startup-detector.d.ts +65 -0
  38. package/dist/utils/startup-detector.js +390 -0
  39. package/dist/utils/usageTracker.d.ts +85 -0
  40. package/dist/utils/usageTracker.js +280 -0
  41. package/dist/version.d.ts +1 -1
  42. package/dist/version.js +1 -1
  43. package/package.json +3 -1
@@ -0,0 +1,292 @@
1
+ /**
2
+ * Smithery CLI Detection Module
3
+ *
4
+ * Detects when a Node.js MCP server is being run through Smithery CLI
5
+ * which acts as a proxy/wrapper around MCP servers.
6
+ */
7
+ import { platform } from 'os';
8
+ export class SmitheryDetector {
9
+ constructor() {
10
+ this._detectionInfo = null;
11
+ }
12
+ static getInstance() {
13
+ if (!SmitheryDetector.instance) {
14
+ SmitheryDetector.instance = new SmitheryDetector();
15
+ }
16
+ return SmitheryDetector.instance;
17
+ }
18
+ /**
19
+ * Get Smithery detection information (cached after first call)
20
+ */
21
+ getSmitheryInfo() {
22
+ if (!this._detectionInfo) {
23
+ this._detectionInfo = this.detectSmithery();
24
+ }
25
+ return this._detectionInfo;
26
+ }
27
+ /**
28
+ * Force re-detection (useful for testing)
29
+ */
30
+ forceRedetect() {
31
+ this._detectionInfo = this.detectSmithery();
32
+ return this._detectionInfo;
33
+ }
34
+ detectSmithery() {
35
+ const result = {
36
+ isSmithery: false,
37
+ confidence: 0,
38
+ evidence: [],
39
+ details: {}
40
+ };
41
+ // Method 1: Check for Smithery-specific environment variables
42
+ this.checkSmitheryEnvironmentVars(result);
43
+ // Method 2: Check process arguments for Smithery patterns
44
+ this.checkProcessArguments(result);
45
+ // Method 3: Check parent process for Smithery CLI
46
+ this.checkParentProcess(result);
47
+ // Method 4: Check for Smithery runtime environment patterns
48
+ this.checkRuntimeEnvironment(result);
49
+ // Method 5: Check for analytics/session indicators
50
+ this.checkAnalyticsIndicators(result);
51
+ // Method 6: Check for MCP SDK transport patterns
52
+ this.checkTransportPatterns(result);
53
+ // Method 7: Check stdio patterns
54
+ this.checkStdioPatterns(result);
55
+ // Set final determination
56
+ result.isSmithery = result.confidence >= 30;
57
+ return result;
58
+ }
59
+ /**
60
+ * Check for Smithery-specific environment variables
61
+ */
62
+ checkSmitheryEnvironmentVars(result) {
63
+ const smitheryEnvVars = [
64
+ 'SMITHERY_SESSION_ID',
65
+ 'SMITHERY_API_KEY',
66
+ 'SMITHERY_CLIENT',
67
+ 'SMITHERY_PROFILE',
68
+ 'SMITHERY_ANALYTICS',
69
+ 'SMITHERY_RUNTIME',
70
+ 'REGISTRY_ENDPOINT',
71
+ 'ANALYTICS_ENDPOINT'
72
+ ];
73
+ for (const envVar of smitheryEnvVars) {
74
+ if (process.env[envVar]) {
75
+ result.confidence += 40;
76
+ result.evidence.push(`Smithery environment variable: ${envVar}`);
77
+ // Extract specific details
78
+ switch (envVar) {
79
+ case 'SMITHERY_SESSION_ID':
80
+ result.details.sessionId = process.env[envVar];
81
+ break;
82
+ case 'SMITHERY_CLIENT':
83
+ result.details.clientType = process.env[envVar];
84
+ break;
85
+ case 'SMITHERY_PROFILE':
86
+ result.details.profile = process.env[envVar];
87
+ break;
88
+ case 'SMITHERY_ANALYTICS':
89
+ result.details.analyticsEnabled = process.env[envVar] === 'true';
90
+ break;
91
+ case 'SMITHERY_RUNTIME':
92
+ result.details.runtimeEnvironment = process.env[envVar];
93
+ break;
94
+ }
95
+ }
96
+ }
97
+ // Check for Smithery endpoints
98
+ if (process.env.REGISTRY_ENDPOINT?.includes('smithery')) {
99
+ result.confidence += 30;
100
+ result.evidence.push('Smithery registry endpoint detected');
101
+ }
102
+ if (process.env.ANALYTICS_ENDPOINT?.includes('smithery')) {
103
+ result.confidence += 25;
104
+ result.evidence.push('Smithery analytics endpoint detected');
105
+ }
106
+ }
107
+ /**
108
+ * Check process arguments for Smithery patterns
109
+ */
110
+ checkProcessArguments(result) {
111
+ const args = process.argv.join(' ');
112
+ // Check for common Smithery CLI patterns
113
+ const smitheryPatterns = [
114
+ /smithery[\s\/\\]cli/i,
115
+ /@smithery[\s\/\\]cli/i,
116
+ /npx.*@smithery/i,
117
+ /smithery.*run/i,
118
+ /smithery.*install/i
119
+ ];
120
+ for (const pattern of smitheryPatterns) {
121
+ if (pattern.test(args)) {
122
+ result.confidence += 35;
123
+ result.evidence.push(`Smithery CLI pattern in arguments: ${pattern.source}`);
124
+ }
125
+ }
126
+ // Check for typical Smithery command structure
127
+ if (args.includes('--config') && args.includes('--client')) {
128
+ result.confidence += 20;
129
+ result.evidence.push('Smithery-style CLI arguments detected');
130
+ }
131
+ }
132
+ /**
133
+ * Check parent process for Smithery CLI
134
+ */
135
+ checkParentProcess(result) {
136
+ try {
137
+ if (platform() === 'darwin' || platform() === 'linux') {
138
+ const { execSync } = require('child_process');
139
+ const ppid = process.ppid;
140
+ if (ppid) {
141
+ // Get parent process command line
142
+ const parentCmd = execSync(`ps -p ${ppid} -o command=`, {
143
+ encoding: 'utf8',
144
+ timeout: 1000
145
+ }).trim();
146
+ if (parentCmd.includes('smithery') || parentCmd.includes('@smithery/cli')) {
147
+ result.confidence += 50;
148
+ result.evidence.push(`Parent process is Smithery CLI: ${parentCmd}`);
149
+ }
150
+ if (parentCmd.includes('node') && parentCmd.includes('npx')) {
151
+ result.confidence += 15;
152
+ result.evidence.push('Parent process shows npx execution pattern');
153
+ }
154
+ }
155
+ }
156
+ }
157
+ catch (error) {
158
+ // Ignore errors, parent process detection is best-effort
159
+ }
160
+ }
161
+ /**
162
+ * Check for Smithery runtime environment patterns
163
+ */
164
+ checkRuntimeEnvironment(result) {
165
+ // Check working directory for Smithery artifacts
166
+ const cwd = process.cwd();
167
+ if (cwd.includes('.smithery') || cwd.includes('smithery-cli')) {
168
+ result.confidence += 25;
169
+ result.evidence.push('Working directory indicates Smithery environment');
170
+ }
171
+ // Check for typical Smithery PATH modifications
172
+ const path = process.env.PATH || '';
173
+ if (path.includes('smithery') || path.includes('.smithery')) {
174
+ result.confidence += 20;
175
+ result.evidence.push('PATH contains Smithery directories');
176
+ }
177
+ // Check for Smithery-injected NODE_OPTIONS or similar
178
+ if (process.env.NODE_OPTIONS?.includes('smithery')) {
179
+ result.confidence += 30;
180
+ result.evidence.push('NODE_OPTIONS indicates Smithery runtime');
181
+ }
182
+ }
183
+ /**
184
+ * Check for analytics and session indicators
185
+ */
186
+ checkAnalyticsIndicators(result) {
187
+ // Check for UUID v7 pattern in environment (Smithery uses uuidv7 for sessions)
188
+ const envVars = Object.keys(process.env);
189
+ for (const key of envVars) {
190
+ const value = process.env[key] || '';
191
+ // UUID v7 pattern: 8-4-4-4-12 hex characters starting with timestamp
192
+ if (/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)) {
193
+ result.confidence += 25;
194
+ result.evidence.push(`UUID v7 session ID pattern detected: ${key}`);
195
+ result.details.sessionId = value;
196
+ }
197
+ }
198
+ // Check for Smithery analytics patterns
199
+ if (process.env.SMITHERY_ANALYTICS_CONSENT) {
200
+ result.confidence += 20;
201
+ result.evidence.push('Smithery analytics consent setting detected');
202
+ }
203
+ }
204
+ /**
205
+ * Check for MCP transport patterns that indicate Smithery
206
+ */
207
+ checkTransportPatterns(result) {
208
+ // Check for environment variables that suggest MCP transport through Smithery
209
+ if (process.env.MCP_TRANSPORT_TYPE) {
210
+ result.confidence += 15;
211
+ result.evidence.push('MCP transport type specification detected');
212
+ result.details.connectionType = process.env.MCP_TRANSPORT_TYPE;
213
+ }
214
+ // Check for Smithery's specific transport configurations
215
+ if (process.env.SMITHERY_CONNECTION_TYPE) {
216
+ result.confidence += 35;
217
+ result.evidence.push('Smithery connection type detected');
218
+ result.details.connectionType = process.env.SMITHERY_CONNECTION_TYPE;
219
+ }
220
+ // Check for server qualification patterns
221
+ if (process.env.SMITHERY_QUALIFIED_NAME || process.env.MCP_SERVER_NAME) {
222
+ result.confidence += 30;
223
+ result.evidence.push('MCP server qualification detected');
224
+ result.details.qualifiedName = process.env.SMITHERY_QUALIFIED_NAME || process.env.MCP_SERVER_NAME;
225
+ }
226
+ }
227
+ /**
228
+ * Check stdio patterns that suggest Smithery proxying
229
+ */
230
+ checkStdioPatterns(result) {
231
+ // Check if stdin/stdout are being piped in a way consistent with Smithery
232
+ if (!process.stdin.isTTY && !process.stdout.isTTY) {
233
+ result.confidence += 10;
234
+ result.evidence.push('Non-TTY stdio suggests proxied execution');
235
+ }
236
+ // Check for JSON-RPC message patterns in environment
237
+ if (process.env.MCP_JSONRPC_VERSION) {
238
+ result.confidence += 15;
239
+ result.evidence.push('JSON-RPC version specification detected');
240
+ }
241
+ // Check for Smithery's specific stdio handling
242
+ if (process.env.SMITHERY_STDIO_BUFFER_SIZE || process.env.SMITHERY_MESSAGE_TIMEOUT) {
243
+ result.confidence += 25;
244
+ result.evidence.push('Smithery stdio configuration detected');
245
+ }
246
+ }
247
+ /**
248
+ * Check if running through Smithery (convenience method)
249
+ */
250
+ isSmithery() {
251
+ return this.getSmitheryInfo().isSmithery;
252
+ }
253
+ /**
254
+ * Get the client type if running through Smithery
255
+ */
256
+ getClientType() {
257
+ return this.getSmitheryInfo().details.clientType;
258
+ }
259
+ /**
260
+ * Get the connection type if running through Smithery
261
+ */
262
+ getConnectionType() {
263
+ return this.getSmitheryInfo().details.connectionType;
264
+ }
265
+ /**
266
+ * Get analytics status if running through Smithery
267
+ */
268
+ isAnalyticsEnabled() {
269
+ return this.getSmitheryInfo().details.analyticsEnabled;
270
+ }
271
+ /**
272
+ * Get session ID if running through Smithery
273
+ */
274
+ getSessionId() {
275
+ return this.getSmitheryInfo().details.sessionId;
276
+ }
277
+ /**
278
+ * Get server qualified name if running through Smithery
279
+ */
280
+ getQualifiedName() {
281
+ return this.getSmitheryInfo().details.qualifiedName;
282
+ }
283
+ }
284
+ // Singleton instance
285
+ export const smitheryDetector = SmitheryDetector.getInstance();
286
+ // Convenience functions
287
+ export const getSmitheryInfo = () => smitheryDetector.getSmitheryInfo();
288
+ export const isSmithery = () => smitheryDetector.isSmithery();
289
+ export const getSmitheryClientType = () => smitheryDetector.getClientType();
290
+ export const getSmitheryConnectionType = () => smitheryDetector.getConnectionType();
291
+ export const getSmitherySessionId = () => smitheryDetector.getSessionId();
292
+ export const isSmitheryAnalyticsEnabled = () => smitheryDetector.isAnalyticsEnabled();
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Production-Ready Startup Detection Module
3
+ *
4
+ * This module provides a lightweight, production-ready way to detect
5
+ * how a Node.js application was started. Perfect for logging, analytics,
6
+ * or conditional behavior based on startup method.
7
+ */
8
+ export interface StartupInfo {
9
+ method: 'npm-run' | 'npx' | 'docker' | 'node-direct' | 'ci-cd' | 'smithery' | 'unknown';
10
+ confidence: number;
11
+ details: {
12
+ npmScript?: string;
13
+ ciPlatform?: string;
14
+ dockerContainer?: boolean;
15
+ smitheryClient?: string;
16
+ smitheryConnection?: string;
17
+ smitherySession?: string;
18
+ evidence: string[];
19
+ };
20
+ environment: 'development' | 'production' | 'ci' | 'container' | 'smithery' | 'unknown';
21
+ }
22
+ export declare class StartupDetector {
23
+ private static instance;
24
+ private _startupInfo;
25
+ private constructor();
26
+ static getInstance(): StartupDetector;
27
+ /**
28
+ * Get startup information (cached after first call)
29
+ */
30
+ getStartupInfo(): StartupInfo;
31
+ /**
32
+ * Force re-detection (useful for testing)
33
+ */
34
+ forceRedetect(): StartupInfo;
35
+ private detectStartupMethod;
36
+ private detectNpmRun;
37
+ private detectNpx;
38
+ private detectDocker;
39
+ private detectCiCd;
40
+ private detectDirectNode;
41
+ private detectSmithery;
42
+ private detectEnvironment;
43
+ /**
44
+ * Get a simple string representation of how the app was started
45
+ */
46
+ getStartupMethodString(): string;
47
+ /**
48
+ * Check if running in a specific environment
49
+ */
50
+ isEnvironment(env: StartupInfo['environment']): boolean;
51
+ /**
52
+ * Check if running via a specific method
53
+ */
54
+ isMethod(method: StartupInfo['method']): boolean;
55
+ }
56
+ export declare const startupDetector: StartupDetector;
57
+ export declare const getStartupInfo: () => StartupInfo;
58
+ export declare const getStartupMethod: () => string;
59
+ export declare const isProduction: () => boolean;
60
+ export declare const isDevelopment: () => boolean;
61
+ export declare const isDocker: () => boolean;
62
+ export declare const isCi: () => boolean;
63
+ export declare const isSmithery: () => boolean;
64
+ export declare const getSmitheryClient: () => string | undefined;
65
+ export declare const getSmitheryConnection: () => string | undefined;