MCP semantic_code_search: Update handling for no code embeddings

What does this MR do and why?

As part of &19655, we are going to implement ad-hoc embeddings indexing of projects. With ad-hoc indexing, we are not immediately indexing Code Embeddings for all eligible projects. Instead, we will perform Code Embeddings indexing for a project on the first time a semantic code search is triggered on the project.

In this MR, we update the semantic code search process to handle the different "no code embeddings" scenarios:

Note: "no code embeddings" mean that the project has no Ai::ActiveContext::Code::Repository OR its state != ready.

  1. If Ai::ActiveContext::Code::Repository record does not exist for a project:
    • trigger the AdHocIndexingWorker (introduced in #577330 (closed))
    • return a message indicating that the embeddings initial indexing has just started
  2. If Ai::ActiveContext::Code::Repository exists with state=failed
    • return a message indicating that the embeddings indexing failed
  3. If Ai::ActiveContext::Code::Repository exists with state NOT ready or failed
    • return a message indicating that the embeddings initial indexing is still ongoing

References

Screenshots or screen recordings

Scenario: project has code embeddings

Screenshot_2025-10-29_at_15.30.10

Scenario: project has NO code embeddings

Screen_Recording_2025-10-29_at_17.18.57

Scenario: project embeddings indexing failed

Screenshot_2025-10-29_at_15.32.02

Scenario: project embeddings initial indexing is in progress

Screenshot_2025-10-29_at_15.32.58

How to set up and validate locally

Prerequisites

  1. Setup MCP server on your GDK
  2. Setup the Code Embeddings Indexing pipeline on your GDK

Testing

Test the semantic_code_search tool using MCP Inspector or your preferred client for MCP testing.

  1. For a project with code embeddings, the tool should return results successfully

    Setup note: you can set up this project by following Prerequisites Step 2

  2. For a project with NO code embeddings but eligible for it:

    • an Ai::ActiveContext::Code::Repository record should be created for the project
    • the record should have a state of code_indexing_in_progress or embedding_indexing_in_progress (the record is initially created with state=pending, but since the ad-hoc indexing is kicked off, the indexing process should have started by the time you are checking

    Setup note: this should be any project under the gitlab-duo namespace without an Ai::ActiveContext::Code::Repository record

  3. For a project with Ai::ActiveContext::Code::Repository record with state=failed

    • the tool should error with a message indicating that the indexing failed

    Setup note: you can set up this project by following Prerequisites Step 2, then updating the project's Ai::ActiveContext::Code::Repository record to state=failed

  4. For a project with Ai::ActiveContext::Code::Repository record with state NOT ready or failed

    • the tool should error with a message indicating that initial indexing is still ongoing

    Setup note: you can set up this project by following Prerequisites Step 2, then updating the project's Ai::ActiveContext::Code::Repository record to code_indexing_in_progress=failed

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #576633 (closed)

Edited by Pam Artiaga

Merge request reports

Loading