Skip to content

Commit 483ead0

Browse files
authored
Migrate LM tools over to MCP (#1528)
1 parent edfe6c9 commit 483ead0

14 files changed

Lines changed: 948 additions & 112 deletions

package-lock.json

Lines changed: 821 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,6 @@
9898
]
9999
}
100100
],
101-
"languageModelTools": [
102-
{
103-
"displayName": "Azure Resources: Get Azure Activity Log",
104-
"icon": "$(azure)",
105-
"inputSchema": {},
106-
"modelDescription": "Gets the Azure activity log",
107-
"name": "azureResources_getAzureActivityLog",
108-
"canBeReferencedInPrompt": true,
109-
"toolReferenceName": "azureActivityLog",
110-
"tags": [
111-
"azure"
112-
]
113-
}
114-
],
115101
"terminal": {
116102
"profiles": [
117103
{
@@ -894,6 +880,12 @@
894880
}
895881
]
896882
}
883+
],
884+
"mcpServerDefinitionProviders": [
885+
{
886+
"id": "vscode-azureresourcegroups.mcp",
887+
"label": "%azureResourceGroups.copilot.mcp.label%"
888+
}
897889
]
898890
},
899891
"scripts": {
@@ -930,13 +922,15 @@
930922
"@microsoft/vscode-azext-azureauth": "^6.1.0-alpha.2",
931923
"@microsoft/vscode-azext-azureutils": "^4.3.0",
932924
"@microsoft/vscode-azext-utils": "^4.1.0",
925+
"@microsoft/vscode-inproc-mcp": "^0.3.0",
933926
"form-data": "^4.0.6",
934927
"fs-extra": "^11.3.0",
935928
"jsonc-parser": "^2.2.1",
936929
"semver": "^7.7.3",
937930
"uuid": "^14.0.0",
938931
"vscode-nls": "^5.0.1",
939932
"vscode-uri": "^3.0.7",
940-
"ws": "^8.21.0"
933+
"ws": "^8.21.0",
934+
"zod": "^4.4.3"
941935
}
942936
}

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@
6363
"Do not translate '@azure'; it is the syntax for addressing the Azure agent.",
6464
"Do not translate any of the words in the command URL."
6565
]
66-
}
66+
},
67+
"azureResourceGroups.copilot.mcp.label": "Copilot Azure Resources Extension Tools"
6768
}

src/chat/askAgentAboutActivityLog/askAgentAboutActivityLog.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export async function askAgentAboutActivityLog(context: IActionContext, item?: A
4545
}
4646
}
4747

48+
if (!activitySelectedCache.selectionCount) {
49+
return;
50+
}
51+
4852
await vscode.commands.executeCommand("workbench.action.chat.newChat");
4953
await vscode.commands.executeCommand("workbench.action.chat.open", { mode: 'agent', query: genericActivityLogPrompt });
5054
}

src/chat/tools/GetAzureActivityLog/GetAzureActivityLog.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/chat/tools/GetAzureActivityLog/GetAzureActivityLogContext.ts renamed to src/chat/tools/azureActivityLog/getAzureActivityLog/GetAzureActivityLogContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { IActionContext } from "@microsoft/vscode-azext-utils";
7-
import { ActivitySelectedCache } from "../../askAgentAboutActivityLog/ActivitySelectedCache";
7+
import { ActivitySelectedCache } from "../../../askAgentAboutActivityLog/ActivitySelectedCache";
88

99
export interface GetAzureActivityLogContext extends IActionContext {
1010
activitySelectedCache: ActivitySelectedCache;

src/chat/tools/GetAzureActivityLog/convertActivityTree.ts renamed to src/chat/tools/azureActivityLog/getAzureActivityLog/convertActivityTree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { ActivityAttributes, ActivityChildItemBase, ActivityChildType } from "@microsoft/vscode-azext-utils";
7-
import { ext } from "../../../extensionVariables";
8-
import { ActivityItem, ActivityStatus } from "../../../tree/activityLog/ActivityItem";
9-
import { TreeDataItem } from "../../../tree/ResourceGroupsItem";
7+
import { ext } from "../../../../extensionVariables";
8+
import { ActivityItem, ActivityStatus } from "../../../../tree/activityLog/ActivityItem";
9+
import { TreeDataItem } from "../../../../tree/ResourceGroupsItem";
1010
import { GetAzureActivityLogContext } from "./GetAzureActivityLogContext";
1111

1212
export type ConvertedActivityItem = {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { callWithTelemetryAndErrorHandling, IActionContext } from "@microsoft/vscode-azext-utils";
7+
import { CopilotTool } from "@microsoft/vscode-inproc-mcp";
8+
import { UnspecifiedOutputSchema } from "@microsoft/vscode-inproc-mcp/mcp";
9+
import { l10n } from "vscode";
10+
import type { z } from "zod";
11+
import { ext } from "../../../../extensionVariables";
12+
import { ActivitySelectedCache } from "../../../askAgentAboutActivityLog/ActivitySelectedCache";
13+
import { GetAzureActivityLogContext } from "./GetAzureActivityLogContext";
14+
import { convertActivityTreeToSimpleObjectArray, ConvertedActivityItem, ExcludedActivityItem } from "./convertActivityTree";
15+
import { logActivityTelemetry, logSelectedActivityTelemetry } from "./logTelemetry";
16+
17+
const getAzureActivityLogToolName = 'get_azure_activity_log';
18+
19+
export const getAzureActivityLogTool: CopilotTool<z.ZodVoid, typeof UnspecifiedOutputSchema> = {
20+
name: getAzureActivityLogToolName,
21+
description: 'Get the Azure activity log from VS Code.',
22+
annotations: {
23+
readOnlyHint: true,
24+
idempotentHint: true,
25+
},
26+
execute: async (_, extras) => {
27+
return await callWithTelemetryAndErrorHandling(`mcpTool/${getAzureActivityLogToolName}/execute`, async (context: IActionContext) => {
28+
context.telemetry.properties.isCopilotEvent = 'true';
29+
context.telemetry.properties.sessionId = extras?.sessionId;
30+
context.telemetry.properties.requestId = extras?.requestId.toString();
31+
return await getAzureActivityLog(context);
32+
}) ?? {
33+
message: l10n.t('Failed to get the Azure activity log.'),
34+
activityItems: [],
35+
};
36+
}
37+
};
38+
39+
async function getAzureActivityLog(actionContext: IActionContext): Promise<{ message: string; activityItems: string[] }> {
40+
const context: GetAzureActivityLogContext = Object.assign(actionContext, { activitySelectedCache: ActivitySelectedCache.getInstance() });
41+
42+
const convertedActivityItems: ConvertedActivityItem[] = await convertActivityTreeToSimpleObjectArray(context);
43+
logActivityTelemetry(context, convertedActivityItems);
44+
45+
let selectedActivityItems: ConvertedActivityItem[] = convertedActivityItems.filter(item => !(item as ExcludedActivityItem)._exclude);
46+
logSelectedActivityTelemetry(context, selectedActivityItems);
47+
48+
if (!context.activitySelectedCache.selectionCount) {
49+
// If no items were selected (i.e. invoked mcp without using a VS Code command), default to providing the entire activity tree.
50+
selectedActivityItems = convertedActivityItems;
51+
} else if (selectedActivityItems.length !== context.activitySelectedCache.selectionCount) {
52+
// If we weren't able to verify all of the selected items, fallback to providing the entire activity tree
53+
selectedActivityItems = convertedActivityItems;
54+
55+
const warning: string = l10n.t('Failed to provide some of the selected item(s) to Copilot. Falling back to providing the entire activity log tree.');
56+
void context.ui.showWarningMessage(warning);
57+
ext.outputChannel.warn(warning);
58+
}
59+
60+
context.activitySelectedCache.reset();
61+
62+
if (selectedActivityItems.length === 0) {
63+
return {
64+
message:
65+
'No activity log items found.',
66+
activityItems: [],
67+
};
68+
}
69+
70+
return {
71+
message:
72+
'Explain the data from the following activity items. ' +
73+
'Prefer explaining the data more conversationally rather than responding with the raw json data. ' +
74+
'The activities provided are in chronological order.',
75+
activityItems: selectedActivityItems.map(item => JSON.stringify(item)),
76+
};
77+
}

src/chat/tools/GetAzureActivityLog/logTelemetry.ts renamed to src/chat/tools/azureActivityLog/getAzureActivityLog/logTelemetry.ts

File renamed without changes.

src/chat/tools/registerLMTools.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)