Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/mcp/src/automation.ts
5248 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 } from '@modelcontextprotocol/sdk/server/mcp.js';
7
import { ApplicationService } from './application';
8
import { applyAllTools } from './automationTools/index.js';
9
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
10
import { z } from 'zod';
11
12
export async function getServer(appService: ApplicationService): Promise<Server> {
13
const server = new McpServer({
14
name: 'VS Code Automation Server',
15
version: '1.0.0',
16
title: 'An MCP Server that can interact with a local build of VS Code. Used for verifying UI behavior.'
17
}, { capabilities: { logging: {} } });
18
19
server.tool(
20
'vscode_automation_start',
21
'Start VS Code Build. If workspacePath is not provided, VS Code will open with the last used workspace or an empty window.',
22
{
23
recordVideo: z.boolean().optional().describe('Whether to record a video of the session'),
24
workspacePath: z.string().optional().describe('Optional path to a workspace or folder to open. If not provided, opens the last used workspace.')
25
},
26
async ({ recordVideo, workspacePath }) => {
27
const app = await appService.getOrCreateApplication({ recordVideo, workspacePath });
28
await app.startTracing();
29
return {
30
content: [{
31
type: 'text' as const,
32
text: app ? `VS Code started successfully${workspacePath ? ` with workspace: ${workspacePath}` : ''}` : `Failed to start VS Code`
33
}]
34
};
35
}
36
);
37
38
// Apply all VS Code automation tools using the modular structure
39
const registeredTools = applyAllTools(server, appService);
40
const app = appService.application;
41
if (app) {
42
registeredTools.forEach(t => t.enable());
43
} else {
44
registeredTools.forEach(t => t.disable());
45
}
46
47
appService.onApplicationChange(app => {
48
if (app) {
49
registeredTools.forEach(t => t.enable());
50
} else {
51
registeredTools.forEach(t => t.disable());
52
}
53
});
54
55
return server.server;
56
}
57
58