deveco-mcp-server 0.1.6 → 0.1.7

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/index.js +80 -14
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -38,21 +38,87 @@ function getBinaryPaths() {
38
38
  };
39
39
  }
40
40
  } catch (err) {
41
- console.error(`Error: Platform package ${packageName} not found.`);
42
- console.error('Attempting to install platform package...');
41
+ console.error(`Platform package ${packageName} not found.`);
42
+ console.error('Installing platform package automatically...');
43
43
 
44
- // Try to install the platform package
45
44
  const { execSync } = require('child_process');
45
+ const os = require('os');
46
+
47
+ // Detect if we're in npx temporary directory
48
+ const isNpx = __dirname.includes('_npx') ||
49
+ __dirname.includes('npm-cache') ||
50
+ __dirname.includes('npx-') ||
51
+ process.env.npm_config_user_config;
52
+
53
+ let installDir = __dirname;
54
+ let binDir = null;
55
+
56
+ // If in npx, install to user's home directory cache
57
+ if (isNpx) {
58
+ const homeDir = os.homedir();
59
+ installDir = path.join(homeDir, '.deveco-mcp-cache');
60
+
61
+ // Create cache directory if it doesn't exist
62
+ if (!fs.existsSync(installDir)) {
63
+ fs.mkdirSync(installDir, { recursive: true });
64
+ }
65
+ }
66
+
46
67
  try {
47
- execSync(`npm install ${packageName}`, {
48
- stdio: 'inherit',
49
- cwd: __dirname
68
+ // Install the platform package
69
+ execSync(`npm install ${packageName}`, {
70
+ stdio: 'pipe',
71
+ cwd: installDir,
72
+ timeout: 60000 // 60 second timeout
50
73
  });
51
74
 
52
- // Try to resolve again
53
- const packagePath = require.resolve(packageName);
54
- const binDir = path.dirname(packagePath);
55
-
75
+ // Find the installed package
76
+ const nodeModulesPath = path.join(installDir, 'node_modules', packageName);
77
+ if (fs.existsSync(nodeModulesPath)) {
78
+ binDir = nodeModulesPath;
79
+ } else {
80
+ // Try to resolve using require
81
+ try {
82
+ const packagePath = require.resolve(packageName, { paths: [installDir] });
83
+ binDir = path.dirname(packagePath);
84
+ } catch (resolveErr) {
85
+ // If resolve fails, use the node_modules path directly
86
+ binDir = nodeModulesPath;
87
+ }
88
+ }
89
+ } catch (installErr) {
90
+ // Installation failed, try alternative: install to current directory
91
+ try {
92
+ execSync(`npm install ${packageName}`, {
93
+ stdio: 'pipe',
94
+ cwd: __dirname,
95
+ timeout: 60000
96
+ });
97
+
98
+ const localNodeModules = path.join(__dirname, 'node_modules', packageName);
99
+ if (fs.existsSync(localNodeModules)) {
100
+ binDir = localNodeModules;
101
+ } else {
102
+ throw installErr;
103
+ }
104
+ } catch (altErr) {
105
+ // All installation attempts failed
106
+ console.error('\n❌ Failed to install platform package automatically.');
107
+ console.error('\nPlease try one of the following:');
108
+ console.error(`\n1. Global install (recommended):`);
109
+ console.error(` npm install -g deveco-mcp-server`);
110
+ console.error(`\n2. Manual install:`);
111
+ console.error(` npm install -g ${packageName}`);
112
+ console.error(` npm install -g deveco-mcp-server`);
113
+ console.error(`\n3. Force reinstall:`);
114
+ console.error(` npm cache clean --force`);
115
+ console.error(` npm install -g deveco-mcp-server`);
116
+ process.exit(1);
117
+ }
118
+ }
119
+
120
+ // Use the installed package path
121
+ if (binDir && fs.existsSync(binDir)) {
56
122
  if (process.platform === 'win32') {
57
123
  return {
58
124
  server: path.join(binDir, 'deveco-mcp-server.exe'),
@@ -64,11 +130,11 @@ function getBinaryPaths() {
64
130
  toolbox: path.join(binDir, 'Contents', 'MacOS', 'deveco-toolbox')
65
131
  };
66
132
  }
67
- } catch (installErr) {
68
- console.error('Failed to install platform package automatically.');
69
- console.error('Please run: npm install --force');
70
- process.exit(1);
71
133
  }
134
+
135
+ // Should not reach here, but just in case
136
+ console.error('Failed to locate installed platform package.');
137
+ process.exit(1);
72
138
  }
73
139
  }
74
140
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deveco-mcp-server",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "NPM wrapper for deveco-mcp-server - HarmonyOS development MCP server with platform-specific binaries",
5
5
  "keywords": [
6
6
  "mcp",
@@ -16,8 +16,8 @@
16
16
  "deveco-mcp-server": "index.js"
17
17
  },
18
18
  "optionalDependencies": {
19
- "deveco-mcp-server-win32-x64": "0.1.6",
20
- "deveco-mcp-server-darwin-arm64": "0.1.6"
19
+ "deveco-mcp-server-win32-x64": "0.1.7",
20
+ "deveco-mcp-server-darwin-arm64": "0.1.7"
21
21
  },
22
22
  "repository": {
23
23
  "type": "git",