Skip to content

Commit 507ecc7

Browse files
committed
copilot comments
1 parent e3eb0dc commit 507ecc7

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatContentParts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export interface IChatContentPart extends IDisposable {
3131
hasSameContent(other: IChatRendererContent, followingContent: IChatRendererContent[], element: ChatTreeItem): boolean;
3232

3333
/**
34-
* Called when the content part is mounted to the DOM after being detached.
34+
* Called when the content part is mounted to the DOM after being detached
35+
* due to virtualization.
3536
*/
3637
onDidRemount?(): void;
3738

src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatMcpAppModel.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,32 @@ export class ChatMcpAppModel extends Disposable {
253253
* Injects a Content-Security-Policy meta tag into the HTML.
254254
*/
255255
private _injectPreamble({ html, csp }: IMcpAppResourceContent): string {
256+
// Note: this is not bulletproof against malformed domains. However it does not
257+
// need to be. The server is the one giving us both the CSP as well as the HTML
258+
// to render in the iframe. MCP Apps give the CSP separately so that systems that
259+
// proxy the HTML from a server can set it in a header, but the CSP and the HTML
260+
// come from the same source and are within the same trust boundary. We only
261+
// process the CSP enough (escaping HTML special characters) to avoid breaking it.
262+
//
263+
// It would certainly be more durable to use `DOMParser.parseFromString` here
264+
// and operate on the DocumentFragment of the HTML, however (even though keeping
265+
// it solely as a detached document is safe) this requires making the HTML trusted
266+
// in the renderer and bypassing various tsec warnings. I consider the string
267+
// munging here to be the lesser of two evils.
268+
const cleanDomains = (s: string[] | undefined) => (s?.join(' ') || '')
269+
.replaceAll('&', '&')
270+
.replaceAll('<', '&lt;')
271+
.replaceAll('>', '&gt;')
272+
.replaceAll('"', '&quot;');
273+
256274
const cspContent = `
257275
default-src 'none';
258276
script-src 'self' 'unsafe-inline';
259277
style-src 'self' 'unsafe-inline';
260-
connect-src 'self' ${csp?.connectDomains?.join(' ') || ''};
261-
img-src 'self' data: ${csp?.resourceDomains?.join(' ') || ''};
262-
font-src 'self' ${csp?.resourceDomains?.join(' ') || ''};
263-
media-src 'self' data: ${csp?.resourceDomains?.join(' ') || ''};
278+
connect-src 'self' ${cleanDomains(csp?.connectDomains)};
279+
img-src 'self' data: ${cleanDomains(csp?.resourceDomains)};
280+
font-src 'self' ${cleanDomains(csp?.resourceDomains)};
281+
media-src 'self' data: ${cleanDomains(csp?.resourceDomains)};
264282
frame-src 'none';
265283
object-src 'none';
266284
base-uri 'self';

src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolInvocationPart.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ export class ChatToolInvocationPart extends Disposable implements IChatContentPa
9393

9494
const render = () => {
9595
partStore.clear();
96-
this.mcpAppPart = undefined;
9796

9897
if (toolInvocation.presentation === ToolInvocationPresentation.HiddenAfterComplete && IChatToolInvocation.isComplete(toolInvocation)) {
9998
return;
@@ -131,8 +130,11 @@ export class ChatToolInvocationPart extends Disposable implements IChatContentPa
131130
appDomNode = this.mcpAppPart.domNode;
132131
r.store.add(this.mcpAppPart.onDidChangeHeight(() => this._onDidChangeHeight.fire()));
133132
} else {
133+
this.mcpAppPart = undefined;
134134
dom.clearNode(appDomNode);
135135
}
136+
137+
this._onDidChangeHeight.fire();
136138
}));
137139
}
138140

src/vs/workbench/contrib/mcp/browser/mcpToolCallUI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export class McpToolCallUI extends Disposable {
236236
public async callTool(name: string, params: Record<string, unknown>, token: CancellationToken): Promise<MCP.CallToolResult> {
237237
const server = await this._getServer(token);
238238
if (!server) {
239-
throw new Error('MCP server not found for UI resource');
239+
throw new Error('MCP server not found for tool call');
240240
}
241241

242242
await startServerAndWaitForLiveTools(server, undefined, token);

0 commit comments

Comments
 (0)