fix(mcp): don't auto-scope to a microservice absent from the index#331
Merged
Conversation
Launching the MCP server from the config/context directory — a top-level child of source_root with no build marker and no source — made detect_microservice_from_path return that dir name via its "first path segment under root" fallback. ScopeManager then auto-scoped every query to a microservice with zero indexed rows, so all tools returned empty results, even though the index was intact and path resolution was correct (reproduced with the bank-chat fixture: search returned [] from bank-chat-context/ but real hits from the parent). Validate the detected scope against the indexed microservice set (ScopeManager._indexed_microservices -> graph microservice_counts); a candidate with no indexed code is suppressed to None (system scope). A real microservice the operator is working in is, by definition, present in the index, so this cannot suppress a legitimate scope. An empty or unreadable index keeps the detected candidate (never silently disables auto-scope). Query-time only: no schema, ontology, embedding, or env-var change; no reindex required. Co-Authored-By: Claude <[email protected]>
7ed77f3 to
49a7ada
Compare
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.
Problem
Launching the MCP server from the config/context directory (a top-level child of
source_rootwith no build marker and no source) made every tool return empty results — even thoughinitbuilt the index correctly and path resolution was right.Reproduced with the bank-chat fixture:
searchreturnedresults: []frombank-chat-context/, but real hits from the parenttests/bank-chat-system/(where.mcp.json+ the index live). Same index, same resolution — the only difference was the bogus auto-scope.Root cause
detect_microservice_from_pathmislabels any codeless top-level child ofsource_rootas a microservice via its "first path segment under root" fallback.ScopeManagerthen setdefault_scope = 'bank-chat-context'and auto-scoped every query to a microservice with zero indexed rows → empty from all tools. The index's realmicroservicevalues arechat-core/chat-assign, sobank-chat-contextmatched nothing.Fix
ScopeManager._detect_scopenow validates the detected candidate against the indexed microservice set (_indexed_microservices→ graphmicroservice_counts()). A candidate with no indexed code →None(system scope). A real microservice the operator is working in is, by definition, in the index, so this cannot suppress a legitimate scope (preserves the auto-scope feature). Empty/unreadable index keeps detection (no silent disabling).Query-time only — no reindex required; restart the MCP server and tools return data.
User-visible behaviour change
No schema, ontology, embedding, or env-var change.
Manual evidence
Drove the real stdio server from
tests/bank-chat-system/bank-chat-context/:[scope] Detected microservice: bank-chat-context→searchresults: [][scope] No microservice detected→searchreturns 5 (top:com.bank.chat.engine.kafka.ChatKafkaConfiguration)Tests
tests/test_microservice_scope.py::TestScopeManagerAutoScopeValidation(4): the regression (codeless context dir → no scope), a non-regression guard (real indexed microservice dir → still scopes), the empty-index fallback, and_indexed_microservicesextraction. Full non-heavy suite: 835 passed, 13 skipped.🤖 Generated with Claude Code