SemanticCodeSearch: Handle no collection record
Context
If there is no "current" Ai::ActiveContext::Collection record in an instance, we should make sure that the semantic_code_search tool is not available.
Optional additional consideration
Consider whether the Ai::ActiveContext::Queries::Code should return a failed Result object for the "no collection record" error. Currently, it throws an exception for the reasons stated in !208905 (comment 2827429735), in particular:
I see a "no collection record" error as a server issue (like a
500). TheQueryshould raise an exception because embeddings indexing is not enabled for the instance.
- This is as opposed to a "project has no embeddings", which is an issue with the project that the client provided (so it's more a
400error)
Proposal
Add a check in API::Mcp::Handlers::ListTools#exclude_tool? to exclude the semantic_code_search if ::Ai::ActiveContext::Collections::Code.collection_record is nil.
Edited by Pam Artiaga