Skip to content

Commit 44bad13

Browse files
authored
Merge pull request #50 from PasserByJia/main
解决ElcAgent使用MCP后,子进程无法自动退出的问题。
2 parents 29833a1 + 021d3b6 commit 44bad13

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "easy-llm-cli",
3-
"version": "0.1.9",
3+
"version": "0.1.10",
44
"engines": {
55
"node": ">=20.0.0"
66
},

packages/cli/src/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ToolCallRequestInfo,
1212
CoreToolScheduler,
1313
ApprovalMode,
14+
closeAllMCPConnections
1415
} from '@google/gemini-cli-core';
1516
import { type Part } from '@google/genai';
1617
import { AgentConfig, AgentResult } from './types.js';
@@ -101,6 +102,8 @@ export class ElcAgent {
101102
await this.processConversationRound(config, geminiClient, [
102103
{ text: userInput },
103104
]);
105+
//close mcp connection
106+
await closeAllMCPConnections();
104107
return this.getLastResult();
105108
}
106109

packages/core/src/tools/mcp-client.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const mcpServerStatusesInternal: Map<string, MCPServerStatus> = new Map();
5353
*/
5454
let mcpDiscoveryState: MCPDiscoveryState = MCPDiscoveryState.NOT_STARTED;
5555

56+
let mcpClient: Client | null = null;
57+
5658
/**
5759
* Event listeners for MCP server status changes
5860
*/
@@ -211,7 +213,7 @@ async function connectAndDiscover(
211213
return;
212214
}
213215

214-
const mcpClient = new Client({
216+
mcpClient = new Client({
215217
name: 'gemini-cli-mcp-client',
216218
version: '0.0.1',
217219
});
@@ -390,3 +392,12 @@ async function connectAndDiscover(
390392
}
391393
}
392394
}
395+
396+
/**
397+
* Close all MCP connections.
398+
*/
399+
export async function closeAllMCPConnections() {
400+
if (mcpClient) {
401+
await mcpClient.close();
402+
}
403+
}

0 commit comments

Comments
 (0)