Skip to content

MCP: 502 on events/tool_calls (indices cortex_tool_calls/cortex_turns not found) + cwd→repo-slug mismatch in cortex_query #4

@andrehrferreira

Description

@andrehrferreira

Summary

While running a cross-project tool-usage analysis via the Cortex MCP server, several read paths returned 502 Bad Gateway because kind-routed global indices are missing, and cortex_query mis-derived the repo slug from the caller's cwd. Reproduced against a healthy daemon (api_reachable: true).

Environment

  • cortex MCP server cortex-mcp-server 0.1.0 (pid live), cortex-api 0.1.0 at http://127.0.0.1:17000
  • daemon up, api_reachable: true, 60+ indexed_repos
  • coverage.overall_severity: "warn" (see secondary findings)

Bugs

1. cortex_tool_calls / cortex_turns indices missing → 502 on events & tool-call search

cortex_tool_calls:

cortex-api .../v1/search/tool-calls returned HTTP 502 Bad Gateway
detail: Index `cortex_tool_calls` not found.

cortex_events_by_kind (kind=tool_call):

.../v1/search/events returned HTTP 502 Bad Gateway
detail: Index `cortex_tool_calls` not found.

cortex_events_by_kind (kind=turn):

.../v1/search/events returned HTTP 502 Bad Gateway
detail: Index `cortex_turns` not found.

A missing Meili index is a recoverable empty state, not a gateway failure — these should return 200 with empty hits (or 404/structured index_unavailable), not 502. Right now any consumer that asks for tool-call or turn telemetry hard-fails. The kind-routed indices (cortex_tool_calls, cortex_turns) appear to never have been created on this daemon despite turns/tool_calls being ingested per-repo (cortex-<repo>-turns style indices exist, e.g. keyword_search against cortex_decisions works).

2. cortex_query derives an un-indexed repo slug from cwd

Calling cortex_query without an explicit scope.repo from cwd E:\HiveLLM\Rulebook auto-resolved:

"scope_resolved": { "repo": "e-hivellm-rulebook" }
"notice": { "code": "repo_not_indexed", "message": "scope.repo `e-hivellm-rulebook` is not present in the cortex-api indexed-repo snapshot" }

…but the repo is indexed — under slug rulebook (present in status.indexed_repos). The cwd→slug derivation lowercases/joins the full path (e-hivellm-rulebook) instead of using the basename / the slug the indexer registered (rulebook). Result: default-scoped queries silently return empty for any project whose path has >1 segment. Passing scope.repo: "rulebook" explicitly works.

Repro

  1. cortex_tool_calls({ limit: 50 }) → 502
  2. cortex_events_by_kind({ kind: "tool_call" }) / { kind: "turn" } → 502
  3. From a nested project dir, cortex_query({ intent: "free_search", query: "x" }) with no scoperepo_not_indexed for a repo that is indexed under its basename slug.

Expected

  • Missing index → empty result set (200) or structured index_unavailable, never 502.
  • cwd→repo-slug resolution matches the slug under which the indexer registered the repo (basename), or falls back to fuzzy-matching indexed_repos before declaring repo_not_indexed.

Secondary findings (lower priority)

  • Coverage drift (/v1/health/coverage, severity warn): vectorizer backend present 15 / expected 594 (missing 579, unexpected 12); meili present 170 / expected 594 (missing 424, unexpected 50). Large gap between expected and present documents across both backends.
  • cortex_keyword_search oversize hits: an empty-query search against cortex_decisions returned a single 91 KB line that exceeded the MCP per-result token cap. Consider a default per-hit field cap or auto-applying attributes_to_retrieve when the caller omits it, so the tool is usable without manual field restriction.

Impact

Tool-call and turn telemetry are unreachable via MCP (502), and default-scoped cortex_query returns empty for normally-indexed projects — both block agent-side usage analytics and pre-change context retrieval.


Filed by an automated analysis session (Claude Code) with the user's authorization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions