Compare commits
6 Commits
6cdf60ced1
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| dcf190067c | |||
| a816e9cd91 | |||
| afd408a4b8 | |||
| 7c2d5d9ad9 | |||
| 2e9126fe64 | |||
| 67cb6ab7f0 |
@@ -7,17 +7,59 @@ on:
|
||||
branches:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: node:20-alpine
|
||||
steps:
|
||||
- name: 安装 Git
|
||||
run: |
|
||||
apk add --no-cache git
|
||||
|
||||
- name: 拉取代码
|
||||
uses: https://devstar.cn/actions/checkout@v4
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: 配置 Git
|
||||
run: |
|
||||
# 添加工作目录为安全目录
|
||||
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||
git config --global --add safe.directory /github/workspace
|
||||
|
||||
# 配置用户信息
|
||||
git config --global user.name "github-actions[bot]"
|
||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
- name: 自动递增版本号
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
run: |
|
||||
apk add --no-cache jq
|
||||
CURRENT_VERSION=$(jq -r '.version' package.json)
|
||||
echo "当前版本: $CURRENT_VERSION"
|
||||
|
||||
# 分解版本号
|
||||
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
|
||||
|
||||
# 递增补丁版本号
|
||||
NEW_PATCH=$((PATCH + 1))
|
||||
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
|
||||
echo "新版本: $NEW_VERSION"
|
||||
|
||||
# 更新 package.json
|
||||
jq --arg version "$NEW_VERSION" '.version = $version' package.json > package.json.tmp
|
||||
mv package.json.tmp package.json
|
||||
|
||||
# 提交版本变更
|
||||
git add package.json
|
||||
git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
|
||||
git push
|
||||
|
||||
- name: 安装依赖
|
||||
run: |
|
||||
npm install
|
||||
@@ -27,7 +69,7 @@ jobs:
|
||||
npm run package
|
||||
|
||||
- name: 发布插件
|
||||
if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main'
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
run: |
|
||||
npm run publish
|
||||
env:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "devstar",
|
||||
"displayName": "%displayName%",
|
||||
"description": "%description%",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.3",
|
||||
"keywords": [],
|
||||
"publisher": "mengning",
|
||||
"engines": {
|
||||
|
||||
40
src/home.ts
40
src/home.ts
@@ -79,7 +79,33 @@ export default class DSHome {
|
||||
async (message) => {
|
||||
const data = message.data;
|
||||
const need_return = message.need_return;
|
||||
if (!need_return) {
|
||||
|
||||
if (need_return) {
|
||||
// 处理需要返回结果的消息
|
||||
switch (message.command) {
|
||||
case 'getUserToken':
|
||||
panel.webview.postMessage({
|
||||
command: 'getUserToken',
|
||||
data: { userToken: this.user.getUserTokenFromLocal() }
|
||||
});
|
||||
break;
|
||||
|
||||
case 'getUsername':
|
||||
panel.webview.postMessage({
|
||||
command: 'getUsername',
|
||||
data: { username: this.user.getUsernameFromLocal() }
|
||||
});
|
||||
break;
|
||||
|
||||
case 'getDevstarDomain':
|
||||
panel.webview.postMessage({
|
||||
command: 'getDevstarDomain',
|
||||
data: { devstarDomain: this.devstarDomain }
|
||||
});
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// 处理不需要返回结果的消息
|
||||
switch (message.command) {
|
||||
case 'openExternalUrl':
|
||||
const url = message.url || (data && data.url);
|
||||
@@ -96,6 +122,18 @@ export default class DSHome {
|
||||
vscode.window.showErrorMessage('打开链接失败: 链接地址无效');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'showInformationNotification':
|
||||
if (data && data.message) {
|
||||
vscode.window.showInformationMessage(data.message);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'showErrorNotification':
|
||||
if (data && data.message) {
|
||||
vscode.window.showErrorMessage(data.message);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
48
src/main.ts
48
src/main.ts
@@ -66,32 +66,17 @@ export class DevStarExtension {
|
||||
const path = params.get('path');
|
||||
const accessToken = params.get('access_token');
|
||||
const devstarUsername = params.get('devstar_username');
|
||||
const rawDevstarDomain = params.get('devstar_domain');
|
||||
const cmd = params.get('cmd') || 'code'; // 获取 cmd 参数,默认为 code
|
||||
let devstarDomain = rawDevstarDomain;
|
||||
if (rawDevstarDomain) {
|
||||
try {
|
||||
const url = new URL(rawDevstarDomain);
|
||||
devstarDomain = `${url.protocol}//${url.hostname}`;
|
||||
const devstarDomain = params.get('devstar_domain');
|
||||
const forwardPortsParam = params.get('forwardPorts');
|
||||
|
||||
// 从 rawDevstarDomain 的查询参数中提取 forwardPorts
|
||||
const forwardPortsParam = url.searchParams.get('forwardPorts');
|
||||
if (forwardPortsParam) {
|
||||
const ports = forwardPortsParam.split(',').map(port => parseInt(port, 10)).filter(port => !isNaN(port));
|
||||
console.log('解析到的 forwardPorts 参数:', ports);
|
||||
context.globalState.update('forwardPorts', ports);
|
||||
} else {
|
||||
// 如果没有 forwardPorts 参数,清除 globalState 中的旧值
|
||||
console.log('未找到 forwardPorts 参数,清除旧的 forwardPorts 配置');
|
||||
context.globalState.update('forwardPorts', undefined);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Invalid devstar_domain URL:', error);
|
||||
}
|
||||
// 处理 forwardPorts 参数
|
||||
if (forwardPortsParam) {
|
||||
const ports = forwardPortsParam.split(',').map(port => parseInt(port, 10)).filter(port => !isNaN(port));
|
||||
context.globalState.update('forwardPorts', ports);
|
||||
} else {
|
||||
// 如果没有 forwardPorts 参数,清除 globalState 中的旧值
|
||||
context.globalState.update('forwardPorts', undefined);
|
||||
}
|
||||
console.log('sanitized_devstar_domain:', devstarDomain);
|
||||
|
||||
// 使用修正后的 devstar_domain
|
||||
if (devstarDomain) {
|
||||
this.user.setDevstarDomain(devstarDomain);
|
||||
this.remoteContainer.setUser(this.user);
|
||||
@@ -124,11 +109,11 @@ export class DevStarExtension {
|
||||
// 如果没有用户登录,则直接登录;
|
||||
const res = await this.user.login(accessToken, devstarUsername)
|
||||
if (res === 'ok') {
|
||||
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context, cmd)
|
||||
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context)
|
||||
}
|
||||
} else if (devstarUsername === this.user.getUsernameFromLocal()) {
|
||||
// 如果同用户已经登录,则忽略,直接打开项目
|
||||
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context, cmd)
|
||||
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context)
|
||||
} else {
|
||||
// 如果不是同用户,可以选择切换用户,或者不切换登录用户,直接打开容器
|
||||
const selection = await vscode.window.showWarningMessage(`已登录用户:${this.user.getUsernameFromLocal()},是否切换用户?`,
|
||||
@@ -137,14 +122,14 @@ export class DevStarExtension {
|
||||
// 如果没有用户登录,则直接登录;
|
||||
const res = await this.user.login(accessToken, devstarUsername)
|
||||
if (res === 'ok') {
|
||||
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context, cmd)
|
||||
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context)
|
||||
}
|
||||
} else if (selection === 'No') {
|
||||
await openProjectWithoutLogging(containerHost, containerPort, containerUsername, projectPath, cmd);
|
||||
await openProjectWithoutLogging(containerHost, containerPort, containerUsername, projectPath);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await openProjectWithoutLogging(containerHost, containerPort, containerUsername, projectPath, cmd);
|
||||
await openProjectWithoutLogging(containerHost, containerPort, containerUsername, projectPath);
|
||||
}
|
||||
} else {
|
||||
vscode.window.showErrorMessage('Missing required parameters.');
|
||||
@@ -161,7 +146,6 @@ export class DevStarExtension {
|
||||
const username = params.get('username');
|
||||
const path = params.get('path');
|
||||
const devstarDomain = params.get('devstar_domain')
|
||||
const cmd = params.get('cmd') || 'code'; // 获取 cmd 参数,默认为 code
|
||||
|
||||
if (host && hostname && port && username && path) {
|
||||
const container_host = host;
|
||||
@@ -181,10 +165,10 @@ export class DevStarExtension {
|
||||
// 将devstar domain存在global state中
|
||||
context.globalState.update('devstarDomain', devstarDomain)
|
||||
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context, cmd)
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
|
||||
} else {
|
||||
// devstarDomain参数不存在,则不存储,使用默认用户配置
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context, cmd)
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export default class RemoteContainer {
|
||||
/**
|
||||
* 第一次打开远程项目
|
||||
*/
|
||||
async firstOpenProject(host: string, hostname: string, port: number, username: string, path: string, context: vscode.ExtensionContext, cmd: string = 'code') {
|
||||
async firstOpenProject(host: string, hostname: string, port: number, username: string, path: string, context: vscode.ExtensionContext) {
|
||||
if (vscode.env.remoteName) {
|
||||
try {
|
||||
await vscode.commands.executeCommand('workbench.action.terminal.newLocal');
|
||||
@@ -76,7 +76,7 @@ export default class RemoteContainer {
|
||||
await this.firstConnect(host, hostname, username, port, path)
|
||||
.then((res) => {
|
||||
if (res === 'success') {
|
||||
this.openRemoteFolder(host, port, username, path, context, cmd);
|
||||
this.openRemoteFolder(host, port, username, path, context);
|
||||
} else {
|
||||
vscode.window.showErrorMessage('首次连接容器失败,请检查网络和容器状态。');
|
||||
}
|
||||
@@ -263,24 +263,32 @@ export default class RemoteContainer {
|
||||
`root@${hostname}`
|
||||
];
|
||||
|
||||
const sshProcess = spawn('ssh', sshArgs);
|
||||
// 使用 detached 选项让 SSH 进程独立运行,不随父进程退出
|
||||
const sshProcess = spawn('ssh', sshArgs, {
|
||||
detached: true, // 让进程在后台独立运行
|
||||
stdio: 'ignore' // 忽略输入输出,避免进程挂起
|
||||
});
|
||||
|
||||
// 解除父进程对子进程的引用,使其真正独立
|
||||
sshProcess.unref();
|
||||
|
||||
sshProcess.on('error', (error: Error) => {
|
||||
reject(error);
|
||||
});
|
||||
|
||||
sshProcess.stdout.on('data', (_data: Buffer) => {
|
||||
});
|
||||
// 由于使用了 stdio: 'ignore',这些事件监听器不再需要
|
||||
// sshProcess.stdout.on('data', (data: Buffer) => {
|
||||
// console.log(`[SSH stdout] ${data.toString()}`);
|
||||
// });
|
||||
|
||||
sshProcess.stderr.on('data', (_data: Buffer) => {
|
||||
});
|
||||
// sshProcess.stderr.on('data', (data: Buffer) => {
|
||||
// console.error(`[SSH stderr] ${data.toString()}`);
|
||||
// });
|
||||
|
||||
if (!this.sshProcesses) {
|
||||
this.sshProcesses = new Map();
|
||||
}
|
||||
const key = `${hostname}:${sshPort}:${containerPort}`;
|
||||
this.sshProcesses.set(key, sshProcess);
|
||||
// 注意:由于进程已 detached 和 unref,不再需要保存到 sshProcesses Map
|
||||
// 因为我们无法也不需要控制这些独立进程的生命周期
|
||||
|
||||
// 等待 SSH 连接建立
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 2000);
|
||||
@@ -352,9 +360,10 @@ export default class RemoteContainer {
|
||||
/**
|
||||
* local env - 使用 Extension API 打开远程文件夹
|
||||
*/
|
||||
async openRemoteFolder(host: string, port: number, _username: string, path: string, context: vscode.ExtensionContext, _cmd: string = 'code'): Promise<void> {
|
||||
async openRemoteFolder(host: string, port: number, _username: string, path: string, context: vscode.ExtensionContext): Promise<void> {
|
||||
try {
|
||||
const sshConfig = await this.getSSHConfig(host);
|
||||
|
||||
if (sshConfig) {
|
||||
try {
|
||||
// 调用 setupPortForwardingFromGlobalState 方法
|
||||
@@ -363,6 +372,22 @@ export default class RemoteContainer {
|
||||
} catch (portError) {
|
||||
vscode.window.showWarningMessage('端口映射设置失败,但容器连接已建立');
|
||||
}
|
||||
|
||||
// 自动配置本地 VSCode 的 MCP Server
|
||||
try {
|
||||
await this.configureMCPServerLocally();
|
||||
} catch (mcpError) {
|
||||
console.error('[MCP] 本地 MCP 配置失败:', mcpError);
|
||||
// 不阻塞主流程,仅记录错误
|
||||
}
|
||||
|
||||
// 自动配置容器内 AI IDE 的 MCP Server
|
||||
try {
|
||||
await this.configureMCPServerInContainer(sshConfig.hostname, port);
|
||||
} catch (mcpError) {
|
||||
console.error('[MCP] 容器内 MCP 配置失败:', mcpError);
|
||||
// 不阻塞主流程,仅记录错误
|
||||
}
|
||||
}
|
||||
|
||||
// 使用 VSCode Extension API 打开远程连接
|
||||
@@ -462,12 +487,238 @@ export default class RemoteContainer {
|
||||
console.log('未找到 forwardPorts 参数,跳过端口映射设置。');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在容器内配置 AI IDE 的 MCP Server
|
||||
* 支持 Trae IDE 等 AI IDE 的 MCP 自动配置
|
||||
*/
|
||||
private async configureMCPServerInContainer(hostname: string, sshPort: number): Promise<void> {
|
||||
// 获取用户 token
|
||||
const userToken = this.user.getUserTokenFromLocal();
|
||||
if (!userToken) {
|
||||
console.log('[MCP] 用户未登录,跳过 MCP Server 配置');
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取 DevStar 域名
|
||||
const devstarDomain = this.user.getDevstarDomain();
|
||||
const mcpUrl = `${devstarDomain}/api/mcp`;
|
||||
|
||||
console.log(`[MCP] 开始配置 MCP Server: ${mcpUrl}`);
|
||||
|
||||
// Trae IDE 的 MCP 配置路径
|
||||
const traeMcpPath = '/root/.trae-server/data/Machine/mcp.json';
|
||||
|
||||
// MCP 配置内容(注意:使用 "mcpServers" 格式)
|
||||
const mcpConfig = {
|
||||
mcpServers: {
|
||||
devstar: {
|
||||
type: 'http',
|
||||
url: mcpUrl,
|
||||
headers: {
|
||||
Authorization: `Bearer ${userToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const configJson = JSON.stringify(mcpConfig, null, 2);
|
||||
|
||||
// 使用 SSH 连接到容器并配置
|
||||
const ssh = new NodeSSH();
|
||||
|
||||
try {
|
||||
await ssh.connect({
|
||||
host: hostname,
|
||||
username: 'root',
|
||||
port: sshPort,
|
||||
privateKeyPath: this.user.getUserPrivateKeyPath(),
|
||||
readyTimeout: 10000,
|
||||
});
|
||||
|
||||
console.log('[MCP] SSH 连接成功');
|
||||
|
||||
// 检查现有配置
|
||||
const checkScript = `
|
||||
if [ -f "${traeMcpPath}" ]; then
|
||||
cat "${traeMcpPath}"
|
||||
else
|
||||
echo "FILE_NOT_EXISTS"
|
||||
fi
|
||||
`;
|
||||
|
||||
const checkResult = await ssh.execCommand(checkScript);
|
||||
|
||||
let needUpdate = true;
|
||||
|
||||
if (checkResult.stdout !== 'FILE_NOT_EXISTS') {
|
||||
try {
|
||||
const existingConfig = JSON.parse(checkResult.stdout);
|
||||
const existingDevstar = existingConfig.mcpServers?.devstar;
|
||||
|
||||
if (existingDevstar) {
|
||||
// 检查 URL 和 token 是否匹配
|
||||
const urlMatch = existingDevstar.url === mcpUrl;
|
||||
const tokenMatch = existingDevstar.headers?.Authorization === `Bearer ${userToken}`;
|
||||
|
||||
if (urlMatch && tokenMatch) {
|
||||
console.log('[MCP] DevStar MCP 配置已存在且正确,无需更新');
|
||||
needUpdate = false;
|
||||
} else {
|
||||
console.log(`[MCP] DevStar MCP 配置需要更新 (URL匹配: ${urlMatch}, Token匹配: ${tokenMatch})`);
|
||||
}
|
||||
}
|
||||
} catch (parseError) {
|
||||
console.log('[MCP] 解析现有配置失败,将创建新配置');
|
||||
}
|
||||
} else {
|
||||
console.log('[MCP] 容器内无配置文件,需要创建');
|
||||
}
|
||||
|
||||
// 创建或更新配置文件
|
||||
if (needUpdate) {
|
||||
const setupScript = `
|
||||
mkdir -p /root/.trae-server/data/Machine && \
|
||||
cat > ${traeMcpPath} << 'EOF'
|
||||
${configJson}
|
||||
EOF
|
||||
echo "MCP 配置已更新"
|
||||
`;
|
||||
|
||||
const result = await ssh.execCommand(setupScript);
|
||||
|
||||
if (result.code === 0) {
|
||||
console.log('[MCP] DevStar MCP 配置成功');
|
||||
} else {
|
||||
console.error(`[MCP] 配置失败: ${result.stderr}`);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('[MCP] SSH 连接或配置失败:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
try {
|
||||
await ssh.dispose();
|
||||
} catch (e) {
|
||||
// ignore dispose error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在本地 VSCode 中配置 MCP Server
|
||||
* 支持 GitHub Copilot 等使用本地 MCP 配置
|
||||
*/
|
||||
private async configureMCPServerLocally(): Promise<void> {
|
||||
// 获取用户 token
|
||||
const userToken = this.user.getUserTokenFromLocal();
|
||||
if (!userToken) {
|
||||
console.log('[MCP] 用户未登录,跳过本地 MCP Server 配置');
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取 DevStar 域名
|
||||
const devstarDomain = this.user.getDevstarDomain();
|
||||
const mcpUrl = `${devstarDomain}/api/mcp`;
|
||||
|
||||
console.log(`[MCP] 开始配置本地 MCP Server: ${mcpUrl}`);
|
||||
|
||||
// 根据操作系统确定配置文件路径
|
||||
let mcpConfigPath: string;
|
||||
const platform = os.platform();
|
||||
const homedir = os.homedir();
|
||||
|
||||
if (platform === 'darwin') {
|
||||
// macOS
|
||||
mcpConfigPath = path.join(homedir, 'Library/Application Support/Code/User/mcp.json');
|
||||
} else if (platform === 'win32') {
|
||||
// Windows
|
||||
mcpConfigPath = path.join(homedir, 'AppData/Roaming/Code/User/mcp.json');
|
||||
} else {
|
||||
// Linux
|
||||
mcpConfigPath = path.join(homedir, '.config/Code/User/mcp.json');
|
||||
}
|
||||
|
||||
console.log(`[MCP] 配置文件路径: ${mcpConfigPath}`);
|
||||
|
||||
// MCP 配置内容(本地 VSCode 使用 "servers" 格式)
|
||||
const mcpConfig = {
|
||||
servers: {
|
||||
devstar: {
|
||||
type: 'http',
|
||||
url: mcpUrl,
|
||||
headers: {
|
||||
Authorization: `Bearer ${userToken}`
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const configJson = JSON.stringify(mcpConfig, null, 2);
|
||||
|
||||
try {
|
||||
// 检查现有配置
|
||||
let existingConfig: any = {};
|
||||
let needUpdate = true;
|
||||
|
||||
if (fs.existsSync(mcpConfigPath)) {
|
||||
try {
|
||||
const content = fs.readFileSync(mcpConfigPath, 'utf8');
|
||||
existingConfig = JSON.parse(content);
|
||||
const existingDevstar = existingConfig.servers?.devstar;
|
||||
|
||||
if (existingDevstar) {
|
||||
// 检查 URL 和 token 是否匹配
|
||||
const urlMatch = existingDevstar.url === mcpUrl;
|
||||
const tokenMatch = existingDevstar.headers?.Authorization === `Bearer ${userToken}`;
|
||||
|
||||
if (urlMatch && tokenMatch) {
|
||||
console.log('[MCP] 本地 DevStar MCP 配置已存在且正确,无需更新');
|
||||
needUpdate = false;
|
||||
} else {
|
||||
console.log(`[MCP] 本地 DevStar MCP 配置需要更新 (URL匹配: ${urlMatch}, Token匹配: ${tokenMatch})`);
|
||||
}
|
||||
}
|
||||
} catch (parseError) {
|
||||
console.log('[MCP] 解析现有配置失败,将创建新配置');
|
||||
}
|
||||
} else {
|
||||
console.log('[MCP] 本地无配置文件,需要创建');
|
||||
}
|
||||
|
||||
// 创建或更新配置文件
|
||||
if (needUpdate) {
|
||||
// 确保目录存在
|
||||
const configDir = path.dirname(mcpConfigPath);
|
||||
if (!fs.existsSync(configDir)) {
|
||||
fs.mkdirSync(configDir, { recursive: true });
|
||||
}
|
||||
|
||||
// 合并现有配置(保留其他 MCP servers)
|
||||
const newConfig = {
|
||||
...existingConfig,
|
||||
servers: {
|
||||
...existingConfig.servers,
|
||||
...mcpConfig.servers
|
||||
}
|
||||
};
|
||||
|
||||
fs.writeFileSync(mcpConfigPath, JSON.stringify(newConfig, null, 2), 'utf8');
|
||||
console.log('[MCP] 本地 DevStar MCP 配置成功');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('[MCP] 本地 MCP 配置失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开项目(无须插件登录)- 使用 Extension API
|
||||
*/
|
||||
export async function openProjectWithoutLogging(host: string, _port: number, _username: string, path: string, _cmd: string = 'code'): Promise<void> {
|
||||
export async function openProjectWithoutLogging(host: string, _port: number, _username: string, path: string): Promise<void> {
|
||||
try {
|
||||
// 使用 VSCode Extension API 打开远程连接
|
||||
// 使用 SSH config 中的 Host 别名,让 SSH config 的用户配置生效
|
||||
|
||||
Reference in New Issue
Block a user