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