From 9a5fff9cc692a81e5b5e6bcf93ad5af854543023 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Wed, 22 Oct 2025 19:09:04 -0400 Subject: [PATCH] refactor(@angular/cli): update algolia config for documentation search tool The Algolia search configuration has been updated to support querying multiple major versions of the documentation. Error handling was also improved to support fallback to known indexes correctly. --- .../angular/cli/src/commands/mcp/constants.ts | 2 +- .../cli/src/commands/mcp/tools/doc-search.ts | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/angular/cli/src/commands/mcp/constants.ts b/packages/angular/cli/src/commands/mcp/constants.ts index 6530bfd34175..789820ca2f53 100644 --- a/packages/angular/cli/src/commands/mcp/constants.ts +++ b/packages/angular/cli/src/commands/mcp/constants.ts @@ -7,7 +7,7 @@ */ export const k1 = '@angular/cli'; -export const at = 'QBHBbOdEO4CmBOC2d7jNmg=='; +export const at = 'gv2tkIHTOiWtI6Su96LXLQ=='; export const iv = Buffer.from([ 0x97, 0xf4, 0x62, 0x95, 0x3e, 0x12, 0x76, 0x84, 0x8a, 0x09, 0x4a, 0xc9, 0xeb, 0xa2, 0x84, 0x69, ]); diff --git a/packages/angular/cli/src/commands/mcp/tools/doc-search.ts b/packages/angular/cli/src/commands/mcp/tools/doc-search.ts index e57d50c6f500..dbf80794cc26 100644 --- a/packages/angular/cli/src/commands/mcp/tools/doc-search.ts +++ b/packages/angular/cli/src/commands/mcp/tools/doc-search.ts @@ -17,7 +17,7 @@ const ALGOLIA_APP_ID = 'L1XWT2UJ7F'; // https://www.algolia.com/doc/guides/security/api-keys/#search-only-api-key // This is a search only, rate limited key. It is sent within the URL of the query request. // This is not the actual key. -const ALGOLIA_API_E = '322d89dab5f2080fe09b795c93413c6a89222b13a447cdf3e6486d692717bc0c'; +const ALGOLIA_API_E = '34738e8ae1a45e58bbce7b0f9810633d8b727b44a6479cf5e14b6a337148bd50'; /** * The minimum major version of Angular for which a version-specific documentation index is known to exist. @@ -45,7 +45,7 @@ const docSearchInputSchema = z.object({ includeTopContent: z .boolean() .optional() - .default(true) + .default(false) .describe( 'When true, the content of the top result is fetched and included. ' + 'Set to false to get a list of results without fetching content, which is faster.', @@ -145,22 +145,22 @@ function createDocSearchHandler({ logger }: McpToolContext) { version ?? LATEST_KNOWN_DOCS_VERSION, MIN_SUPPORTED_DOCS_VERSION, ); - let searchResults = await client.search(createSearchArguments(query, finalSearchedVersion)); + let searchResults; + try { + searchResults = await client.search(createSearchArguments(query, finalSearchedVersion)); + } catch {} // If the initial search for a newer-than-stable version returns no results, it may be because // the index for that version doesn't exist yet. In this case, fall back to the latest known // stable version. - if ( - searchResults.results.every((result) => !('hits' in result) || result.hits.length === 0) && - finalSearchedVersion > LATEST_KNOWN_DOCS_VERSION - ) { + if (!searchResults && finalSearchedVersion > LATEST_KNOWN_DOCS_VERSION) { finalSearchedVersion = LATEST_KNOWN_DOCS_VERSION; searchResults = await client.search(createSearchArguments(query, finalSearchedVersion)); } - const allHits = searchResults.results.flatMap((result) => (result as SearchResponse).hits); + const allHits = searchResults?.results.flatMap((result) => (result as SearchResponse).hits); - if (allHits.length === 0) { + if (!allHits?.length) { return { content: [ {