Skip to content

Commit d95f4bd

Browse files
authored
mcp: respect annotations on tool results (microsoft#250003)
We still show everything to the user so the model can't do sneaky things, but user-only messages are now omitted from the tool result data and we show the user text as progress. Fixes microsoft#248437
1 parent f00e510 commit d95f4bd

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/vs/workbench/contrib/chat/common/languageModelToolsService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export interface IToolData {
4545

4646
export interface IToolProgressStep {
4747
readonly message: string | IMarkdownString | undefined;
48-
readonly increment: number | undefined;
49-
readonly total: number | undefined;
48+
readonly increment?: number;
49+
readonly total?: number;
5050
}
5151

5252
export type ToolProgress = IProgress<IToolProgressStep>;

src/vs/workbench/contrib/mcp/common/mcpService.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,30 @@ class McpToolImplementation implements IToolImpl {
280280
};
281281

282282
for (const item of callResult.content) {
283+
const audience = item.annotations?.audience || ['assistant'];
284+
if (audience.includes('user')) {
285+
if (item.type === 'text') {
286+
progress.report({ message: item.text });
287+
}
288+
}
289+
290+
const isForModel = audience.includes('assistant');
283291
if (item.type === 'text') {
284292
details.output.push({ type: 'text', value: item.text });
285-
result.content.push({
286-
kind: 'text',
287-
value: item.text
288-
});
293+
if (isForModel) {
294+
result.content.push({
295+
kind: 'text',
296+
value: item.text
297+
});
298+
}
289299
} else if (item.type === 'image' || item.type === 'audio') {
290300
details.output.push({ type: 'data', mimeType: item.mimeType, value64: item.data });
291-
result.content.push({
292-
kind: 'data',
293-
value: { mimeType: item.mimeType, data: decodeBase64(item.data) }
294-
});
301+
if (isForModel) {
302+
result.content.push({
303+
kind: 'data',
304+
value: { mimeType: item.mimeType, data: decodeBase64(item.data) }
305+
});
306+
}
295307
} else {
296308
// unsupported for now.
297309
}

0 commit comments

Comments
 (0)