Path: blob/main/test/mcp/src/automationTools/notebook.ts
3520 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { McpServer, RegisteredTool } from '@modelcontextprotocol/sdk/server/mcp.js';6import { ApplicationService } from '../application';7import { z } from 'zod';89/**10* Notebook Tools11*/12export function applyNotebookTools(server: McpServer, appService: ApplicationService): RegisteredTool[] {13const tools: RegisteredTool[] = [];1415tools.push(server.tool(16'vscode_automation_notebook_open',17'Open a notebook',18async () => {19const app = await appService.getOrCreateApplication();20await app.workbench.notebook.openNotebook();21return {22content: [{23type: 'text' as const,24text: 'Opened notebook'25}]26};27}28));2930// Playwright can probably figure this one out31// server.tool(32// 'vscode_automation_notebook_focus_next_cell',33// 'Focus the next cell in the notebook',34// async () => {35// await app.workbench.notebook.focusNextCell();36// return {37// content: [{38// type: 'text' as const,39// text: 'Focused next cell'40// }]41// };42// }43// );4445// Playwright can probably figure this one out46// server.tool(47// 'vscode_automation_notebook_focus_first_cell',48// 'Focus the first cell in the notebook',49// async () => {50// await app.workbench.notebook.focusFirstCell();51// return {52// content: [{53// type: 'text' as const,54// text: 'Focused first cell'55// }]56// };57// }58// );5960tools.push(server.tool(61'vscode_automation_notebook_edit_cell',62'Enter edit mode for the current cell',63async () => {64const app = await appService.getOrCreateApplication();65await app.workbench.notebook.editCell();66return {67content: [{68type: 'text' as const,69text: 'Entered cell edit mode'70}]71};72}73));7475// Seems too niche76// server.tool(77// 'vscode_automation_notebook_stop_editing_cell',78// 'Exit edit mode for the current cell',79// async () => {80// await app.workbench.notebook.stopEditingCell();81// return {82// content: [{83// type: 'text' as const,84// text: 'Exited cell edit mode'85// }]86// };87// }88// );8990tools.push(server.tool(91'vscode_automation_notebook_type_in_editor',92'Type text in the notebook cell editor',93{94text: z.string().describe('Text to type in the cell editor')95},96async (args) => {97const { text } = args;98const app = await appService.getOrCreateApplication();99await app.workbench.notebook.waitForTypeInEditor(text);100return {101content: [{102type: 'text' as const,103text: `Typed in notebook cell: "${text}"`104}]105};106}107));108109// Playwright can probably figure this one out110// server.tool(111// 'vscode_automation_notebook_wait_for_cell_contents',112// 'Wait for specific contents in the active cell editor',113// {114// contents: z.string().describe('Expected contents in the active cell')115// },116// async (args) => {117// const { contents } = args;118// await app.workbench.notebook.waitForActiveCellEditorContents(contents);119// return {120// content: [{121// type: 'text' as const,122// text: `Active cell contains expected contents: "${contents}"`123// }]124// };125// }126// );127128// Playwright can probably figure this one out129// server.tool(130// 'vscode_automation_notebook_wait_for_markdown_contents',131// 'Wait for specific text in markdown cell output',132// {133// markdownSelector: z.string().describe('CSS selector for the markdown element'),134// text: z.string().describe('Expected text in the markdown output')135// },136// async (args) => {137// const { markdownSelector, text } = args;138// await app.workbench.notebook.waitForMarkdownContents(markdownSelector, text);139// return {140// content: [{141// type: 'text' as const,142// text: `Markdown content found: "${text}" in ${markdownSelector}`143// }]144// };145// }146// );147148// Playwright can probably figure this one out149// server.tool(150// 'vscode_automation_notebook_insert_cell',151// 'Insert a new cell of specified type',152// {153// kind: z.enum(['markdown', 'code']).describe('Type of cell to insert')154// },155// async (args) => {156// const { kind } = args;157// await app.workbench.notebook.insertNotebookCell(kind);158// return {159// content: [{160// type: 'text' as const,161// text: `Inserted ${kind} cell`162// }]163// };164// }165// );166167// Playwright can probably figure this one out168// server.tool(169// 'vscode_automation_notebook_delete_active_cell',170// 'Delete the currently active cell',171// async () => {172// await app.workbench.notebook.deleteActiveCell();173// return {174// content: [{175// type: 'text' as const,176// text: 'Deleted active cell'177// }]178// };179// }180// );181182// Seems too niche183// server.tool(184// 'vscode_automation_notebook_focus_in_cell_output',185// 'Focus inside cell output area',186// async () => {187// await app.workbench.notebook.focusInCellOutput();188// return {189// content: [{190// type: 'text' as const,191// text: 'Focused in cell output'192// }]193// };194// }195// );196197// Seems too niche198// server.tool(199// 'vscode_automation_notebook_focus_out_cell_output',200// 'Focus outside cell output area',201// async () => {202// await app.workbench.notebook.focusOutCellOutput();203// return {204// content: [{205// type: 'text' as const,206// text: 'Focused out of cell output'207// }]208// };209// }210// );211212// Playwright can probably figure this one out213// server.tool(214// 'vscode_automation_notebook_execute_active_cell',215// 'Execute the currently active cell',216// async () => {217// await app.workbench.notebook.executeActiveCell();218// return {219// content: [{220// type: 'text' as const,221// text: 'Executed active cell'222// }]223// };224// }225// );226227// Playwright can probably figure this one out228// server.tool(229// 'vscode_automation_notebook_execute_cell_action',230// 'Execute a specific cell action using CSS selector',231// {232// selector: z.string().describe('CSS selector for the cell action to execute')233// },234// async (args) => {235// const { selector } = args;236// await app.workbench.notebook.executeCellAction(selector);237// return {238// content: [{239// type: 'text' as const,240// text: `Executed cell action: ${selector}`241// }]242// };243// }244// );245246return tools;247}248249250