Skip to content

fix(mcp): scope cortex_intelligence by explicit project param#3

Open
jessekemp1 wants to merge 1 commit into
mainfrom
fix/cortex-intelligence-project-scope
Open

fix(mcp): scope cortex_intelligence by explicit project param#3
jessekemp1 wants to merge 1 commit into
mainfrom
fix/cortex-intelligence-project-scope

Conversation

@jessekemp1

Copy link
Copy Markdown
Owner

Summary

cortex_intelligence could not be scoped to a project, so every project-unscoped query was silently answered against the cortex project. 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 project parameter to the tool and forwards it to the bridge.

Root cause

Two independent hardcoded-to-cortex defaults sit on the query path:

  1. mcp_server.pycortex_intelligence(query, query_type) exposed no project param and POSTed only {request, domain, query_type} to /intelligence/query.
  2. api/bridge_endpoint.pyIntelligenceQuery.project has default="cortex", so the omitted field became "cortex" before the handler ran.
  3. bridge.py:384 — even when project is empty, _detect_current_project() runs git rev-parse --show-toplevel with cwd=self.root_dir (the bridge daemon's own directory, always the cortex repo) and falls back to a hardcoded return "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

  • Add an optional project: str = "" arg to cortex_intelligence.
  • Forward it in the request body when set; omit it when empty so existing auto-detect/back-compat behavior is preserved.

This mirrors the sibling tools (cortex_taskboard, cortex_outcomes, cortex_plan_create, and the cortex-dbx recall_similar / record_decision) that already take an explicit project.

Verification

Against the live bridge:

Request Scoped to
no project cortex (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-dbx is a separate Databricks App whose MCP tools already take an explicit project, so it never had this bug.

Recommended follow-ups (not in this PR)

  • Change IntelligenceQuery.project default 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 to cortex.
  • Wire the /scope skill into /intelligence/query so a session can set its active project.

This pull request and its description were written by Isaac.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant