From b4dff124e0b52c44a1120a46512992e90082f691 Mon Sep 17 00:00:00 2001 From: Joaquin Coromina Date: Tue, 13 May 2025 02:00:50 -0400 Subject: [PATCH] Updated file with class MCPConfigService and functions to check if mcp.json config file exists or not --- .../contrib/void/common/mcpConfigService.ts | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/vs/workbench/contrib/void/common/mcpConfigService.ts b/src/vs/workbench/contrib/void/common/mcpConfigService.ts index e69de29b..0b5b99d2 100644 --- a/src/vs/workbench/contrib/void/common/mcpConfigService.ts +++ b/src/vs/workbench/contrib/void/common/mcpConfigService.ts @@ -0,0 +1,67 @@ +/*-------------------------------------------------------------------------------------- + * Copyright 2025 Glass Devtools, Inc. All rights reserved. + * Licensed under the Apache License, Version 2.0. See LICENSE.txt for more information. + *--------------------------------------------------------------------------------------*/ + +import { URI } from '../../../../base/common/uri.js'; +import { Disposable } from '../../../../base/common/lifecycle.js'; +import { registerSingleton, InstantiationType } from '../../../../platform/instantiation/common/extensions.js'; +import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js'; +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'; + +export interface IMCPConfigService { + readonly _serviceBrand: undefined; + + getMCPConfigPath(): Promise; + // configFileExists(): Promise; +} + +export const IMCPConfigService = createDecorator('mcpConfigService'); + +class MCPConfigService extends Disposable implements IMCPConfigService { + _serviceBrand: undefined; + + constructor( + @IFileService private readonly fileService: IFileService, + @IPathService private readonly pathService: IPathService, + @IProductService private readonly productService: IProductService + ) { + super(); + this._initialize(); + } + + + + private async _initialize() { + // Check logs + const doesMCPExist = await this.configFileExists(); + console.log('MCP Config File Exists:', doesMCPExist); + } + + async getMCPConfigPath(): Promise { + // Get the appropriate directory based on dev mode + const appName = this.productService.dataFolderName + + const userHome = await this.pathService.userHome(); + const mcpConfigPath = join(userHome.path, appName, 'mcp.json'); + return URI.file(mcpConfigPath); + } + + async configFileExists(): Promise { + try { + const mcpConfigUri = await this.getMCPConfigPath(); + + // Try to get file stats - if it succeeds, the file exists + await this.fileService.stat(mcpConfigUri); + return true; + } catch (error) { + // File doesn't exist or can't be accessed + return false; + } + } +} + +registerSingleton(IMCPConfigService, MCPConfigService, InstantiationType.Delayed);