Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/mcp/src/automationTools/extensions.ts
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { McpServer, RegisteredTool } from '@modelcontextprotocol/sdk/server/mcp.js';
7
import { ApplicationService } from '../application';
8
import { z } from 'zod';
9
10
/**
11
* Extensions Tools
12
*/
13
export function applyExtensionsTools(server: McpServer, appService: ApplicationService): RegisteredTool[] {
14
const tools: RegisteredTool[] = [];
15
16
// Playwright can probably figure this out
17
// server.tool(
18
// 'vscode_automation_extensions_search',
19
// 'Search for an extension by ID',
20
// {
21
// extensionId: z.string().describe('Extension ID to search for (e.g., "ms-python.python")')
22
// },
23
// async (args) => {
24
// const { extensionId } = args;
25
// await app.workbench.extensions.searchForExtension(extensionId);
26
// return {
27
// content: [{
28
// type: 'text' as const,
29
// text: `Searched for extension: ${extensionId}`
30
// }]
31
// };
32
// }
33
// );
34
35
tools.push(server.tool(
36
'vscode_automation_extensions_open',
37
'Open an extension by ID',
38
{
39
extensionId: z.string().describe('Extension ID to open (e.g., "ms-python.python")')
40
},
41
async (args) => {
42
const { extensionId } = args;
43
const app = await appService.getOrCreateApplication();
44
await app.workbench.extensions.openExtension(extensionId);
45
return {
46
content: [{
47
type: 'text' as const,
48
text: `Opened extension: ${extensionId}`
49
}]
50
};
51
}
52
));
53
54
// Playwright can probably figure this out
55
// server.tool(
56
// 'vscode_automation_extensions_close',
57
// 'Close an extension tab by title',
58
// {
59
// title: z.string().describe('Extension title to close')
60
// },
61
// async (args) => {
62
// const { title } = args;
63
// await app.workbench.extensions.closeExtension(title);
64
// return {
65
// content: [{
66
// type: 'text' as const,
67
// text: `Closed extension: ${title}`
68
// }]
69
// };
70
// }
71
// );
72
73
tools.push(server.tool(
74
'vscode_automation_extensions_install',
75
'Install an extension by ID',
76
{
77
extensionId: z.string().describe('Extension ID to install (e.g., "ms-python.python")'),
78
waitUntilEnabled: z.boolean().optional().default(true).describe('Whether to wait until the extension is enabled')
79
},
80
async (args) => {
81
const { extensionId, waitUntilEnabled = true } = args;
82
const app = await appService.getOrCreateApplication();
83
await app.workbench.extensions.installExtension(extensionId, waitUntilEnabled);
84
return {
85
content: [{
86
type: 'text' as const,
87
text: `Installed extension: ${extensionId}${waitUntilEnabled ? ' (waited until enabled)' : ''}`
88
}]
89
};
90
}
91
));
92
93
return tools;
94
}
95
96