From 140d6295a8d35f1a5e37047b20553131b62fa14d Mon Sep 17 00:00:00 2001 From: winlifes <110321103+Winlifes@users.noreply.github.com> Date: Thu, 16 Apr 2026 17:06:26 +0800 Subject: [PATCH] Client config: fix VS Code path by platform --- lib/client-config.js | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/lib/client-config.js b/lib/client-config.js index b412b5a..5d93fc2 100644 --- a/lib/client-config.js +++ b/lib/client-config.js @@ -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 }, },