Skip to content

fix(copilotcli): update elicitation handler in copilot cli to use ask tool#309446

Draft
DonJayamanne wants to merge 1 commit intomainfrom
don/confidential-rodent
Draft

fix(copilotcli): update elicitation handler in copilot cli to use ask tool#309446
DonJayamanne wants to merge 1 commit intomainfrom
don/confidential-rodent

Conversation

@DonJayamanne
Copy link
Copy Markdown
Contributor

Fixes #307962

Copilot AI review requested due to automatic review settings April 13, 2026 10:43
@DonJayamanne DonJayamanne self-assigned this Apr 13, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.loadMcpConfig to accept a sessionUri and forward it to IMcpService.startMcpGateway.
  • Update CopilotCLISessionService to 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

Comment on lines 539 to 542
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 {
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 });

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copilot CLI: MCP elicitation behave different to local chat

2 participants