Skip to content

Commit a64f9a8

Browse files
authored
feat(amazonq): added dev override for registry URL (#8326)
## Problem Developers need a way to override the MCP registry URL for testing and development purposes without modifying production code or waiting for backend profile configuration changes. Currently, the registry URL is only fetched from the `getProfile` API call, making it difficult to test against different registry endpoints during development. ## Solution Added a new developer setting `aws.dev.amazonqRegistry` with a `registryUrl` field that allows overriding the MCP registry URL from VSCode settings. The override takes precedence over the URL fetched from `getProfile`, enabling developers to easily test against custom registry endpoints. **Changes:** - **VSCode Extension**: Added `amazonqRegistry` to dev settings, extracted `registryUrl` from config, and passed it to the language server via initialization options - **Language Server**: Added `registryUrl` to client capabilities, updated `ProfileStatusMonitor` to accept and prioritize override URL, and modified `McpToolsServer` to use the override when initializing MCP Manager **Usage:** ```json { "aws.dev.amazonqRegistry": { "registryUrl": "https://custom-registry.example.com/manifest.json" } } ``` --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 2bb9239 commit a64f9a8

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

packages/amazonq/src/lsp/activation.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,29 @@ import vscode from 'vscode'
77
import { startLanguageServer } from './client'
88
import { AmazonQLspInstaller, getBundledResourcePaths } from './lspInstaller'
99
import { lspSetupStage, ToolkitError, messages, getLogger } from 'aws-core-vscode/shared'
10+
import { getAmazonQLspConfig } from './config'
1011

1112
export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
13+
const config = getAmazonQLspConfig()
14+
const registryUrl = config.registryUrl
15+
1216
try {
1317
await lspSetupStage('all', async () => {
1418
const installResult = await new AmazonQLspInstaller().resolve()
15-
await lspSetupStage('launch', async () => await startLanguageServer(ctx, installResult.resourcePaths))
19+
await lspSetupStage(
20+
'launch',
21+
async () => await startLanguageServer(ctx, installResult.resourcePaths, registryUrl)
22+
)
1623
})
1724
} catch (err) {
1825
const e = err as ToolkitError
1926
getLogger('amazonqLsp').warn(`Failed to start downloaded LSP, falling back to bundled LSP: ${e.message}`)
2027
try {
2128
await lspSetupStage('all', async () => {
22-
await lspSetupStage('launch', async () => await startLanguageServer(ctx, getBundledResourcePaths(ctx)))
29+
await lspSetupStage(
30+
'launch',
31+
async () => await startLanguageServer(ctx, getBundledResourcePaths(ctx), registryUrl)
32+
)
2333
})
2434
} catch (error) {
2535
void messages.showViewLogsMessage(

packages/amazonq/src/lsp/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ export function hasGlibcPatch(): boolean {
8383

8484
export async function startLanguageServer(
8585
extensionContext: vscode.ExtensionContext,
86-
resourcePaths: AmazonQResourcePaths
86+
resourcePaths: AmazonQResourcePaths,
87+
registryUrl?: string
8788
) {
8889
const toDispose = extensionContext.subscriptions
8990

@@ -188,6 +189,7 @@ export async function startLanguageServer(
188189
codeReviewInChat: codeReviewInChat,
189190
// feature flag for displaying findings found not through CodeReview in the Code Issues Panel
190191
displayFindings: true,
192+
registryUrl: registryUrl,
191193
},
192194
window: {
193195
notifications: true,

packages/amazonq/src/lsp/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212

1313
export interface ExtendedAmazonQLSPConfig extends BaseLspInstaller.LspConfig {
1414
ui?: string
15+
registryUrl?: string
1516
}
1617

1718
// Taken from language server runtimes since they are not exported:
@@ -44,10 +45,12 @@ export const defaultAmazonQLspConfig: ExtendedAmazonQLSPConfig = {
4445
}
4546

4647
export function getAmazonQLspConfig(): ExtendedAmazonQLSPConfig {
48+
const registryConfig = DevSettings.instance.get('amazonqRegistry', {})
4749
return {
4850
...defaultAmazonQLspConfig,
4951
...(DevSettings.instance.getServiceConfig('amazonqLsp', {}) as ExtendedAmazonQLSPConfig),
5052
...getServiceEnvVarConfig('amazonqLsp', Object.keys(defaultAmazonQLspConfig)),
53+
registryUrl: (registryConfig as any)?.registryUrl,
5154
}
5255
}
5356
/**

packages/amazonq/test/unit/amazonq/lsp/config.test.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { defaultAmazonQLspConfig, ExtendedAmazonQLSPConfig, getAmazonQLspConfig
1111
describe('getAmazonQLspConfig', () => {
1212
let sandbox: sinon.SinonSandbox
1313
let serviceConfigStub: sinon.SinonStub
14+
let getStub: sinon.SinonStub
1415
const settingConfig: ExtendedAmazonQLSPConfig = {
1516
manifestUrl: 'https://custom.url/manifest.json',
1617
supportedVersions: '4.0.0',
@@ -24,8 +25,10 @@ describe('getAmazonQLspConfig', () => {
2425
sandbox = sinon.createSandbox()
2526

2627
serviceConfigStub = sandbox.stub()
28+
getStub = sandbox.stub()
2729
sandbox.stub(DevSettings, 'instance').get(() => ({
2830
getServiceConfig: serviceConfigStub,
31+
get: getStub,
2932
}))
3033
})
3134

@@ -36,29 +39,45 @@ describe('getAmazonQLspConfig', () => {
3639

3740
it('uses default config', () => {
3841
serviceConfigStub.returns({})
39-
assert.deepStrictEqual(getAmazonQLspConfig(), defaultAmazonQLspConfig)
42+
getStub.returns({})
43+
assert.deepStrictEqual(getAmazonQLspConfig(), { ...defaultAmazonQLspConfig, registryUrl: undefined })
4044
})
4145

4246
it('overrides path', () => {
4347
const path = '/custom/path/to/lsp'
4448
serviceConfigStub.returns({ path })
49+
getStub.returns({})
4550

4651
assert.deepStrictEqual(getAmazonQLspConfig(), {
4752
...defaultAmazonQLspConfig,
4853
path,
54+
registryUrl: undefined,
4955
})
5056
})
5157

5258
it('overrides default settings', () => {
5359
serviceConfigStub.returns(settingConfig)
60+
getStub.returns({})
5461

55-
assert.deepStrictEqual(getAmazonQLspConfig(), settingConfig)
62+
assert.deepStrictEqual(getAmazonQLspConfig(), { ...settingConfig, registryUrl: undefined })
5663
})
5764

5865
it('environment variable takes precedence over settings', () => {
5966
setEnv(settingConfig)
6067
serviceConfigStub.returns({})
61-
assert.deepStrictEqual(getAmazonQLspConfig(), settingConfig)
68+
getStub.returns({})
69+
assert.deepStrictEqual(getAmazonQLspConfig(), { ...settingConfig, registryUrl: undefined })
70+
})
71+
72+
it('includes registryUrl from amazonqRegistry setting', () => {
73+
const registryUrl = 'https://custom.registry.url/manifest.json'
74+
serviceConfigStub.returns({})
75+
getStub.withArgs('amazonqRegistry', {}).returns({ registryUrl })
76+
77+
assert.deepStrictEqual(getAmazonQLspConfig(), {
78+
...defaultAmazonQLspConfig,
79+
registryUrl,
80+
})
6281
})
6382

6483
function setEnv(envConfig: ExtendedAmazonQLSPConfig) {

packages/core/src/shared/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ const devSettings = {
778778
codewhispererService: Record(String, String),
779779
amazonqLsp: Record(String, String),
780780
amazonqWorkspaceLsp: Record(String, String),
781+
amazonqRegistry: Record(String, String),
781782
cloudformationLsp: Record(String, String),
782783
ssoCacheDirectory: String,
783784
autofillStartUrl: String,

0 commit comments

Comments
 (0)