Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/mcp/src/automationTools/core.ts
5251 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 { z } from 'zod';
8
import { ApplicationService } from '../application';
9
10
/**
11
* Core Application Management Tools
12
*/
13
export function applyCoreTools(server: McpServer, appService: ApplicationService): RegisteredTool[] {
14
const tools: RegisteredTool[] = [];
15
16
tools.push(server.tool(
17
'vscode_automation_restart',
18
'Restart VS Code with optional workspace or folder and extra command-line arguments',
19
{
20
workspaceOrFolder: z.string().optional().describe('Path to a workspace or folder to open on restart'),
21
extraArgs: z.array(z.string()).optional().describe('Extra CLI arguments to pass on restart')
22
},
23
async ({ workspaceOrFolder, extraArgs }) => {
24
const app = await appService.getOrCreateApplication();
25
await app.restart({ workspaceOrFolder, extraArgs });
26
const workspaceText = workspaceOrFolder ? ` with workspace: ${workspaceOrFolder}` : '';
27
const argsText = extraArgs?.length ? ` (args: ${extraArgs.join(' ')})` : '';
28
return {
29
content: [{
30
type: 'text' as const,
31
text: `VS Code restarted successfully${workspaceText}${argsText}`
32
}]
33
};
34
}
35
));
36
37
tools.push(server.tool(
38
'vscode_automation_stop',
39
'Stop the VS Code application',
40
async () => {
41
const app = await appService.getOrCreateApplication();
42
await app.stopTracing(undefined, true);
43
await app.stop();
44
return {
45
content: [{
46
type: 'text' as const,
47
text: 'VS Code stopped successfully'
48
}]
49
};
50
}
51
));
52
53
// This doesn't seem particularly useful
54
// server.tool(
55
// 'vscode_automation_get_quality',
56
// 'Get the quality/build type of VS Code (Dev, Insiders, Stable, etc.)',
57
// async () => {
58
// const info = {
59
// quality: app.quality,
60
// remote: app.remote,
61
// web: app.web,
62
// workspacePathOrFolder: app.workspacePathOrFolder,
63
// extensionsPath: app.extensionsPath,
64
// userDataPath: app.userDataPath
65
// };
66
// return {
67
// content: [{
68
// type: 'text' as const,
69
// text: `VS Code Info:\n${JSON.stringify(info, null, 2)}`
70
// }]
71
// };
72
// }
73
// );
74
75
// This doesn't seem particularly useful
76
// server.tool(
77
// 'vscode_automation_wait_for_element',
78
// 'Wait for a UI element to appear using CSS selector - prefer using specific workbench methods when available',
79
// {
80
// selector: z.string().describe('CSS selector for the element to wait for'),
81
// timeout: z.number().optional().default(20).describe('Timeout in seconds (default: 20)')
82
// },
83
// async (args) => {
84
// const { selector, timeout = 20 } = args;
85
// const retryCount = Math.floor((timeout * 1000) / 100); // 100ms intervals
86
// const element = await app.code.waitForElement(selector, undefined, retryCount);
87
// return {
88
// content: [{
89
// type: 'text' as const,
90
// text: `Element found: ${selector} (${!!element ? 'success' : 'not found'})`
91
// }]
92
// };
93
// }
94
// );
95
96
// Defer to Playwright's tool
97
// server.tool(
98
// 'vscode_automation_click_element',
99
// 'Click on a UI element - prefer using specific workbench methods when available',
100
// {
101
// selector: z.string().describe('CSS selector for the element to click'),
102
// xOffset: z.number().optional().describe('Optional X offset from element center'),
103
// yOffset: z.number().optional().describe('Optional Y offset from element center')
104
// },
105
// async (args) => {
106
// const { selector, xOffset, yOffset } = args;
107
// await app.code.waitAndClick(selector, xOffset, yOffset);
108
// return {
109
// content: [{
110
// type: 'text' as const,
111
// text: `Clicked element: ${selector}${xOffset !== undefined ? ` (offset: ${xOffset}, ${yOffset})` : ''}`
112
// }]
113
// };
114
// }
115
// );
116
117
// Defer to Playwright's tool
118
// server.tool(
119
// 'vscode_automation_send_keybinding',
120
// 'Send a keybinding to VS Code (e.g., ctrl+shift+p, cmd+s)',
121
// {
122
// keybinding: z.string().describe('The keybinding to send (e.g., ctrl+shift+p, cmd+s, escape)'),
123
// waitSelector: z.string().optional().describe('Optional CSS selector to wait for after sending the keybinding')
124
// },
125
// async (args) => {
126
// const { keybinding, waitSelector } = args;
127
// await app.code.dispatchKeybinding(keybinding, async () => {
128
// if (waitSelector) {
129
// await app.code.waitForElement(waitSelector);
130
// }
131
// });
132
// return {
133
// content: [{
134
// type: 'text' as const,
135
// text: `Sent keybinding: ${keybinding}${waitSelector ? ` (waited for: ${waitSelector})` : ''}`
136
// }]
137
// };
138
// }
139
// );
140
141
// Defer to Playwright's tool
142
// server.tool(
143
// 'vscode_automation_get_text_content',
144
// 'Get text content from a UI element using CSS selector',
145
// {
146
// selector: z.string().describe('CSS selector for the element'),
147
// expectedText: z.string().optional().describe('Optional expected text to wait for')
148
// },
149
// async (args) => {
150
// const { selector, expectedText } = args;
151
// const text = await app.code.waitForTextContent(selector, expectedText);
152
// return {
153
// content: [{
154
// type: 'text' as const,
155
// text: `Text content from ${selector}: "${text}"`
156
// }]
157
// };
158
// }
159
// );
160
161
return tools;
162
}
163
164