Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/mcp/src/automationTools/notebook.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
* Notebook Tools
12
*/
13
export function applyNotebookTools(server: McpServer, appService: ApplicationService): RegisteredTool[] {
14
const tools: RegisteredTool[] = [];
15
16
tools.push(server.tool(
17
'vscode_automation_notebook_open',
18
'Open a notebook',
19
async () => {
20
const app = await appService.getOrCreateApplication();
21
await app.workbench.notebook.openNotebook();
22
return {
23
content: [{
24
type: 'text' as const,
25
text: 'Opened notebook'
26
}]
27
};
28
}
29
));
30
31
// Playwright can probably figure this one out
32
// server.tool(
33
// 'vscode_automation_notebook_focus_next_cell',
34
// 'Focus the next cell in the notebook',
35
// async () => {
36
// await app.workbench.notebook.focusNextCell();
37
// return {
38
// content: [{
39
// type: 'text' as const,
40
// text: 'Focused next cell'
41
// }]
42
// };
43
// }
44
// );
45
46
// Playwright can probably figure this one out
47
// server.tool(
48
// 'vscode_automation_notebook_focus_first_cell',
49
// 'Focus the first cell in the notebook',
50
// async () => {
51
// await app.workbench.notebook.focusFirstCell();
52
// return {
53
// content: [{
54
// type: 'text' as const,
55
// text: 'Focused first cell'
56
// }]
57
// };
58
// }
59
// );
60
61
tools.push(server.tool(
62
'vscode_automation_notebook_edit_cell',
63
'Enter edit mode for the current cell',
64
async () => {
65
const app = await appService.getOrCreateApplication();
66
await app.workbench.notebook.editCell();
67
return {
68
content: [{
69
type: 'text' as const,
70
text: 'Entered cell edit mode'
71
}]
72
};
73
}
74
));
75
76
// Seems too niche
77
// server.tool(
78
// 'vscode_automation_notebook_stop_editing_cell',
79
// 'Exit edit mode for the current cell',
80
// async () => {
81
// await app.workbench.notebook.stopEditingCell();
82
// return {
83
// content: [{
84
// type: 'text' as const,
85
// text: 'Exited cell edit mode'
86
// }]
87
// };
88
// }
89
// );
90
91
tools.push(server.tool(
92
'vscode_automation_notebook_type_in_editor',
93
'Type text in the notebook cell editor',
94
{
95
text: z.string().describe('Text to type in the cell editor')
96
},
97
async (args) => {
98
const { text } = args;
99
const app = await appService.getOrCreateApplication();
100
await app.workbench.notebook.waitForTypeInEditor(text);
101
return {
102
content: [{
103
type: 'text' as const,
104
text: `Typed in notebook cell: "${text}"`
105
}]
106
};
107
}
108
));
109
110
// Playwright can probably figure this one out
111
// server.tool(
112
// 'vscode_automation_notebook_wait_for_cell_contents',
113
// 'Wait for specific contents in the active cell editor',
114
// {
115
// contents: z.string().describe('Expected contents in the active cell')
116
// },
117
// async (args) => {
118
// const { contents } = args;
119
// await app.workbench.notebook.waitForActiveCellEditorContents(contents);
120
// return {
121
// content: [{
122
// type: 'text' as const,
123
// text: `Active cell contains expected contents: "${contents}"`
124
// }]
125
// };
126
// }
127
// );
128
129
// Playwright can probably figure this one out
130
// server.tool(
131
// 'vscode_automation_notebook_wait_for_markdown_contents',
132
// 'Wait for specific text in markdown cell output',
133
// {
134
// markdownSelector: z.string().describe('CSS selector for the markdown element'),
135
// text: z.string().describe('Expected text in the markdown output')
136
// },
137
// async (args) => {
138
// const { markdownSelector, text } = args;
139
// await app.workbench.notebook.waitForMarkdownContents(markdownSelector, text);
140
// return {
141
// content: [{
142
// type: 'text' as const,
143
// text: `Markdown content found: "${text}" in ${markdownSelector}`
144
// }]
145
// };
146
// }
147
// );
148
149
// Playwright can probably figure this one out
150
// server.tool(
151
// 'vscode_automation_notebook_insert_cell',
152
// 'Insert a new cell of specified type',
153
// {
154
// kind: z.enum(['markdown', 'code']).describe('Type of cell to insert')
155
// },
156
// async (args) => {
157
// const { kind } = args;
158
// await app.workbench.notebook.insertNotebookCell(kind);
159
// return {
160
// content: [{
161
// type: 'text' as const,
162
// text: `Inserted ${kind} cell`
163
// }]
164
// };
165
// }
166
// );
167
168
// Playwright can probably figure this one out
169
// server.tool(
170
// 'vscode_automation_notebook_delete_active_cell',
171
// 'Delete the currently active cell',
172
// async () => {
173
// await app.workbench.notebook.deleteActiveCell();
174
// return {
175
// content: [{
176
// type: 'text' as const,
177
// text: 'Deleted active cell'
178
// }]
179
// };
180
// }
181
// );
182
183
// Seems too niche
184
// server.tool(
185
// 'vscode_automation_notebook_focus_in_cell_output',
186
// 'Focus inside cell output area',
187
// async () => {
188
// await app.workbench.notebook.focusInCellOutput();
189
// return {
190
// content: [{
191
// type: 'text' as const,
192
// text: 'Focused in cell output'
193
// }]
194
// };
195
// }
196
// );
197
198
// Seems too niche
199
// server.tool(
200
// 'vscode_automation_notebook_focus_out_cell_output',
201
// 'Focus outside cell output area',
202
// async () => {
203
// await app.workbench.notebook.focusOutCellOutput();
204
// return {
205
// content: [{
206
// type: 'text' as const,
207
// text: 'Focused out of cell output'
208
// }]
209
// };
210
// }
211
// );
212
213
// Playwright can probably figure this one out
214
// server.tool(
215
// 'vscode_automation_notebook_execute_active_cell',
216
// 'Execute the currently active cell',
217
// async () => {
218
// await app.workbench.notebook.executeActiveCell();
219
// return {
220
// content: [{
221
// type: 'text' as const,
222
// text: 'Executed active cell'
223
// }]
224
// };
225
// }
226
// );
227
228
// Playwright can probably figure this one out
229
// server.tool(
230
// 'vscode_automation_notebook_execute_cell_action',
231
// 'Execute a specific cell action using CSS selector',
232
// {
233
// selector: z.string().describe('CSS selector for the cell action to execute')
234
// },
235
// async (args) => {
236
// const { selector } = args;
237
// await app.workbench.notebook.executeCellAction(selector);
238
// return {
239
// content: [{
240
// type: 'text' as const,
241
// text: `Executed cell action: ${selector}`
242
// }]
243
// };
244
// }
245
// );
246
247
return tools;
248
}
249
250