fix bug of env

This commit is contained in:
锦恢 2025-06-12 13:53:26 +08:00
parent 1a11ca64e5
commit 0f32993edb
2 changed files with 13 additions and 1 deletions

View File

@ -44,6 +44,9 @@ export class McpClient {
if (!this.oauthPovider){
this.oauthPovider = await this.oAuthClient.getOAuthProvider();
}
const env = { ...process.env, ...this.options.env } as Record<string, string>;
// 根据连接类型创建传输层
switch (this.options.connectionType) {
case 'STDIO':
@ -52,7 +55,7 @@ export class McpClient {
args: this.options.args || [],
cwd: this.options.cwd || process.cwd(),
stderr: 'pipe',
env: this.options.env,
env
});
break;

View File

@ -45,6 +45,10 @@ function getCWD(option: McpOptions) {
// 如果是绝对路径,直接返回目录
if (path.isAbsolute(file)) {
// 如果是是文件,则返回文件所在的目录
if (!fs.existsSync(file)) {
return '';
}
if (fs.statSync(file).isDirectory()) {
return file;
} else {
@ -53,6 +57,11 @@ function getCWD(option: McpOptions) {
} else {
// 如果是相对路径,根据 cwd 获取真实路径
const absPath = path.resolve(option.cwd || process.cwd(), file);
if (!fs.existsSync(absPath)) {
return '';
}
// 如果是是文件,则返回文件所在的目录
if (fs.statSync(absPath).isDirectory()) {
return absPath;