feat(@angular/cli): allow Algolia search key override via env var#33081
Open
gn00295120 wants to merge 2 commits intoangular:mainfrom
Open
feat(@angular/cli): allow Algolia search key override via env var#33081gn00295120 wants to merge 2 commits intoangular:mainfrom
gn00295120 wants to merge 2 commits intoangular:mainfrom
Conversation
The MCP `search_documentation` tool currently uses a single bundled Algolia API key for the public Angular documentation index. This works out of the box but gives operators no way to: * substitute a different key for self-hosted documentation indices, * point an internal CI environment at a separate Algolia application to avoid sharing the public rate-limit budget, * test key rotation without rebuilding the CLI. This change adds a `NG_DOCS_SEARCH_API_KEY` environment variable that, when set to a non-empty string, is used verbatim in place of the bundled key. When the variable is absent or empty, behaviour is unchanged — the bundled key continues to be used. The override path is factored into a small `resolveAlgoliaApiKey()` helper so the env-var precedence rules are unit-testable without spinning up the full MCP tool runner. Three Jasmine specs cover: override set, override unset, and override set to empty string. The previous comment block on `ALGOLIA_API_E` is replaced with a short note describing the override mechanism and the operator scenarios it enables.
There was a problem hiding this comment.
Code Review
This pull request introduces the resolveAlgoliaApiKey function to allow overriding the Algolia API key via the NG_DOCS_SEARCH_API_KEY environment variable, falling back to a bundled default if unset. It also includes unit tests for this new logic. Feedback suggests providing an environment variable override for the Algolia App ID to better support self-hosted documentation and recommends trimming whitespace from the environment variable value to prevent configuration errors.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
NG_DEBUGindocs/design/analytics.md, which is for a different purpose. Happy to add a brief mention if reviewers prefer.PR Type
What is the current behavior?
The MCP
search_documentationtool uses a single bundled Algolia APIkey for the public Angular documentation index. Operators have no way
to substitute a different key for self-hosted documentation, internal
CI environments, or rotation testing without rebuilding the CLI.
Issue Number: N/A
What is the new behavior?
A new environment variable,
NG_DOCS_SEARCH_API_KEY, takes precedenceover the bundled key when set to a non-empty value. When unset or set
to an empty string, behaviour is unchanged.
The override path is factored into a small
resolveAlgoliaApiKey()helper so the precedence rules are unit-testable without spinning up
the full MCP tool runner. The helper is exported (
for testing) andconsumed from
createDocSearchHandler:The bracket-syntax env access matches the existing convention in
mcp-server.ts(process.env['NG_MCP_CODE_EXAMPLES']). The variablename follows the
NG_*prefix used by every other CLI environmentvariable (see
utilities/environment-options.ts).Tests
Three Jasmine specs in
packages/angular/cli/src/commands/mcp/tools/doc-search_spec.ts:returns the env var value when set to a non-empty stringfalls back to the bundled default when the env var is unsetfalls back to the bundled default when the env var is an empty stringThe fallback specs assert the resulting key matches the expected
Algolia key format (32 hex chars) without logging the value.
Comment cleanup
The previous comment block on
ALGOLIA_API_Eis replaced with ashort note describing the new override mechanism and the operator
scenarios it enables. The
/#search-only-api-keyURL was tied tothat specific phrasing; since the new comment no longer makes that
claim, the URL is dropped to avoid implying a constraint the bundled
key does not necessarily honour.
Does this PR introduce a breaking change?
Default behaviour is unchanged for users who do not set the new
environment variable. Existing
ng mcpworkflows continue to use thebundled key with no configuration.
Other information
The variable name choice (
NG_DOCS_SEARCH_API_KEYvs alternativeslike
NG_ALGOLIA_API_KEYorNG_MCP_DOCS_KEY) is a judgement call;happy to rename to whatever fits the convention reviewers prefer.