@@ -8,14 +8,9 @@ import { IEnvironmentService } from '../../environment/common/environment.js';
88import { IFileService } from '../../files/common/files.js' ;
99import { ILogService } from '../../log/common/log.js' ;
1010import { IUriIdentityService } from '../../uriIdentity/common/uriIdentity.js' ;
11- import { IGalleryMcpServer , IMcpGalleryService , IMcpManagementService , InstallOptions , ILocalMcpServer , RegistryType , IInstallableMcpServer , IGalleryMcpServerConfiguration } from '../common/mcpManagement.js' ;
11+ import { IGalleryMcpServer , IMcpGalleryService , IMcpManagementService , InstallOptions , ILocalMcpServer , RegistryType , IInstallableMcpServer } from '../common/mcpManagement.js' ;
1212import { McpUserResourceManagementService as CommonMcpUserResourceManagementService , McpManagementService as CommonMcpManagementService } from '../common/mcpManagementService.js' ;
1313import { IMcpResourceScannerService } from '../common/mcpResourceScannerService.js' ;
14- import { McpServerType } from '../common/mcpPlatformTypes.js' ;
15- import { INpmPackageManagementService } from './npmPackageService.js' ;
16- import { Schemas } from '../../../base/common/network.js' ;
17- import { IConfigurationService } from '../../configuration/common/configuration.js' ;
18-
1914
2015export class McpUserResourceManagementService extends CommonMcpUserResourceManagementService {
2116 constructor (
@@ -26,8 +21,6 @@ export class McpUserResourceManagementService extends CommonMcpUserResourceManag
2621 @ILogService logService : ILogService ,
2722 @IMcpResourceScannerService mcpResourceScannerService : IMcpResourceScannerService ,
2823 @IEnvironmentService environmentService : IEnvironmentService ,
29- @IConfigurationService private readonly configurationService : IConfigurationService ,
30- @INpmPackageManagementService private readonly npmPackageService : INpmPackageManagementService ,
3124 ) {
3225 super ( mcpResource , mcpGalleryService , fileService , uriIdentityService , logService , mcpResourceScannerService , environmentService ) ;
3326 }
@@ -41,9 +34,7 @@ export class McpUserResourceManagementService extends CommonMcpUserResourceManag
4134 const manifest = await this . updateMetadataFromGallery ( server ) ;
4235 const packageType = options ?. packageType ?? manifest . packages ?. [ 0 ] ?. registry_type ?? RegistryType . REMOTE ;
4336
44- const { config, inputs } = packageType === RegistryType . NODE
45- ? await this . getNodePackageMcpServerConfiguration ( server , manifest )
46- : this . getMcpServerConfigurationFromManifest ( manifest , packageType ) ;
37+ const { config, inputs } = this . getMcpServerConfigurationFromManifest ( manifest , packageType ) ;
4738
4839 const installable : IInstallableMcpServer = {
4940 name : server . name ,
@@ -69,73 +60,6 @@ export class McpUserResourceManagementService extends CommonMcpUserResourceManag
6960 }
7061 }
7162
72- private async getNodePackageMcpServerConfiguration ( server : IGalleryMcpServer , manifest : IGalleryMcpServerConfiguration ) : Promise < Omit < IInstallableMcpServer , 'name' > > {
73- if ( this . configurationService . getValue ( 'chat.mcp.enableNpmInstall' ) !== true ) {
74- return this . getMcpServerConfigurationFromManifest ( manifest , RegistryType . NODE ) ;
75- }
76-
77- const nodePackage = manifest . packages ?. find ( p => p . registry_type === RegistryType . NODE ) ;
78- if ( ! nodePackage ) {
79- throw new Error ( 'No npm package found in manifest' ) ;
80- }
81-
82- const location = this . getLocation ( server . name , server . version ) ;
83- if ( ! ( await this . fileService . exists ( location ) ) ) {
84- await this . fileService . createFolder ( location ) ;
85- }
86-
87- const packageVersion = ! nodePackage . version || nodePackage . version === 'latest' ? await this . npmPackageService . getLatestPackageVersion ( nodePackage . identifier ) : nodePackage . version ;
88- await this . npmPackageService . installPackage ( nodePackage . identifier , packageVersion , location . with ( { scheme : Schemas . file } ) . fsPath ) ;
89-
90- const entryPoint = await this . findPackageEntryPoint ( nodePackage . identifier , location ) ;
91- const result = this . getMcpServerConfigurationFromManifest ( manifest , RegistryType . NODE ) ;
92- if ( result . config . type === McpServerType . LOCAL && result . config . args ) {
93- const newArgs = [ ...result . config . args ] ;
94- newArgs [ 0 ] = entryPoint . with ( { scheme : Schemas . file } ) . fsPath ;
95- return {
96- config : {
97- ...result . config ,
98- command : 'node' ,
99- args : newArgs ,
100- version : server . version
101- } ,
102- inputs : result . inputs
103- } ;
104- }
105- return result ;
106- }
107-
108- private async findPackageEntryPoint ( packageName : string , packageLocation : URI ) : Promise < URI > {
109- const nodeModulesPath = this . uriIdentityService . extUri . joinPath ( packageLocation , 'node_modules' , packageName ) ;
110- const packageJsonPath = this . uriIdentityService . extUri . joinPath ( nodeModulesPath , 'package.json' ) ;
111-
112- try {
113- const packageJsonContent = await this . fileService . readFile ( packageJsonPath ) ;
114- const packageJson = JSON . parse ( packageJsonContent . value . toString ( ) ) ;
115-
116- if ( packageJson . bin ) {
117- if ( typeof packageJson . bin === 'string' ) {
118- return this . uriIdentityService . extUri . joinPath ( nodeModulesPath , packageJson . bin ) ;
119- } else if ( typeof packageJson . bin === 'object' ) {
120- const binName = packageJson . bin [ packageName ] || Object . values ( packageJson . bin ) [ 0 ] ;
121- if ( binName ) {
122- return this . uriIdentityService . extUri . joinPath ( nodeModulesPath , binName as string ) ;
123- }
124- }
125- }
126-
127- if ( packageJson . main ) {
128- return this . uriIdentityService . extUri . joinPath ( nodeModulesPath , packageJson . main ) ;
129- }
130-
131- return this . uriIdentityService . extUri . joinPath ( nodeModulesPath , 'index.js' ) ;
132-
133- } catch ( error ) {
134- this . logService . error ( 'Failed to read package.json for entry point' , packageName , error ) ;
135- throw new Error ( `Could not find entry point for package ${ packageName } ` ) ;
136- }
137- }
138-
13963}
14064
14165export class McpManagementService extends CommonMcpManagementService implements IMcpManagementService {
0 commit comments