8000 mcp: add support for elicitations by connor4312 · Pull Request #251872 · microsoft/vscode · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

mcp: add support for elicitations #251872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ abstract class BaseChatConfirmationWidget extends Disposable {
return this._domNode;
}

private get showingButtons() {
return !this.domNode.classList.contains('hideButtons');
}

setShowButtons(showButton: boolean): void {
this.domNode.classList.toggle('hideButtons', !showButton);
}
Expand Down Expand Up @@ -176,7 +180,7 @@ abstract class BaseChatConfirmationWidget extends Disposable {
protected renderMessage(element: HTMLElement, listContainer: HTMLElement): void {
this.messageElement.append(element);

if (this._configurationService.getValue<boolean>('chat.notifyWindowOnConfirmation')) {
if (this.showingButtons && this._configurationService.getValue<boolean>('chat.notifyWindowOnConfirmation')) {
const targetWindow = dom.getWindow(listContainer);
if (!targetWindow.document.hasFocus()) {
this._hostService.focus(targetWindow, { mode: FocusMode.Notify });
Expand All @@ -186,24 +190,31 @@ abstract class BaseChatConfirmationWidget extends Disposable {
}

export class ChatConfirmationWidget extends BaseChatConfirmationWidget {
private _renderedMessage: HTMLElement | undefined;

constructor(
title: string | IMarkdownString,
subtitle: string | IMarkdownString | undefined,
private readonly message: string | IMarkdownString,
message: string | IMarkdownString,
buttons: IChatConfirmationButton[],
container: HTMLElement,
private readonly _container: HTMLElement,
@IInstantiationService instantiationService: IInstantiationService,
@IContextMenuService contextMenuService: IContextMenuService,
@IConfigurationService configurationService: IConfigurationService,
@IHostService hostService: IHostService,
) {
super(title, subtitle, buttons, instantiationService, contextMenuService, configurationService, hostService);
this.updateMessage(message);
}

public updateMessage(message: string | IMarkdownString): void {
this._renderedMessage?.remove();
const renderedMessage = this._register(this.markdownRenderer.render(
typeof this.message === 'string' ? new MarkdownString(this.message) : this.message,
typeof message === 'string' ? new MarkdownString(message) : message,
{ asyncRenderCallback: () => this._onDidChangeHeight.fire() }
));
this.renderMessage(renderedMessage.element, container);
this.renderMessage(renderedMessage.element, this._container);
this._renderedMessage = renderedMessage.element;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Emitter } from '../../../../../base/common/event.js';
import { IMarkdownString, isMarkdownString, MarkdownString } from '../../../../../base/common/htmlContent.js';
import { Disposable, IDisposable } from '../../../../../base/common/lifecycle.js';
import { localize } from '../../../../../nls.js';
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
import { IChatProgressRenderableResponseContent } from '../../common/chatModel.js';
import { IChatElicitationRequest } from '../../common/chatService.js';
import { ChatConfirmationWidget } from './chatConfirmationWidget.js';
import { IChatContentPart, IChatContentPartRenderContext } from './chatContentParts.js';

export class ChatElicitationContentPart extends Disposable implements IChatContentPart {
public readonly domNode: HTMLElement;

private readonly _onDidChangeHeight = this._register(new Emitter<void>());
public readonly >

constructor(
elicitation: IChatElicitationRequest,
context: IChatContentPartRenderContext,
@IInstantiationService private readonly instantiationService: IInstantiationService,
) {
super();

const buttons = [
{ label: localize('accept', "Respond"), data: true },
{ label: localize('dismiss', "Cancel"), data: false, isSecondary: true },
];
const confirmationWidget = this._register(this.instantiationService.createInstance(ChatConfirmationWidget, elicitation.title, elicitation.originMessage, this.getMessageToRender(elicitation), buttons, context.container));
confirmationWidget.setShowButtons(elicitation.state === 'pending');

this._register(confirmationWidget.onDidChangeHeight(() => this._onDidChangeHeight.fire()));

this._register(confirmationWidget.onDidClick(async e => {
if (e.data) {
await elicitation.accept();
} else {
await elicitation.reject();
}

confirmationWidget.setShowButtons(false);
confirmationWidget.updateMessage(this.getMessageToRender(elicitation));

this._onDidChangeHeight.fire();
}));

this.domNode = confirmationWidget.domNode;
}

private getMessageToRender(elicitation: IChatElicitationRequest): IMarkdownString | string {
if (!elicitation.acceptedResult) {
return elicitation.message;
}

const messageMd = isMarkdownString(elicitation.message) ? MarkdownString.lift(elicitation.message) : new MarkdownString(elicitation.message);
messageMd.appendCodeblock('json', JSON.stringify(elicitation.acceptedResult, null, 2));
return messageMd;
}

hasSameContent(other: IChatProgressRenderableResponseContent): boolean {
// No other change allowed for this content type
return other.kind === 'elicitation';
}

addDisposable(disposable: IDisposable): void {
this._register(disposable);
}
}
11 changes: 10 additions & 1 deletion src/vs/workbench/contrib/chat/browser/chatListRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { IChatAgentMetadata } from '../common/chatAgents.js';
import { ChatContextKeys } from '../common/chatContextKeys.js';
import { IChatTextEditGroup } from '../common/chatModel.js';
import { chatSubcommandLeader } from '../common/chatParserTypes.js';
import { ChatAgentVoteDirection, ChatAgentVoteDownReason, ChatErrorLevel, IChatConfirmation, IChatContentReference, IChatExtensionsContent, IChatFollowup, IChatMarkdownContent, IChatTask, IChatTaskSerialized, IChatToolInvocation, IChatToolInvocationSerialized, IChatTreeData, IChatUndoStop } from '../common/chatService.js';
import { ChatAgentVoteDirection, ChatAgentVoteDownReason, ChatErrorLevel, IChatConfirmation, IChatContentReference, IChatElicitationRequest, IChatExtensionsContent, IChatFollowup, IChatMarkdownContent, IChatTask, IChatTaskSerialized, IChatToolInvocation, IChatToolInvocationSerialized, IChatTreeData, IChatUndoStop } from '../common/chatService.js';
import { IChatCodeCitations, IChatErrorDetailsPart, IChatReferences, IChatRendererContent, IChatRequestViewModel, IChatResponseViewModel, IChatWorkingProgress, isRequestVM, isResponseVM } from '../common/chatViewModel.js';
import { getNWords } from '../common/chatWordCounter.js';
import { CodeBlockModelCollection } from '../common/codeBlockModelCollection.js';
Expand Down Expand Up @@ -80,6 +80,7 @@ import { ChatEditorOptions } from './chatOptions.js';
import { ChatCodeBlockContentProvider, CodeBlockPart } from './codeBlockPart.js';
import { canceledName } from '../../../../base/common/errors.js';
import { IChatRequestVariableEntry } from '../common/chatVariableEntries.js';
import { ChatElicitationContentPart } from './chatContentParts/chatElicitationContentPart.js';

const $ = dom.$;

Expand Down Expand Up @@ -963,6 +964,8 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
return this.renderUndoStop(content);
} else if (content.kind === 'errorDetails') {
return this.renderChatErrorDetails(context, content, templateData);
} else if (content.kind === 'elicitation') {
return this.renderElicitation(context, content, templateData);
}

return this.renderNoContent(other => content.kind === other.kind);
Expand Down Expand Up @@ -1136,6 +1139,12 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
return part;
}

private renderElicitation(context: IChatContentPartRenderContext, elicitation: IChatElicitationRequest, templateData: IChatListItemTemplate): IChatContentPart {
const part = this.instantiationService.createInstance(ChatElicitationContentPart, elicitation, context);
part.addDisposable(part.onDidChangeHeight(() => this.updateItemHeight(templateData)));
return part;
}

private renderAttachments(variables: IChatRequestVariableEntry[], contentReferences: ReadonlyArray<IChatContentReference> | undefined, templateData: IChatListItemTemplate) {
return this.instantiationService.createInstance(ChatAttachmentsContentPart, variables, contentReferences, undefined);
}
Expand Down
6 changes: 4 additions & 2 deletions src/vs/workbench/contrib/chat/common/chatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { CellUri, ICellEditOperation } from '../../notebook/common/notebookCommo
import { IChatAgentCommand, IChatAgentData, IChatAgentResult, IChatAgentService, reviveSerializedAgent } from './chatAgents.js';
import { IChatEditingService, IChatEditingSession } from './chatEditingService.js';
import { ChatRequestTextPart, IParsedChatRequest, reviveParsedChatRequest } from './chatParserTypes.js';
import { ChatAgentVoteDirection, ChatAgentVoteDownReason, IChatAgentMarkdownContentWithVulnerability, IChatCodeCitation, IChatCommandButton, IChatConfirmation, IChatContentInlineReference, IChatContentReference, IChatEditingSessionAction, IChatExtensionsContent, IChatFollowup, IChatLocationData, IChatMarkdownContent, IChatNotebookEdit, IChatPrepareToolInvocationPart, IChatProgress, IChatProgressMessage, IChatResponseCodeblockUriPart, IChatResponseProgressFileTreeData, IChatTask, IChatTaskSerialized, IChatTextEdit, IChatToolInvocation, IChatToolInvocationSerialized, IChatTreeData, IChatUndoStop, IChatUsedContext, IChatWarningMessage, isIUsedContext } from './chatService.js';
import { ChatAgentVoteDirection, ChatAgentVoteDownReason, IChatAgentMarkdownContentWithVulnerability, IChatCodeCitation, IChatCommandButton, IChatConfirmation, IChatContentInlineReference, IChatContentReference, IChatEditingSessionAction, IChatElicitationRequest, IChatExtensionsContent, IChatFollowup, IChatLocationData, IChatMarkdownContent, IChatNotebookEdit, IChatPrepareToolInvocationPart, IChatProgress, IChatProgressMessage, IChatResponseCodeblockUriPart, IChatResponseProgressFileTreeData, IChatTask, IChatTaskSerialized, IChatTextEdit, IChatToolInvocation, IChatToolInvocationSerialized, IChatTreeData, IChatUndoStop, IChatUsedContext, IChatWarningMessage, isIUsedContext } from './chatService.js';
import { IChatRequestVariableEntry } from './chatVariableEntries.js';
import { ChatAgentLocation, ChatMode } from './constants.js';

Expand Down Expand Up @@ -123,7 +123,8 @@ export type IChatProgressResponseContent =
| IChatToolInvocation
| IChatToolInvocationSerializ AE8F ed
| IChatUndoStop
| IChatPrepareToolInvocationPart;
| IChatPrepareToolInvocationPart
| IChatElicitationRequest;

const nonHistoryKinds = new Set(['toolInvocation', 'toolInvocationSerialized', 'undoStop', 'prepareToolInvocation']);
function isChatProgressHistoryResponseContent(content: IChatProgressResponseContent): content is IChatProgressHistoryResponseContent {
Expand Down Expand Up @@ -349,6 +350,7 @@ class AbstractResponse implements IResponse {
case 'extensions':
case 'undoStop':
case 'prepareToolInvocation':
case 'elicitation':
// Ignore
continue;
case 'inlineReference':
Expand Down
14 changes: 13 additions & 1 deletion src/vs/workbench/contrib/chat/common/chatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,17 @@ export interface IChatConfirmation {
kind: 'confirmation';
}

export interface IChatElicitationRequest {
kind: 'elicitation';
title: string | IMarkdownString;
message: string | IMarkdownString;
originMessage?: string | IMarkdownString;
state: 'pending' | 'accepted' | 'rejected';
acceptedResult?: Record<string, unknown>;
accept(): Promise<void>;
reject(): Promise<void>;
}

export interface IChatTerminalToolInvocationData {
kind: 'terminal';
command: string;
Expand Down Expand Up @@ -310,7 +321,8 @@ export type IChatProgress =
| IChatExtensionsContent
| IChatUndoStop
| IChatPrepareToolInvocationPart
| IChatTaskSerialized;
| IChatTaskSerialized
| IChatElicitationRequest;

export interface IChatFollowup {
kind: 'reply';
Expand Down
4 changes: 3 additions & 1 deletion src/vs/workbench/contrib/mcp/browser/mcp.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ import { IMcpRegistry } from '../common/mcpRegistryTypes.js';
import { McpResourceFilesystem } from '../common/mcpResourceFilesystem.js';
import { McpSamplingService } from '../common/mcpSamplingService.js';
import { McpService } from '../common/mcpService.js';
import { HasInstalledMcpServersContext, IMcpSamplingService, IMcpService, IMcpWorkbenchService, InstalledMcpServersViewId, McpServersGalleryEnabledContext } from '../common/mcpTypes.js';
import { HasInstalledMcpServersContext, IMcpElicitationService, IMcpSamplingService, IMcpService, IMcpWorkbenchService, InstalledMcpServersViewId, McpServersGalleryEnabledContext } from '../common/mcpTypes.js';
import { McpAddContextContribution } from './mcpAddContextContribution.js';
import { AddConfigurationAction, EditStoredInput, InstallFromActivation, ListMcpServerCommand, McpBrowseCommand, McpBrowseResourcesCommand, McpConfigureSamplingModels, MCPServerActionRendering, McpServerOptionsCommand, McpStartPromptingServerCommand, RemoveStoredInput, ResetMcpCachedTools, ResetMcpTrustCommand, RestartServer, ShowConfiguration, ShowOutput, StartServer, StopServer } from './mcpCommands.js';
import { McpDiscovery } from './mcpDiscovery.js';
import { McpElicitationService } from './mcpElicitationService.js';
import { McpLanguageFeatures } from './mcpLanguageFeatures.js';
import { McpResourceQuickAccess } from './mcpResourceQuickAccess.js';
import { McpServerEditor } from './mcpServerEditor.js';
Expand All @@ -51,6 +52,7 @@ registerSingleton(IMcpWorkbenchService, McpWorkbenchService, InstantiationType.E
registerSingleton(IMcpConfigPathsService, McpConfigPathsService, InstantiationType.Delayed);
registerSingleton(IMcpDevModeDebugging, McpDevModeDebugging, InstantiationType.Delayed);
registerSingleton(IMcpSamplingService, McpSamplingService, InstantiationType.Delayed);
registerSingleton(IMcpElicitationService, McpElicitationService, InstantiationType.Delayed);

mcpDiscoveryRegistry.register(new SyncDescriptor(RemoteNativeMpcDiscovery));
mcpDiscoveryRegistry.register(new SyncDescriptor(ConfigMcpDiscovery));
Expand Down
Loading
Loading
0