fix bug of env
This commit is contained in:
parent
1a11ca64e5
commit
0f32993edb
@ -44,6 +44,9 @@ export class McpClient {
|
|||||||
if (!this.oauthPovider){
|
if (!this.oauthPovider){
|
||||||
this.oauthPovider = await this.oAuthClient.getOAuthProvider();
|
this.oauthPovider = await this.oAuthClient.getOAuthProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const env = { ...process.env, ...this.options.env } as Record<string, string>;
|
||||||
|
|
||||||
// 根据连接类型创建传输层
|
// 根据连接类型创建传输层
|
||||||
switch (this.options.connectionType) {
|
switch (this.options.connectionType) {
|
||||||
case 'STDIO':
|
case 'STDIO':
|
||||||
@ -52,7 +55,7 @@ export class McpClient {
|
|||||||
args: this.options.args || [],
|
args: this.options.args || [],
|
||||||
cwd: this.options.cwd || process.cwd(),
|
cwd: this.options.cwd || process.cwd(),
|
||||||
stderr: 'pipe',
|
stderr: 'pipe',
|
||||||
env: this.options.env,
|
env
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -45,6 +45,10 @@ function getCWD(option: McpOptions) {
|
|||||||
// 如果是绝对路径,直接返回目录
|
// 如果是绝对路径,直接返回目录
|
||||||
if (path.isAbsolute(file)) {
|
if (path.isAbsolute(file)) {
|
||||||
// 如果是是文件,则返回文件所在的目录
|
// 如果是是文件,则返回文件所在的目录
|
||||||
|
if (!fs.existsSync(file)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
if (fs.statSync(file).isDirectory()) {
|
if (fs.statSync(file).isDirectory()) {
|
||||||
return file;
|
return file;
|
||||||
} else {
|
} else {
|
||||||
@ -53,6 +57,11 @@ function getCWD(option: McpOptions) {
|
|||||||
} else {
|
} else {
|
||||||
// 如果是相对路径,根据 cwd 获取真实路径
|
// 如果是相对路径,根据 cwd 获取真实路径
|
||||||
const absPath = path.resolve(option.cwd || process.cwd(), file);
|
const absPath = path.resolve(option.cwd || process.cwd(), file);
|
||||||
|
|
||||||
|
if (!fs.existsSync(absPath)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
// 如果是是文件,则返回文件所在的目录
|
// 如果是是文件,则返回文件所在的目录
|
||||||
if (fs.statSync(absPath).isDirectory()) {
|
if (fs.statSync(absPath).isDirectory()) {
|
||||||
return absPath;
|
return absPath;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user