fix(copilotcli): update elicitation handler in copilot cli to use ask tool#309446
fix(copilotcli): update elicitation handler in copilot cli to use ask tool#309446DonJayamanne wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the Copilot CLI session/MCP integration so the MCP gateway can be started with a session-associated URI (instead of an always-random URI), aligning MCP tool-call context with the originating chat session.
Changes:
- Extend
ICopilotCLIMCPHandler.loadMcpConfigto accept asessionUriand forward it toIMcpService.startMcpGateway. - Update
CopilotCLISessionServiceto pass a session-derived URI into MCP config loading for both session creation and session resume. - Adjust CLI test helpers to match the updated MCP handler interface.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/extension/chatSessions/copilotcli/node/test/testHelpers.ts | Updates the null MCP handler stub to accept a resource/URI parameter. |
| extensions/copilot/src/extension/chatSessions/copilotcli/node/mcpHandler.ts | Threads a session URI through MCP config loading and into startMcpGateway. |
| extensions/copilot/src/extension/chatSessions/copilotcli/node/copilotcliSessionService.ts | Provides a session-derived URI to loadMcpConfig when creating/resuming CLI sessions. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 1
| public async createSession(options: ICreateSessionOptions, token: CancellationToken): Promise<RefCountedSession> { | ||
| const { mcpConfig: mcpServers, disposable: mcpGateway } = await this.mcpHandler.loadMcpConfig(); | ||
| const resource = options.sessionId ? SessionIdForCLI.getResource(options.sessionId) : URI.from({ scheme: 'copilot-cli', path: `mcp-gateway-${generateUuid()}` }); | ||
| const { mcpConfig: mcpServers, disposable: mcpGateway } = await this.mcpHandler.loadMcpConfig(resource); | ||
| try { |
There was a problem hiding this comment.
When options.sessionId is not provided, the gateway resource falls back to a random copilot-cli URI. That resource does not match the chat session resource shape used elsewhere (SessionIdForCLI.getResource(...) → scheme copilotcli), so MCP gateway tool calls won’t be associated with the actual chat session (and inline elicitation/ask UX will still differ in these code paths, e.g. delegation / untitled sessions). Consider ensuring a session id/resource is always available before starting the gateway (e.g. generate a sessionId up-front when missing, use SessionIdForCLI.getResource(sessionId) for the gateway resource, and pass the same sessionId through to sessionManager.createSession).
See below for a potential fix:
const sessionId = options.sessionId ?? generateUuid();
const resource = SessionIdForCLI.getResource(sessionId);
const { mcpConfig: mcpServers, disposable: mcpGateway } = await this.mcpHandler.loadMcpConfig(resource);
try {
const sessionOptions = await this.createSessionsOptions({ ...options, sessionId, mcpServers });
const sessionManager = await raceCancellationError(this.getSessionManager(), token);
const sdkSession = await sessionManager.createSession({ ...sessionOptions, sessionId });
Fixes #307962