fix(mcp): scope cortex_intelligence by explicit project param#3
Open
jessekemp1 wants to merge 1 commit into
Open
fix(mcp): scope cortex_intelligence by explicit project param#3jessekemp1 wants to merge 1 commit into
jessekemp1 wants to merge 1 commit into
Conversation
cortex_intelligence had no project arg, so the bridge fell back to _detect_current_project(), which runs 'git rev-parse --show-toplevel' in the bridge daemon's own cwd (always the cortex repo) and hardcodes a 'cortex' fallback. The IntelligenceQuery model also defaults project to 'cortex'. Net effect: every project-unscoped query was silently scoped to 'cortex', so a pre-flight about another project (e.g. Interac) returned 0.0 confidence. Add an optional project param and forward it to /intelligence/query when set; omit it when empty to preserve existing auto-detect behavior. Verified against the live bridge: no project -> scoped 'cortex'; project=interac -> scoped 'interac'. Co-authored-by: Isaac
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.
Summary
cortex_intelligencecould not be scoped to a project, so every project-unscoped query was silently answered against thecortexproject. A pre-flight question about a different project (e.g. "what cloud does Interac run on?") returned 0.0 confidence with no relevant context — not because the data was missing, but because the query never searched the right project.This adds an optional
projectparameter to the tool and forwards it to the bridge.Root cause
Two independent hardcoded-to-
cortexdefaults sit on the query path:mcp_server.py—cortex_intelligence(query, query_type)exposed noprojectparam and POSTed only{request, domain, query_type}to/intelligence/query.api/bridge_endpoint.py—IntelligenceQuery.projecthasdefault="cortex", so the omitted field became"cortex"before the handler ran.bridge.py:384— even when project is empty,_detect_current_project()runsgit rev-parse --show-toplevelwithcwd=self.root_dir(the bridge daemon's own directory, always the cortex repo) and falls back to a hardcodedreturn "cortex".The bridge is one long-lived daemon serving every Claude session across all projects; it has no channel to learn the caller's working context, so it cannot infer the project on its own. The only reliable signal is an explicit project from the caller.
Fix
project: str = ""arg tocortex_intelligence.This mirrors the sibling tools (
cortex_taskboard,cortex_outcomes,cortex_plan_create, and the cortex-dbxrecall_similar/record_decision) that already take an explicitproject.Verification
Against the live bridge:
projectcortex(the bug)project="interac"interac(fixed)Unit logic (forwarded when provided, omitted when empty) confirmed directly and covered by a new regression test in
tests/test_mcp_research_tools.py::TestCortexIntelligenceProjectScope. Tool count is unchanged, so existing registration tests stay green.Why here and not cortex-dbx
cortex_intelligence, the bridge, and_detect_current_project()live only in this repo.cortex-dbxis a separate Databricks App whose MCP tools already take an explicitproject, so it never had this bug.Recommended follow-ups (not in this PR)
IntelligenceQuery.projectdefault from"cortex"to empty, and make_detect_current_project()'s fallback project-agnostic (search all projects) so an unscoped query returns an honest cross-project result instead of silently biasing tocortex./scopeskill into/intelligence/queryso a session can set its active project.This pull request and its description were written by Isaac.