From 1ed79ef9859dc9e674e42245ca036fdbebba4756 Mon Sep 17 00:00:00 2001 From: Joaquin Coromina Date: Tue, 13 May 2025 02:37:06 -0400 Subject: [PATCH] Added function to create mcp config file if it doesnt exist --- .../contrib/void/common/mcpConfigService.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/void/common/mcpConfigService.ts b/src/vs/workbench/contrib/void/common/mcpConfigService.ts index 53aaed7f..39acdfce 100644 --- a/src/vs/workbench/contrib/void/common/mcpConfigService.ts +++ b/src/vs/workbench/contrib/void/common/mcpConfigService.ts @@ -11,6 +11,7 @@ import { IFileService } from '../../../../platform/files/common/files.js'; import { IPathService } from '../../../services/path/common/pathService.js'; import { join } from '../../../../base/common/path.js'; import { IProductService } from '../../../../platform/product/common/productService.js'; +import { VSBuffer } from '../../../../base/common/buffer.js'; export interface IMCPConfigService { readonly _serviceBrand: undefined; @@ -25,6 +26,11 @@ class MCPConfigService extends Disposable implements IMCPConfigService { _serviceBrand: undefined; private readonly MCP_CONFIG_FILE_NAME = 'mcp.json'; + private readonly MCP_CONFIG_SAMPLE = { + mcpServers: [], + } + private readonly MCP_CONFIG_SAMPLE_STRING = JSON.stringify(this.MCP_CONFIG_SAMPLE, null, 2); + constructor( @IFileService private readonly fileService: IFileService, @IPathService private readonly pathService: IPathService, @@ -38,8 +44,14 @@ class MCPConfigService extends Disposable implements IMCPConfigService { private async _initialize() { // Check logs - const doesMCPExist = await this.configFileExists(); - console.log('MCP Config File Exists:', doesMCPExist); + const mcpExists = await this.configFileExists(); + if (!mcpExists) { + console.log('MCP Config file does not exist. Creating...'); + await this.createMCPConfigFile(); + } else { + console.log('MCP Config file already exists.'); + } + } async getMCPConfigPath(): Promise { @@ -63,6 +75,18 @@ class MCPConfigService extends Disposable implements IMCPConfigService { return false; } } + + async createMCPConfigFile(): Promise { + const mcpConfigUri = await this.getMCPConfigPath(); + + // Create the directory if it doesn't exist + await this.fileService.createFile(mcpConfigUri.with({ path: mcpConfigUri.path })); + + const buffer = VSBuffer.fromString(this.MCP_CONFIG_SAMPLE_STRING); + + // Create the MCP config file with default content + await this.fileService.writeFile(mcpConfigUri, buffer); + } } registerSingleton(IMCPConfigService, MCPConfigService, InstantiationType.Delayed);