@google/gemini-cli-core 0.1.12-nightly.250714.b018e2d3 → 0.1.13-nightly.250726.fb751c54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -3
- package/dist/google-gemini-cli-core-0.1.13.tgz +0 -0
- package/dist/src/code_assist/codeAssist.js +2 -2
- package/dist/src/code_assist/codeAssist.js.map +1 -1
- package/dist/src/code_assist/oauth2.js +46 -5
- package/dist/src/code_assist/oauth2.js.map +1 -1
- package/dist/src/code_assist/oauth2.test.js +107 -10
- package/dist/src/code_assist/oauth2.test.js.map +1 -1
- package/dist/src/code_assist/server.d.ts +4 -6
- package/dist/src/code_assist/server.js +4 -69
- package/dist/src/code_assist/server.js.map +1 -1
- package/dist/src/code_assist/server.test.js +10 -2
- package/dist/src/code_assist/server.test.js.map +1 -1
- package/dist/src/code_assist/setup.d.ts +6 -1
- package/dist/src/code_assist/setup.js +4 -1
- package/dist/src/code_assist/setup.js.map +1 -1
- package/dist/src/code_assist/setup.test.js +4 -1
- package/dist/src/code_assist/setup.test.js.map +1 -1
- package/dist/src/code_assist/types.d.ts +2 -2
- package/dist/src/config/config.d.ts +55 -11
- package/dist/src/config/config.js +85 -33
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +29 -26
- package/dist/src/config/config.test.js.map +1 -1
- package/dist/src/config/flashFallback.test.js +1 -1
- package/dist/src/config/flashFallback.test.js.map +1 -1
- package/dist/src/core/client.d.ts +8 -3
- package/dist/src/core/client.js +62 -3
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +145 -37
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/contentGenerator.d.ts +3 -2
- package/dist/src/core/contentGenerator.js +5 -4
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/contentGenerator.test.js +12 -5
- package/dist/src/core/contentGenerator.test.js.map +1 -1
- package/dist/src/core/coreToolScheduler.js +14 -1
- package/dist/src/core/coreToolScheduler.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +84 -2
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/geminiChat.d.ts +4 -3
- package/dist/src/core/geminiChat.js +8 -11
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/geminiRequest.js +2 -37
- package/dist/src/core/geminiRequest.js.map +1 -1
- package/dist/src/core/logger.js +6 -0
- package/dist/src/core/logger.js.map +1 -1
- package/dist/src/core/logger.test.js +1 -1
- package/dist/src/core/logger.test.js.map +1 -1
- package/dist/src/core/modelCheck.d.ts +1 -1
- package/dist/src/core/modelCheck.js +10 -3
- package/dist/src/core/modelCheck.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.test.js +8 -5
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
- package/dist/src/core/prompts.js +42 -18
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/prompts.test.js +121 -4
- package/dist/src/core/prompts.test.js.map +1 -1
- package/dist/src/core/turn.d.ts +12 -3
- package/dist/src/core/turn.js +10 -0
- package/dist/src/core/turn.js.map +1 -1
- package/dist/src/core/turn.test.js +129 -0
- package/dist/src/core/turn.test.js.map +1 -1
- package/dist/src/ide/ide-client.d.ts +28 -0
- package/dist/src/ide/ide-client.js +79 -0
- package/dist/src/ide/ide-client.js.map +1 -0
- package/dist/src/ide/ideContext.d.ts +174 -0
- package/dist/src/ide/ideContext.js +101 -0
- package/dist/src/ide/ideContext.js.map +1 -0
- package/dist/src/ide/ideContext.test.js +111 -0
- package/dist/src/ide/ideContext.test.js.map +1 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +13 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/google-auth-provider.d.ts +23 -0
- package/dist/src/mcp/google-auth-provider.js +63 -0
- package/dist/src/mcp/google-auth-provider.js.map +1 -0
- package/dist/src/mcp/google-auth-provider.test.d.ts +6 -0
- package/dist/src/mcp/google-auth-provider.test.js +54 -0
- package/dist/src/mcp/google-auth-provider.test.js.map +1 -0
- package/dist/src/mcp/oauth-provider.d.ts +142 -0
- package/dist/src/mcp/oauth-provider.js +446 -0
- package/dist/src/mcp/oauth-provider.js.map +1 -0
- package/dist/src/mcp/oauth-provider.test.d.ts +6 -0
- package/dist/src/mcp/oauth-provider.test.js +520 -0
- package/dist/src/mcp/oauth-provider.test.js.map +1 -0
- package/dist/src/mcp/oauth-token-storage.d.ts +81 -0
- package/dist/src/mcp/oauth-token-storage.js +149 -0
- package/dist/src/mcp/oauth-token-storage.js.map +1 -0
- package/dist/src/mcp/oauth-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/oauth-token-storage.test.js +205 -0
- package/dist/src/mcp/oauth-token-storage.test.js.map +1 -0
- package/dist/src/mcp/oauth-utils.d.ts +109 -0
- package/dist/src/mcp/oauth-utils.js +183 -0
- package/dist/src/mcp/oauth-utils.js.map +1 -0
- package/dist/src/mcp/oauth-utils.test.d.ts +6 -0
- package/dist/src/mcp/oauth-utils.test.js +144 -0
- package/dist/src/mcp/oauth-utils.test.js.map +1 -0
- package/dist/src/prompts/mcp-prompts.d.ts +8 -0
- package/dist/src/prompts/mcp-prompts.js +13 -0
- package/dist/src/prompts/mcp-prompts.js.map +1 -0
- package/dist/src/prompts/prompt-registry.d.ts +26 -0
- package/dist/src/prompts/prompt-registry.js +47 -0
- package/dist/src/prompts/prompt-registry.js.map +1 -0
- package/dist/src/services/fileDiscoveryService.test.js +101 -60
- package/dist/src/services/fileDiscoveryService.test.js.map +1 -1
- package/dist/src/services/gitService.js +1 -5
- package/dist/src/services/gitService.js.map +1 -1
- package/dist/src/services/gitService.test.js +68 -92
- package/dist/src/services/gitService.test.js.map +1 -1
- package/dist/src/services/loopDetectionService.d.ts +94 -0
- package/dist/src/services/loopDetectionService.js +318 -0
- package/dist/src/services/loopDetectionService.js.map +1 -0
- package/dist/src/services/loopDetectionService.test.d.ts +6 -0
- package/dist/src/services/loopDetectionService.test.js +266 -0
- package/dist/src/services/loopDetectionService.test.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +5 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +69 -4
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +4 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +9 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
- package/dist/src/telemetry/constants.d.ts +1 -0
- package/dist/src/telemetry/constants.js +1 -0
- package/dist/src/telemetry/constants.js.map +1 -1
- package/dist/src/telemetry/file-exporters.d.ts +28 -0
- package/dist/src/telemetry/file-exporters.js +62 -0
- package/dist/src/telemetry/file-exporters.js.map +1 -0
- package/dist/src/telemetry/integration.test.circular.d.ts +6 -0
- package/dist/src/telemetry/integration.test.circular.js +53 -0
- package/dist/src/telemetry/integration.test.circular.js.map +1 -0
- package/dist/src/telemetry/loggers.d.ts +3 -1
- package/dist/src/telemetry/loggers.js +34 -2
- package/dist/src/telemetry/loggers.js.map +1 -1
- package/dist/src/telemetry/loggers.test.circular.d.ts +6 -0
- package/dist/src/telemetry/loggers.test.circular.js +100 -0
- package/dist/src/telemetry/loggers.test.circular.js.map +1 -0
- package/dist/src/telemetry/sdk.js +17 -6
- package/dist/src/telemetry/sdk.js.map +1 -1
- package/dist/src/telemetry/types.d.ts +19 -1
- package/dist/src/telemetry/types.js +28 -0
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.d.ts +1 -0
- package/dist/src/telemetry/uiTelemetry.js +7 -0
- package/dist/src/telemetry/uiTelemetry.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.test.js +92 -0
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
- package/dist/src/tools/edit.d.ts +7 -12
- package/dist/src/tools/edit.js +34 -32
- package/dist/src/tools/edit.js.map +1 -1
- package/dist/src/tools/edit.test.js +12 -0
- package/dist/src/tools/edit.test.js.map +1 -1
- package/dist/src/tools/glob.d.ts +1 -14
- package/dist/src/tools/glob.js +13 -36
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/glob.test.js +11 -7
- package/dist/src/tools/glob.test.js.map +1 -1
- package/dist/src/tools/grep.d.ts +3 -6
- package/dist/src/tools/grep.js +12 -18
- package/dist/src/tools/grep.js.map +1 -1
- package/dist/src/tools/grep.test.js +9 -6
- package/dist/src/tools/grep.test.js.map +1 -1
- package/dist/src/tools/ls.d.ts +6 -14
- package/dist/src/tools/ls.js +47 -40
- package/dist/src/tools/ls.js.map +1 -1
- package/dist/src/tools/mcp-client.d.ts +83 -1
- package/dist/src/tools/mcp-client.js +613 -148
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +211 -616
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/mcp-tool.d.ts +11 -5
- package/dist/src/tools/mcp-tool.js +34 -10
- package/dist/src/tools/mcp-tool.js.map +1 -1
- package/dist/src/tools/mcp-tool.test.js +74 -24
- package/dist/src/tools/mcp-tool.test.js.map +1 -1
- package/dist/src/tools/memoryTool.js +2 -2
- package/dist/src/tools/memoryTool.js.map +1 -1
- package/dist/src/tools/modifiable-tool.test.js +51 -62
- package/dist/src/tools/modifiable-tool.test.js.map +1 -1
- package/dist/src/tools/read-file.d.ts +3 -3
- package/dist/src/tools/read-file.js +10 -10
- package/dist/src/tools/read-file.js.map +1 -1
- package/dist/src/tools/read-file.test.js +100 -70
- package/dist/src/tools/read-file.test.js.map +1 -1
- package/dist/src/tools/read-many-files.d.ts +6 -10
- package/dist/src/tools/read-many-files.js +74 -43
- package/dist/src/tools/read-many-files.js.map +1 -1
- package/dist/src/tools/read-many-files.test.js +7 -3
- package/dist/src/tools/read-many-files.test.js.map +1 -1
- package/dist/src/tools/shell.d.ts +2 -23
- package/dist/src/tools/shell.js +58 -138
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/shell.test.js +86 -311
- package/dist/src/tools/shell.test.js.map +1 -1
- package/dist/src/tools/tool-registry.d.ts +13 -2
- package/dist/src/tools/tool-registry.js +57 -10
- package/dist/src/tools/tool-registry.js.map +1 -1
- package/dist/src/tools/tool-registry.test.js +112 -41
- package/dist/src/tools/tool-registry.test.js.map +1 -1
- package/dist/src/tools/tools.d.ts +37 -2
- package/dist/src/tools/tools.js +25 -2
- package/dist/src/tools/tools.js.map +1 -1
- package/dist/src/tools/web-fetch.js +7 -2
- package/dist/src/tools/web-fetch.js.map +1 -1
- package/dist/src/tools/web-fetch.test.js +1 -0
- package/dist/src/tools/web-fetch.test.js.map +1 -1
- package/dist/src/tools/web-search.js +2 -2
- package/dist/src/tools/web-search.js.map +1 -1
- package/dist/src/tools/write-file.d.ts +0 -8
- package/dist/src/tools/write-file.js +14 -23
- package/dist/src/tools/write-file.js.map +1 -1
- package/dist/src/utils/bfsFileSearch.d.ts +2 -0
- package/dist/src/utils/bfsFileSearch.js +4 -1
- package/dist/src/utils/bfsFileSearch.js.map +1 -1
- package/dist/src/utils/bfsFileSearch.test.js +108 -105
- package/dist/src/utils/bfsFileSearch.test.js.map +1 -1
- package/dist/src/utils/browser.d.ts +13 -0
- package/dist/src/utils/browser.js +49 -0
- package/dist/src/utils/browser.js.map +1 -0
- package/dist/src/utils/editCorrector.js +4 -4
- package/dist/src/utils/editCorrector.js.map +1 -1
- package/dist/src/utils/editCorrector.test.js +1 -1
- package/dist/src/utils/editor.js +16 -10
- package/dist/src/utils/editor.js.map +1 -1
- package/dist/src/utils/editor.test.js +128 -28
- package/dist/src/utils/editor.test.js.map +1 -1
- package/dist/src/utils/errorReporting.d.ts +1 -1
- package/dist/src/utils/errorReporting.js +2 -2
- package/dist/src/utils/errorReporting.js.map +1 -1
- package/dist/src/utils/errorReporting.test.js +44 -38
- package/dist/src/utils/errorReporting.test.js.map +1 -1
- package/dist/src/utils/errors.js +4 -4
- package/dist/src/utils/errors.js.map +1 -1
- package/dist/src/utils/fileUtils.d.ts +4 -4
- package/dist/src/utils/fileUtils.js +33 -17
- package/dist/src/utils/fileUtils.js.map +1 -1
- package/dist/src/utils/fileUtils.test.js +37 -37
- package/dist/src/utils/fileUtils.test.js.map +1 -1
- package/dist/src/utils/getFolderStructure.d.ts +3 -2
- package/dist/src/utils/getFolderStructure.js +27 -28
- package/dist/src/utils/getFolderStructure.js.map +1 -1
- package/dist/src/utils/getFolderStructure.test.js +169 -187
- package/dist/src/utils/getFolderStructure.test.js.map +1 -1
- package/dist/src/utils/gitIgnoreParser.js +4 -7
- package/dist/src/utils/gitIgnoreParser.js.map +1 -1
- package/dist/src/utils/gitIgnoreParser.test.js +70 -61
- package/dist/src/utils/gitIgnoreParser.test.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.d.ts +2 -1
- package/dist/src/utils/memoryDiscovery.js +11 -5
- package/dist/src/utils/memoryDiscovery.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.test.js +160 -371
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
- package/dist/src/utils/partUtils.d.ts +14 -0
- package/dist/src/utils/partUtils.js +65 -0
- package/dist/src/utils/partUtils.js.map +1 -0
- package/dist/src/utils/partUtils.test.d.ts +6 -0
- package/dist/src/utils/partUtils.test.js +130 -0
- package/dist/src/utils/partUtils.test.js.map +1 -0
- package/dist/src/utils/paths.d.ts +11 -0
- package/dist/src/utils/paths.js +17 -1
- package/dist/src/utils/paths.js.map +1 -1
- package/dist/src/utils/quotaErrorDetection.js +2 -11
- package/dist/src/utils/quotaErrorDetection.js.map +1 -1
- package/dist/src/utils/retry.d.ts +6 -0
- package/dist/src/utils/retry.js +2 -2
- package/dist/src/utils/retry.js.map +1 -1
- package/dist/src/utils/safeJsonStringify.d.ts +13 -0
- package/dist/src/utils/safeJsonStringify.js +25 -0
- package/dist/src/utils/safeJsonStringify.js.map +1 -0
- package/dist/src/utils/safeJsonStringify.test.d.ts +6 -0
- package/dist/src/utils/safeJsonStringify.test.js +61 -0
- package/dist/src/utils/safeJsonStringify.test.js.map +1 -0
- package/dist/src/utils/schemaValidator.d.ts +1 -1
- package/dist/src/utils/schemaValidator.js +6 -3
- package/dist/src/utils/schemaValidator.js.map +1 -1
- package/dist/src/utils/shell-utils.d.ts +44 -0
- package/dist/src/utils/shell-utils.js +243 -0
- package/dist/src/utils/shell-utils.js.map +1 -0
- package/dist/src/utils/shell-utils.test.d.ts +6 -0
- package/dist/src/utils/shell-utils.test.js +450 -0
- package/dist/src/utils/shell-utils.test.js.map +1 -0
- package/dist/src/utils/summarizer.d.ts +1 -1
- package/dist/src/utils/summarizer.js +11 -39
- package/dist/src/utils/summarizer.js.map +1 -1
- package/dist/src/utils/summarizer.test.js +1 -1
- package/dist/src/utils/systemEncoding.d.ts +40 -0
- package/dist/src/utils/systemEncoding.js +149 -0
- package/dist/src/utils/systemEncoding.js.map +1 -0
- package/dist/src/utils/systemEncoding.test.d.ts +6 -0
- package/dist/src/utils/systemEncoding.test.js +368 -0
- package/dist/src/utils/systemEncoding.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
- package/dist/google-gemini-cli-core-0.1.12.tgz +0 -0
- package/dist/src/core/geminiRequest.test.js +0 -72
- package/dist/src/core/geminiRequest.test.js.map +0 -1
- /package/dist/src/{core/geminiRequest.test.d.ts → ide/ideContext.test.d.ts} +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
7
|
+
import { createIdeContextStore } from './ideContext.js';
|
|
8
|
+
describe('ideContext - Active File', () => {
|
|
9
|
+
let ideContext;
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
// Create a fresh, isolated instance for each test
|
|
12
|
+
ideContext = createIdeContextStore();
|
|
13
|
+
});
|
|
14
|
+
it('should return undefined initially for active file context', () => {
|
|
15
|
+
expect(ideContext.getOpenFilesContext()).toBeUndefined();
|
|
16
|
+
});
|
|
17
|
+
it('should set and retrieve the active file context', () => {
|
|
18
|
+
const testFile = {
|
|
19
|
+
activeFile: '/path/to/test/file.ts',
|
|
20
|
+
selectedText: '1234',
|
|
21
|
+
};
|
|
22
|
+
ideContext.setOpenFilesContext(testFile);
|
|
23
|
+
const activeFile = ideContext.getOpenFilesContext();
|
|
24
|
+
expect(activeFile).toEqual(testFile);
|
|
25
|
+
});
|
|
26
|
+
it('should update the active file context when called multiple times', () => {
|
|
27
|
+
const firstFile = {
|
|
28
|
+
activeFile: '/path/to/first.js',
|
|
29
|
+
selectedText: '1234',
|
|
30
|
+
};
|
|
31
|
+
ideContext.setOpenFilesContext(firstFile);
|
|
32
|
+
const secondFile = {
|
|
33
|
+
activeFile: '/path/to/second.py',
|
|
34
|
+
cursor: { line: 20, character: 30 },
|
|
35
|
+
};
|
|
36
|
+
ideContext.setOpenFilesContext(secondFile);
|
|
37
|
+
const activeFile = ideContext.getOpenFilesContext();
|
|
38
|
+
expect(activeFile).toEqual(secondFile);
|
|
39
|
+
});
|
|
40
|
+
it('should handle empty string for file path', () => {
|
|
41
|
+
const testFile = {
|
|
42
|
+
activeFile: '',
|
|
43
|
+
selectedText: '1234',
|
|
44
|
+
};
|
|
45
|
+
ideContext.setOpenFilesContext(testFile);
|
|
46
|
+
expect(ideContext.getOpenFilesContext()).toEqual(testFile);
|
|
47
|
+
});
|
|
48
|
+
it('should notify subscribers when active file context changes', () => {
|
|
49
|
+
const subscriber1 = vi.fn();
|
|
50
|
+
const subscriber2 = vi.fn();
|
|
51
|
+
ideContext.subscribeToOpenFiles(subscriber1);
|
|
52
|
+
ideContext.subscribeToOpenFiles(subscriber2);
|
|
53
|
+
const testFile = {
|
|
54
|
+
activeFile: '/path/to/subscribed.ts',
|
|
55
|
+
cursor: { line: 15, character: 25 },
|
|
56
|
+
};
|
|
57
|
+
ideContext.setOpenFilesContext(testFile);
|
|
58
|
+
expect(subscriber1).toHaveBeenCalledTimes(1);
|
|
59
|
+
expect(subscriber1).toHaveBeenCalledWith(testFile);
|
|
60
|
+
expect(subscriber2).toHaveBeenCalledTimes(1);
|
|
61
|
+
expect(subscriber2).toHaveBeenCalledWith(testFile);
|
|
62
|
+
// Test with another update
|
|
63
|
+
const newFile = {
|
|
64
|
+
activeFile: '/path/to/new.js',
|
|
65
|
+
selectedText: '1234',
|
|
66
|
+
};
|
|
67
|
+
ideContext.setOpenFilesContext(newFile);
|
|
68
|
+
expect(subscriber1).toHaveBeenCalledTimes(2);
|
|
69
|
+
expect(subscriber1).toHaveBeenCalledWith(newFile);
|
|
70
|
+
expect(subscriber2).toHaveBeenCalledTimes(2);
|
|
71
|
+
expect(subscriber2).toHaveBeenCalledWith(newFile);
|
|
72
|
+
});
|
|
73
|
+
it('should stop notifying a subscriber after unsubscribe', () => {
|
|
74
|
+
const subscriber1 = vi.fn();
|
|
75
|
+
const subscriber2 = vi.fn();
|
|
76
|
+
const unsubscribe1 = ideContext.subscribeToOpenFiles(subscriber1);
|
|
77
|
+
ideContext.subscribeToOpenFiles(subscriber2);
|
|
78
|
+
ideContext.setOpenFilesContext({
|
|
79
|
+
activeFile: '/path/to/file1.txt',
|
|
80
|
+
selectedText: '1234',
|
|
81
|
+
});
|
|
82
|
+
expect(subscriber1).toHaveBeenCalledTimes(1);
|
|
83
|
+
expect(subscriber2).toHaveBeenCalledTimes(1);
|
|
84
|
+
unsubscribe1();
|
|
85
|
+
ideContext.setOpenFilesContext({
|
|
86
|
+
activeFile: '/path/to/file2.txt',
|
|
87
|
+
selectedText: '1234',
|
|
88
|
+
});
|
|
89
|
+
expect(subscriber1).toHaveBeenCalledTimes(1); // Should not be called again
|
|
90
|
+
expect(subscriber2).toHaveBeenCalledTimes(2);
|
|
91
|
+
});
|
|
92
|
+
it('should allow the cursor to be optional', () => {
|
|
93
|
+
const testFile = {
|
|
94
|
+
activeFile: '/path/to/test/file.ts',
|
|
95
|
+
};
|
|
96
|
+
ideContext.setOpenFilesContext(testFile);
|
|
97
|
+
const activeFile = ideContext.getOpenFilesContext();
|
|
98
|
+
expect(activeFile).toEqual(testFile);
|
|
99
|
+
});
|
|
100
|
+
it('should clear the active file context', () => {
|
|
101
|
+
const testFile = {
|
|
102
|
+
activeFile: '/path/to/test/file.ts',
|
|
103
|
+
selectedText: '1234',
|
|
104
|
+
};
|
|
105
|
+
ideContext.setOpenFilesContext(testFile);
|
|
106
|
+
expect(ideContext.getOpenFilesContext()).toEqual(testFile);
|
|
107
|
+
ideContext.clearOpenFilesContext();
|
|
108
|
+
expect(ideContext.getOpenFilesContext()).toBeUndefined();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
//# sourceMappingURL=ideContext.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ideContext.test.js","sourceRoot":"","sources":["../../../src/ide/ideContext.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,IAAI,UAAoD,CAAC;IAEzD,UAAU,CAAC,GAAG,EAAE;QACd,kDAAkD;QAClD,UAAU,GAAG,qBAAqB,EAAE,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;QACnE,MAAM,CAAC,UAAU,CAAC,mBAAmB,EAAE,CAAC,CAAC,aAAa,EAAE,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QACzD,MAAM,QAAQ,GAAG;YACf,UAAU,EAAE,uBAAuB;YAC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AmB,EAAE,CAAC,CAAC,aAAa,EAAE,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -26,10 +26,16 @@ export * from './utils/memoryDiscovery.js';
|
|
|
26
26
|
export * from './utils/gitIgnoreParser.js';
|
|
27
27
|
export * from './utils/editor.js';
|
|
28
28
|
export * from './utils/quotaErrorDetection.js';
|
|
29
|
+
export * from './utils/fileUtils.js';
|
|
30
|
+
export * from './utils/retry.js';
|
|
31
|
+
export * from './utils/systemEncoding.js';
|
|
29
32
|
export * from './services/fileDiscoveryService.js';
|
|
30
33
|
export * from './services/gitService.js';
|
|
34
|
+
export * from './ide/ide-client.js';
|
|
35
|
+
export * from './ide/ideContext.js';
|
|
31
36
|
export * from './tools/tools.js';
|
|
32
37
|
export * from './tools/tool-registry.js';
|
|
38
|
+
export * from './prompts/mcp-prompts.js';
|
|
33
39
|
export * from './tools/read-file.js';
|
|
34
40
|
export * from './tools/ls.js';
|
|
35
41
|
export * from './tools/grep.js';
|
|
@@ -43,5 +49,11 @@ export * from './tools/web-search.js';
|
|
|
43
49
|
export * from './tools/read-many-files.js';
|
|
44
50
|
export * from './tools/mcp-client.js';
|
|
45
51
|
export * from './tools/mcp-tool.js';
|
|
52
|
+
export { MCPOAuthProvider } from './mcp/oauth-provider.js';
|
|
53
|
+
export { MCPOAuthToken, MCPOAuthCredentials, MCPOAuthTokenStorage, } from './mcp/oauth-token-storage.js';
|
|
54
|
+
export type { MCPOAuthConfig } from './mcp/oauth-provider.js';
|
|
55
|
+
export type { OAuthAuthorizationServerMetadata, OAuthProtectedResourceMetadata, } from './mcp/oauth-utils.js';
|
|
56
|
+
export { OAuthUtils } from './mcp/oauth-utils.js';
|
|
46
57
|
export * from './telemetry/index.js';
|
|
47
58
|
export { sessionId } from './utils/session.js';
|
|
59
|
+
export * from './utils/browser.js';
|
package/dist/src/index.js
CHANGED
|
@@ -29,12 +29,20 @@ export * from './utils/memoryDiscovery.js';
|
|
|
29
29
|
export * from './utils/gitIgnoreParser.js';
|
|
30
30
|
export * from './utils/editor.js';
|
|
31
31
|
export * from './utils/quotaErrorDetection.js';
|
|
32
|
+
export * from './utils/fileUtils.js';
|
|
33
|
+
export * from './utils/retry.js';
|
|
34
|
+
export * from './utils/systemEncoding.js';
|
|
32
35
|
// Export services
|
|
33
36
|
export * from './services/fileDiscoveryService.js';
|
|
34
37
|
export * from './services/gitService.js';
|
|
38
|
+
// Export IDE specific logic
|
|
39
|
+
export * from './ide/ide-client.js';
|
|
40
|
+
export * from './ide/ideContext.js';
|
|
35
41
|
// Export base tool definitions
|
|
36
42
|
export * from './tools/tools.js';
|
|
37
43
|
export * from './tools/tool-registry.js';
|
|
44
|
+
// Export prompt logic
|
|
45
|
+
export * from './prompts/mcp-prompts.js';
|
|
38
46
|
// Export specific tool logic
|
|
39
47
|
export * from './tools/read-file.js';
|
|
40
48
|
export * from './tools/ls.js';
|
|
@@ -49,7 +57,12 @@ export * from './tools/web-search.js';
|
|
|
49
57
|
export * from './tools/read-many-files.js';
|
|
50
58
|
export * from './tools/mcp-client.js';
|
|
51
59
|
export * from './tools/mcp-tool.js';
|
|
60
|
+
// MCP OAuth
|
|
61
|
+
export { MCPOAuthProvider } from './mcp/oauth-provider.js';
|
|
62
|
+
export { MCPOAuthTokenStorage, } from './mcp/oauth-token-storage.js';
|
|
63
|
+
export { OAuthUtils } from './mcp/oauth-utils.js';
|
|
52
64
|
// Export telemetry functions
|
|
53
65
|
export * from './telemetry/index.js';
|
|
54
66
|
export { sessionId } from './utils/session.js';
|
|
67
|
+
export * from './utils/browser.js';
|
|
55
68
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gBAAgB;AAChB,cAAc,oBAAoB,CAAC;AAEnC,oBAAoB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apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
7
|
+
import { OAuthClientInformation, OAuthClientInformationFull, OAuthClientMetadata, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
8
|
+
import { MCPServerConfig } from '../config/config.js';
|
|
9
|
+
export declare class GoogleCredentialProvider implements OAuthClientProvider {
|
|
10
|
+
private readonly config?;
|
|
11
|
+
private readonly auth;
|
|
12
|
+
readonly redirectUrl = "";
|
|
13
|
+
readonly clientMetadata: OAuthClientMetadata;
|
|
14
|
+
private _clientInformation?;
|
|
15
|
+
constructor(config?: MCPServerConfig | undefined);
|
|
16
|
+
clientInformation(): OAuthClientInformation | undefined;
|
|
17
|
+
saveClientInformation(clientInformation: OAuthClientInformationFull): void;
|
|
18
|
+
tokens(): Promise<OAuthTokens | undefined>;
|
|
19
|
+
saveTokens(_tokens: OAuthTokens): void;
|
|
20
|
+
redirectToAuthorization(_authorizationUrl: URL): void;
|
|
21
|
+
saveCodeVerifier(_codeVerifier: string): void;
|
|
22
|
+
codeVerifier(): string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { GoogleAuth } from 'google-auth-library';
|
|
7
|
+
export class GoogleCredentialProvider {
|
|
8
|
+
config;
|
|
9
|
+
auth;
|
|
10
|
+
// Properties required by OAuthClientProvider, with no-op values
|
|
11
|
+
redirectUrl = '';
|
|
12
|
+
clientMetadata = {
|
|
13
|
+
client_name: 'Gemini CLI (Google ADC)',
|
|
14
|
+
redirect_uris: [],
|
|
15
|
+
grant_types: [],
|
|
16
|
+
response_types: [],
|
|
17
|
+
token_endpoint_auth_method: 'none',
|
|
18
|
+
};
|
|
19
|
+
_clientInformation;
|
|
20
|
+
constructor(config) {
|
|
21
|
+
this.config = config;
|
|
22
|
+
const scopes = this.config?.oauth?.scopes;
|
|
23
|
+
if (!scopes || scopes.length === 0) {
|
|
24
|
+
throw new Error('Scopes must be provided in the oauth config for Google Credentials provider');
|
|
25
|
+
}
|
|
26
|
+
this.auth = new GoogleAuth({
|
|
27
|
+
scopes,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
clientInformation() {
|
|
31
|
+
return this._clientInformation;
|
|
32
|
+
}
|
|
33
|
+
saveClientInformation(clientInformation) {
|
|
34
|
+
this._clientInformation = clientInformation;
|
|
35
|
+
}
|
|
36
|
+
async tokens() {
|
|
37
|
+
const client = await this.auth.getClient();
|
|
38
|
+
const accessTokenResponse = await client.getAccessToken();
|
|
39
|
+
if (!accessTokenResponse.token) {
|
|
40
|
+
console.error('Failed to get access token from Google ADC');
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const tokens = {
|
|
44
|
+
access_token: accessTokenResponse.token,
|
|
45
|
+
token_type: 'Bearer',
|
|
46
|
+
};
|
|
47
|
+
return tokens;
|
|
48
|
+
}
|
|
49
|
+
saveTokens(_tokens) {
|
|
50
|
+
// No-op, ADC manages tokens.
|
|
51
|
+
}
|
|
52
|
+
redirectToAuthorization(_authorizationUrl) {
|
|
53
|
+
// No-op
|
|
54
|
+
}
|
|
55
|
+
saveCodeVerifier(_codeVerifier) {
|
|
56
|
+
// No-op
|
|
57
|
+
}
|
|
58
|
+
codeVerifier() {
|
|
59
|
+
// No-op
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=google-auth-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-auth-provider.js","sourceRoot":"","sources":["../../../src/mcp/google-auth-provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,MAAM,OAAO,wBAAwB;IAc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,uBAAuB,CAAC,iBAAsB;QAC5C,QAAQ;IACV,CAAC;IAED,gBAAgB,CAAC,aAAqB;QACpC,QAAQ;IACV,CAAC;IAED,YAAY;QACV,QAAQ;QACR,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { GoogleAuth } from 'google-auth-library';
|
|
7
|
+
import { GoogleCredentialProvider } from './google-auth-provider.js';
|
|
8
|
+
import { vi, describe, beforeEach, it, expect } from 'vitest';
|
|
9
|
+
vi.mock('google-auth-library');
|
|
10
|
+
describe('GoogleCredentialProvider', () => {
|
|
11
|
+
it('should throw an error if no scopes are provided', () => {
|
|
12
|
+
expect(() => new GoogleCredentialProvider()).toThrow('Scopes must be provided in the oauth config for Google Credentials provider');
|
|
13
|
+
});
|
|
14
|
+
it('should use scopes from the config if provided', () => {
|
|
15
|
+
const config = {
|
|
16
|
+
oauth: {
|
|
17
|
+
scopes: ['scope1', 'scope2'],
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
new GoogleCredentialProvider(config);
|
|
21
|
+
expect(GoogleAuth).toHaveBeenCalledWith({
|
|
22
|
+
scopes: ['scope1', 'scope2'],
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe('with provider instance', () => {
|
|
26
|
+
let provider;
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
const config = {
|
|
29
|
+
oauth: {
|
|
30
|
+
scopes: ['scope1', 'scope2'],
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
provider = new GoogleCredentialProvider(config);
|
|
34
|
+
vi.clearAllMocks();
|
|
35
|
+
});
|
|
36
|
+
it('should return credentials', async () => {
|
|
37
|
+
const mockClient = {
|
|
38
|
+
getAccessToken: vi.fn().mockResolvedValue({ token: 'test-token' }),
|
|
39
|
+
};
|
|
40
|
+
GoogleAuth.prototype.getClient.mockResolvedValue(mockClient);
|
|
41
|
+
const credentials = await provider.tokens();
|
|
42
|
+
expect(credentials?.access_token).toBe('test-token');
|
|
43
|
+
});
|
|
44
|
+
it('should return undefined if access token is not available', async () => {
|
|
45
|
+
const mockClient = {
|
|
46
|
+
getAccessToken: vi.fn().mockResolvedValue({ token: null }),
|
|
47
|
+
};
|
|
48
|
+
GoogleAuth.prototype.getClient.mockResolvedValue(mockClient);
|
|
49
|
+
const credentials = await provider.tokens();
|
|
50
|
+
expect(credentials).toBeUndefined();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=google-auth-provider.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-auth-provider.test.js","sourceRoot":"","sources":["../../../src/mcp/google-auth-provider.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAQ,MAAM,QAAQ,CAAC;AAGpE,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;AAE/B,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QACzD,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,wBAAwB,EAAE,CAAC,CAAC,OAAO,CAClD,6EAA6E,CAC9E,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,MAAM,GAAG;YACb,KAAK,EAAE;gBACL,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;aAC7B;SACiB,CAAC;QACrB,IA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QAAQ,CAAC,MAAM,EAAE,CAAC;YAC5C,MAAM,CAAC,WAAW,CAAC,CAAC,aAAa,EAAE,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { MCPOAuthToken } from './oauth-token-storage.js';
|
|
7
|
+
/**
|
|
8
|
+
* OAuth configuration for an MCP server.
|
|
9
|
+
*/
|
|
10
|
+
export interface MCPOAuthConfig {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
clientId?: string;
|
|
13
|
+
clientSecret?: string;
|
|
14
|
+
authorizationUrl?: string;
|
|
15
|
+
tokenUrl?: string;
|
|
16
|
+
scopes?: string[];
|
|
17
|
+
redirectUri?: string;
|
|
18
|
+
tokenParamName?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* OAuth authorization response.
|
|
22
|
+
*/
|
|
23
|
+
export interface OAuthAuthorizationResponse {
|
|
24
|
+
code: string;
|
|
25
|
+
state: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* OAuth token response from the authorization server.
|
|
29
|
+
*/
|
|
30
|
+
export interface OAuthTokenResponse {
|
|
31
|
+
access_token: string;
|
|
32
|
+
token_type: string;
|
|
33
|
+
expires_in?: number;
|
|
34
|
+
refresh_token?: string;
|
|
35
|
+
scope?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Dynamic client registration request.
|
|
39
|
+
*/
|
|
40
|
+
export interface OAuthClientRegistrationRequest {
|
|
41
|
+
client_name: string;
|
|
42
|
+
redirect_uris: string[];
|
|
43
|
+
grant_types: string[];
|
|
44
|
+
response_types: string[];
|
|
45
|
+
token_endpoint_auth_method: string;
|
|
46
|
+
code_challenge_method?: string[];
|
|
47
|
+
scope?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Dynamic client registration response.
|
|
51
|
+
*/
|
|
52
|
+
export interface OAuthClientRegistrationResponse {
|
|
53
|
+
client_id: string;
|
|
54
|
+
client_secret?: string;
|
|
55
|
+
client_id_issued_at?: number;
|
|
56
|
+
client_secret_expires_at?: number;
|
|
57
|
+
redirect_uris: string[];
|
|
58
|
+
grant_types: string[];
|
|
59
|
+
response_types: string[];
|
|
60
|
+
token_endpoint_auth_method: string;
|
|
61
|
+
code_challenge_method?: string[];
|
|
62
|
+
scope?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Provider for handling OAuth authentication for MCP servers.
|
|
66
|
+
*/
|
|
67
|
+
export declare class MCPOAuthProvider {
|
|
68
|
+
private static readonly REDIRECT_PORT;
|
|
69
|
+
private static readonly REDIRECT_PATH;
|
|
70
|
+
private static readonly HTTP_OK;
|
|
71
|
+
private static readonly HTTP_REDIRECT;
|
|
72
|
+
/**
|
|
73
|
+
* Register a client dynamically with the OAuth server.
|
|
74
|
+
*
|
|
75
|
+
* @param registrationUrl The client registration endpoint URL
|
|
76
|
+
* @param config OAuth configuration
|
|
77
|
+
* @returns The registered client information
|
|
78
|
+
*/
|
|
79
|
+
private static registerClient;
|
|
80
|
+
/**
|
|
81
|
+
* Discover OAuth configuration from an MCP server URL.
|
|
82
|
+
*
|
|
83
|
+
* @param mcpServerUrl The MCP server URL
|
|
84
|
+
* @returns OAuth configuration if discovered, null otherwise
|
|
85
|
+
*/
|
|
86
|
+
private static discoverOAuthFromMCPServer;
|
|
87
|
+
/**
|
|
88
|
+
* Generate PKCE parameters for OAuth flow.
|
|
89
|
+
*
|
|
90
|
+
* @returns PKCE parameters including code verifier, challenge, and state
|
|
91
|
+
*/
|
|
92
|
+
private static generatePKCEParams;
|
|
93
|
+
/**
|
|
94
|
+
* Start a local HTTP server to handle OAuth callback.
|
|
95
|
+
*
|
|
96
|
+
* @param expectedState The state parameter to validate
|
|
97
|
+
* @returns Promise that resolves with the authorization code
|
|
98
|
+
*/
|
|
99
|
+
private static startCallbackServer;
|
|
100
|
+
/**
|
|
101
|
+
* Build the authorization URL with PKCE parameters.
|
|
102
|
+
*
|
|
103
|
+
* @param config OAuth configuration
|
|
104
|
+
* @param pkceParams PKCE parameters
|
|
105
|
+
* @returns The authorization URL
|
|
106
|
+
*/
|
|
107
|
+
private static buildAuthorizationUrl;
|
|
108
|
+
/**
|
|
109
|
+
* Exchange authorization code for tokens.
|
|
110
|
+
*
|
|
111
|
+
* @param config OAuth configuration
|
|
112
|
+
* @param code Authorization code
|
|
113
|
+
* @param codeVerifier PKCE code verifier
|
|
114
|
+
* @returns The token response
|
|
115
|
+
*/
|
|
116
|
+
private static exchangeCodeForToken;
|
|
117
|
+
/**
|
|
118
|
+
* Refresh an access token using a refresh token.
|
|
119
|
+
*
|
|
120
|
+
* @param config OAuth configuration
|
|
121
|
+
* @param refreshToken The refresh token
|
|
122
|
+
* @returns The new token response
|
|
123
|
+
*/
|
|
124
|
+
static refreshAccessToken(config: MCPOAuthConfig, refreshToken: string, tokenUrl: string): Promise<OAuthTokenResponse>;
|
|
125
|
+
/**
|
|
126
|
+
* Perform the full OAuth authorization code flow with PKCE.
|
|
127
|
+
*
|
|
128
|
+
* @param serverName The name of the MCP server
|
|
129
|
+
* @param config OAuth configuration
|
|
130
|
+
* @param mcpServerUrl Optional MCP server URL for OAuth discovery
|
|
131
|
+
* @returns The obtained OAuth token
|
|
132
|
+
*/
|
|
133
|
+
static authenticate(serverName: string, config: MCPOAuthConfig, mcpServerUrl?: string): Promise<MCPOAuthToken>;
|
|
134
|
+
/**
|
|
135
|
+
* Get a valid access token for an MCP server, refreshing if necessary.
|
|
136
|
+
*
|
|
137
|
+
* @param serverName The name of the MCP server
|
|
138
|
+
* @param config OAuth configuration
|
|
139
|
+
* @returns A valid access token or null if not authenticated
|
|
140
|
+
*/
|
|
141
|
+
static getValidToken(serverName: string, config: MCPOAuthConfig): Promise<string | null>;
|
|
142
|
+
}
|