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