deveco-mcp-server 0.1.6 → 0.1.8
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/index.js +130 -17
- package/package.json +5 -4
package/index.js
CHANGED
|
@@ -41,34 +41,147 @@ function getBinaryPaths() {
|
|
|
41
41
|
console.error(`Error: Platform package ${packageName} not found.`);
|
|
42
42
|
console.error('Attempting to install platform package...');
|
|
43
43
|
|
|
44
|
-
//
|
|
44
|
+
// 检查 npm 镜像源(仅提示,不影响安装)
|
|
45
|
+
try {
|
|
46
|
+
const { execSync } = require('child_process');
|
|
47
|
+
const registry = execSync('npm config get registry', { encoding: 'utf-8' }).trim();
|
|
48
|
+
if (!registry.includes('npmjs.org')) {
|
|
49
|
+
console.warn(`\n⚠️ Detected non-official npm registry: ${registry}`);
|
|
50
|
+
console.warn('Auto-install will use official registry (https://registry.npmjs.org/) to ensure package availability.\n');
|
|
51
|
+
}
|
|
52
|
+
} catch (regErr) {
|
|
53
|
+
// 忽略检查错误
|
|
54
|
+
}
|
|
55
|
+
|
|
45
56
|
const { execSync } = require('child_process');
|
|
57
|
+
const os = require('os');
|
|
58
|
+
|
|
59
|
+
// Detect if we're in npx temporary directory
|
|
60
|
+
const isNpx = __dirname.includes('_npx') ||
|
|
61
|
+
__dirname.includes('npm-cache') ||
|
|
62
|
+
__dirname.includes('npx-') ||
|
|
63
|
+
process.env.npm_config_user_config;
|
|
64
|
+
|
|
65
|
+
let installDir = __dirname;
|
|
66
|
+
let binDir = null;
|
|
67
|
+
|
|
68
|
+
// If in npx, install to user's home directory cache
|
|
69
|
+
if (isNpx) {
|
|
70
|
+
const homeDir = os.homedir();
|
|
71
|
+
installDir = path.join(homeDir, '.deveco-mcp-cache');
|
|
72
|
+
|
|
73
|
+
// Create cache directory if it doesn't exist
|
|
74
|
+
if (!fs.existsSync(installDir)) {
|
|
75
|
+
fs.mkdirSync(installDir, { recursive: true });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
46
79
|
try {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
80
|
+
// Install the platform package with official registry (ignore output to avoid JSON parsing errors)
|
|
81
|
+
// Force using official registry to avoid mirror sync issues
|
|
82
|
+
execSync(`npm install --registry=https://registry.npmjs.org ${packageName}`, {
|
|
83
|
+
stdio: 'ignore', // Ignore output completely
|
|
84
|
+
cwd: installDir,
|
|
85
|
+
timeout: 60000 // 60 second timeout
|
|
50
86
|
});
|
|
51
87
|
|
|
52
|
-
//
|
|
53
|
-
const
|
|
54
|
-
const
|
|
88
|
+
// Find the installed package - check multiple possible locations
|
|
89
|
+
const nodeModulesPath = path.join(installDir, 'node_modules', packageName);
|
|
90
|
+
const packageJsonPath = path.join(nodeModulesPath, 'package.json');
|
|
91
|
+
|
|
92
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
93
|
+
binDir = nodeModulesPath;
|
|
94
|
+
} else {
|
|
95
|
+
// Try to resolve using require with multiple paths
|
|
96
|
+
const searchPaths = [
|
|
97
|
+
installDir,
|
|
98
|
+
path.join(installDir, 'node_modules'),
|
|
99
|
+
__dirname,
|
|
100
|
+
path.join(__dirname, 'node_modules')
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
for (const searchPath of searchPaths) {
|
|
104
|
+
try {
|
|
105
|
+
const packagePath = require.resolve(packageName, { paths: [searchPath] });
|
|
106
|
+
binDir = path.dirname(packagePath);
|
|
107
|
+
break;
|
|
108
|
+
} catch (resolveErr) {
|
|
109
|
+
// Continue to next path
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// If still not found, use the expected path anyway
|
|
114
|
+
if (!binDir) {
|
|
115
|
+
binDir = nodeModulesPath;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} catch (installErr) {
|
|
119
|
+
// Installation failed, try alternative: install to current directory with official registry
|
|
120
|
+
try {
|
|
121
|
+
execSync(`npm install --registry=https://registry.npmjs.org ${packageName}`, {
|
|
122
|
+
stdio: 'ignore',
|
|
123
|
+
cwd: __dirname,
|
|
124
|
+
timeout: 60000
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const localNodeModules = path.join(__dirname, 'node_modules', packageName);
|
|
128
|
+
const localPackageJson = path.join(localNodeModules, 'package.json');
|
|
129
|
+
|
|
130
|
+
if (fs.existsSync(localPackageJson)) {
|
|
131
|
+
binDir = localNodeModules;
|
|
132
|
+
} else {
|
|
133
|
+
throw installErr;
|
|
134
|
+
}
|
|
135
|
+
} catch (altErr) {
|
|
136
|
+
// All installation attempts failed
|
|
137
|
+
console.error('\n❌ Failed to install platform package automatically.');
|
|
138
|
+
console.error('\nTroubleshooting steps:');
|
|
139
|
+
console.error(`\n1. Check npm registry (should be https://registry.npmjs.org/):`);
|
|
140
|
+
console.error(` npm config get registry`);
|
|
141
|
+
console.error(` npm config set registry https://registry.npmjs.org/`);
|
|
142
|
+
console.error(`\n2. Clear npm cache:`);
|
|
143
|
+
console.error(` npm cache clean --force`);
|
|
144
|
+
console.error(`\n3. Manual install (recommended):`);
|
|
145
|
+
console.error(` npm install -g ${packageName}`);
|
|
146
|
+
console.error(` npm install -g deveco-mcp-server`);
|
|
147
|
+
console.error(`\n4. Or use with registry flag in MCP config:`);
|
|
148
|
+
console.error(` "args": ["--registry=https://registry.npmjs.org", "-y", "deveco-mcp-server"]`);
|
|
149
|
+
console.error(`\n5. Check if package exists:`);
|
|
150
|
+
console.error(` npm view ${packageName}`);
|
|
151
|
+
process.exit(1);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Verify the installed package exists and has the expected structure
|
|
156
|
+
if (binDir && fs.existsSync(binDir)) {
|
|
157
|
+
// Check if binary files exist
|
|
158
|
+
let serverPath, toolboxPath;
|
|
55
159
|
|
|
56
160
|
if (process.platform === 'win32') {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
toolbox: path.join(binDir, 'deveco-toolbox.exe')
|
|
60
|
-
};
|
|
161
|
+
serverPath = path.join(binDir, 'deveco-mcp-server.exe');
|
|
162
|
+
toolboxPath = path.join(binDir, 'deveco-toolbox.exe');
|
|
61
163
|
} else {
|
|
164
|
+
serverPath = path.join(binDir, 'Contents', 'MacOS', 'deveco-mcp-server');
|
|
165
|
+
toolboxPath = path.join(binDir, 'Contents', 'MacOS', 'deveco-toolbox');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Verify server binary exists
|
|
169
|
+
if (fs.existsSync(serverPath)) {
|
|
62
170
|
return {
|
|
63
|
-
server:
|
|
64
|
-
toolbox:
|
|
171
|
+
server: serverPath,
|
|
172
|
+
toolbox: toolboxPath
|
|
65
173
|
};
|
|
174
|
+
} else {
|
|
175
|
+
// Binary not found at expected location, try to find it
|
|
176
|
+
console.error(`Installed package found at ${binDir}, but binary not at expected location.`);
|
|
177
|
+
console.error(`Expected: ${serverPath}`);
|
|
178
|
+
process.exit(1);
|
|
66
179
|
}
|
|
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
180
|
}
|
|
181
|
+
|
|
182
|
+
// Should not reach here, but just in case
|
|
183
|
+
console.error('Failed to locate installed platform package.');
|
|
184
|
+
process.exit(1);
|
|
72
185
|
}
|
|
73
186
|
}
|
|
74
187
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deveco-mcp-server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "NPM wrapper for deveco-mcp-server - HarmonyOS development MCP server with platform-specific binaries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -16,12 +16,13 @@
|
|
|
16
16
|
"deveco-mcp-server": "index.js"
|
|
17
17
|
},
|
|
18
18
|
"optionalDependencies": {
|
|
19
|
-
"deveco-mcp-server-win32-x64": "0.1.
|
|
20
|
-
"deveco-mcp-server-darwin-arm64": "0.1.
|
|
19
|
+
"deveco-mcp-server-win32-x64": "0.1.8",
|
|
20
|
+
"deveco-mcp-server-darwin-arm64": "0.1.8",
|
|
21
|
+
"deveco-mcp-server-darwin-x64": "0.1.8"
|
|
21
22
|
},
|
|
22
23
|
"repository": {
|
|
23
24
|
"type": "git",
|
|
24
|
-
"url": "https://github.com/
|
|
25
|
+
"url": "https://github.com/open-deveco/deveco-toolbox.git"
|
|
25
26
|
},
|
|
26
27
|
"author": "",
|
|
27
28
|
"license": "ISC"
|