Path: blob/main/extensions/copilot/src/extension/githubMcp/vscode-node/githubMcp.contribution.ts
13399 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 { lm } from 'vscode';6import { IAuthenticationService } from '../../../platform/authentication/common/authentication';7import { ConfigKey, IConfigurationService } from '../../../platform/configuration/common/configurationService';8import { ILogService } from '../../../platform/log/common/logService';9import { IExperimentationService } from '../../../platform/telemetry/common/nullExperimentationService';10import { Disposable, IDisposable } from '../../../util/vs/base/common/lifecycle';11import { GitHubMcpDefinitionProvider } from '../common/githubMcpDefinitionProvider';1213export class GitHubMcpContrib extends Disposable {14private disposable?: IDisposable;15private definitionProvider?: GitHubMcpDefinitionProvider;1617constructor(18@IConfigurationService private readonly configurationService: IConfigurationService,19@IExperimentationService private readonly experimentationService: IExperimentationService,20@IAuthenticationService private readonly authenticationService: IAuthenticationService,21@ILogService private readonly logService: ILogService22) {23super();24this._registerConfigurationListener();25if (this.enabled) {26void this._registerGitHubMcpDefinitionProvider();27}28}2930private _registerConfigurationListener() {31this._register(this.configurationService.onDidChangeConfiguration(e => {32if (e.affectsConfiguration(ConfigKey.GitHubMcpEnabled.fullyQualifiedId)) {33if (this.enabled) {34void this._registerGitHubMcpDefinitionProvider();35} else {36this.logService.trace('Unregistering GitHub MCP Definition Provider.');37this.disposable?.dispose();38this.disposable = undefined;39this.definitionProvider = undefined;40}41}42}));43}4445private async _registerGitHubMcpDefinitionProvider() {46if (!this.definitionProvider) {47this.logService.trace('Registering GitHub MCP Definition Provider.');48// Register the GitHub MCP Definition Provider49this.definitionProvider = new GitHubMcpDefinitionProvider(this.configurationService, this.authenticationService, this.logService);50this.disposable = lm.registerMcpServerDefinitionProvider('github', this.definitionProvider);51}52}5354private get enabled(): boolean {55return this.configurationService.getExperimentBasedConfig(ConfigKey.GitHubMcpEnabled, this.experimentationService);56}57}585960