Client config: fix VS Code path by platform

This commit is contained in:
winlifes
2026-04-16 17:06:26 +08:00
parent 9a547d1f5f
commit 140d6295a8
+41 -2
View File
@@ -6,6 +6,45 @@ const path = require('path');
const SERVER_NAME = 'funplay_cocos';
function getUserHomePath() {
const home = os.homedir();
if (home) {
return home;
}
const homeDrive = process.env.HOMEDRIVE;
const homePath = process.env.HOMEPATH;
if (homeDrive && homePath) {
return `${homeDrive}${homePath}`;
}
return process.env.HOME || '';
}
function getVSCodeConfigPath(homePath) {
switch (process.platform) {
case 'win32': {
const appData = process.env.APPDATA || path.join(homePath, 'AppData', 'Roaming');
return path.join(appData, 'Code', 'User', 'mcp.json');
}
case 'darwin': {
const primaryPath = path.join(homePath, 'Library', 'Application Support', 'Code', 'User', 'mcp.json');
const primaryDirectory = path.dirname(primaryPath);
if (fs.existsSync(primaryPath) || fs.existsSync(primaryDirectory)) {
return primaryPath;
}
return path.join(homePath, '.vscode', 'mcp.json');
}
case 'linux':
return path.join(homePath, '.config', 'Code', 'User', 'mcp.json');
default:
return path.join(homePath, '.vscode', 'mcp.json');
}
}
function ensureParent(filePath) {
const dir = path.dirname(filePath);
if (dir && !fs.existsSync(dir)) {
@@ -67,7 +106,7 @@ function configureTomlTarget(target) {
}
function buildTargets(config) {
const home = os.homedir();
const home = getUserHomePath();
const url = `http://${config.host}:${config.port}/`;
return [
@@ -88,7 +127,7 @@ function buildTargets(config) {
{
id: 'vscode',
name: 'VS Code',
configPath: path.join(home, '.vscode', 'mcp.json'),
configPath: getVSCodeConfigPath(home),
rootKey: 'servers',
entry: { type: 'http', url },
},