Skip to content

feat: current_context MCP tool — lightweight session awareness#7

Merged
EtanHey merged 1 commit intomainfrom
feat/session-awareness
Feb 19, 2026
Merged

feat: current_context MCP tool — lightweight session awareness#7
EtanHey merged 1 commit intomainfrom
feat/session-awareness

Conversation

@EtanHey
Copy link
Copy Markdown
Owner

@EtanHey EtanHey commented Feb 19, 2026

Summary

  • Adds brainlayer_current_context — 12th MCP tool, fast (no embedding needed)
  • Returns recent sessions, active projects, branches, files, and active plan
  • Designed for voice assistants and quick context injection at conversation start
  • CurrentContext dataclass in engine.py with format() method

Test plan

  • 5 unit tests for CurrentContext formatting (empty, projects, branches, plan, file truncation)
  • MCP tool count updated to 12, tool registration + annotations verified
  • 37 tests pass in 5s

🤖 Generated with Claude Code


Note

Medium Risk
Adds a new MCP tool and DB-backed query path (via file_interactions and session_context) which could impact performance or fail on unexpected DB schemas/data, but changes are read-only and additive.

Overview
Adds a new lightweight current_context() capability in engine.py, including a CurrentContext dataclass with a concise markdown format() and a DB query for recent distinct file_interactions within a configurable hours window.

Exposes this via a new read-only MCP tool brainlayer_current_context (tool count now 12), wiring it through call_tool to _current_context, and adds unit/integration test coverage for formatting and MCP registration/annotations.

Written by Cursor Bugbot for commit a0540a5. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new context tool that displays your current working context, including recent sessions, active projects, recent files, active branches, and active plan in a formatted view.
  • Tests

    • Added comprehensive test coverage for context formatting and retrieval functionality.

Adds brainlayer_current_context — a fast, no-embedding tool that returns
recent sessions, active projects, branches, files, and active plan.
Designed for voice assistants and quick context injection at conversation
start.

- CurrentContext dataclass with format() method in engine.py
- current_context() queries session_context + file interactions
- 12th MCP tool, read-only annotations
- 5 unit tests, tool count tests updated to 12

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@EtanHey EtanHey merged commit db338c1 into main Feb 19, 2026
0 of 3 checks passed
@EtanHey EtanHey deleted the feat/session-awareness branch February 19, 2026 19:53
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 19, 2026

Caution

Review failed

The pull request is closed.

📜 Recent review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2fc35e4 and a0540a5.

📒 Files selected for processing (4)
  • src/brainlayer/engine.py
  • src/brainlayer/mcp/__init__.py
  • tests/test_engine.py
  • tests/test_think_recall_integration.py

📝 Walkthrough

Walkthrough

A new CurrentContext dataclass and current_context() function were added to the engine to compute and format working context from recent sessions and file interactions. The feature is exposed via a new MCP tool brainlayer_current_context, with supporting tests added for formatting and integration validation.

Changes

Cohort / File(s) Summary
Engine API
src/brainlayer/engine.py
Added CurrentContext dataclass with fields for recent sessions, active projects, branches, files, and plan; introduced current_context() function that aggregates context from sessions and file interactions within a configurable time window and formats output as markdown.
MCP Integration
src/brainlayer/mcp/__init__.py
Added brainlayer_current_context tool to the MCP tool list with routing in call_tool(); implemented internal _current_context() function to invoke engine function, format results, and handle errors.
Test Coverage
tests/test_engine.py, tests/test_think_recall_integration.py
Added unit tests for CurrentContext formatting with scenarios covering empty context, projects, branches, plans, and file truncation; updated MCP tool count expectations from 11 to 12 and validated presence of new tool in registered tools list.

Sequence Diagram(s)

sequenceDiagram
    participant Client as MCP Client
    participant MCP as brainlayer.mcp
    participant Engine as brainlayer.engine
    participant Store as VectorStore

    Client->>MCP: call_tool("brainlayer_current_context", hours=24)
    MCP->>Engine: current_context(store, hours=24)
    Engine->>Store: sessions(store, days=...)
    Store-->>Engine: [SessionInfo, ...]
    Engine->>Store: file_interactions(past 24 hours)
    Store-->>Engine: [FileInteraction, ...]
    Engine->>Engine: aggregate projects, branches, plan
    Engine->>Engine: format() -> markdown string
    Engine-->>MCP: CurrentContext
    MCP-->>Client: [TextContent with formatted context]
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Whisker-twitches with delight!
New context threads, woven tight,
Sessions, files, branches bright—
The garden of work, in focus light!
MCP tools now multiply,
Awareness soars way up high! 🌟

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/session-awareness

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread src/brainlayer/engine.py
result = CurrentContext()

# Get recent sessions
recent = sessions(store, days=max(1, hours // 24) or 1, limit=10)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Floor division truncates hours-to-days conversion

Medium Severity

The hours // 24 floor division truncates partial days, causing the sessions query window to be narrower than intended. For example, hours=25 yields days=1 (24 hours), so sessions between 24–25 hours ago are missed, even though the file_interactions query on line 472 correctly uses timedelta(hours=25). The fix would be ceiling division (e.g., (hours + 23) // 24) to ensure the sessions window fully covers the requested hours range. Also, or 1 is redundant since max(1, ...) already guarantees a value ≥ 1.

Fix in Cursor Fix in Web

Comment thread src/brainlayer/engine.py
""",
(date_from,),
)
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DISTINCT query with ORDER BY non-selected column

Medium Severity

The query uses SELECT DISTINCT file_path ... ORDER BY timestamp DESC, but timestamp is not in the SELECT list. SQLite does not allow ORDER BY on a column outside the DISTINCT select list — it will either error or silently ignore the ordering. This means recent_files won't be ordered by most recent interaction as intended. A GROUP BY file_path with MAX(timestamp) or a subquery would achieve the desired recency ordering.

Fix in Cursor Fix in Web

Comment thread src/brainlayer/engine.py
for f in self.recent_files[:10]:
# Show just the filename, not full path
name = f.rsplit("/", 1)[-1] if "/" in f else f
parts.append(f"- {name}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File count header mismatches actual displayed items

Low Severity

The header displays len(self.recent_files) (up to 20 from the SQL query) but only the first 10 files are listed via self.recent_files[:10]. When there are more than 10 files, the output says something like "Recent files (15):" but only shows 10 entries, creating a confusing mismatch for the user. The count in the parentheses doesn't reflect what's actually rendered.

Fix in Cursor Fix in Web

EtanHey added a commit that referenced this pull request Feb 19, 2026
)

Adds brainlayer_current_context — a fast, no-embedding tool that returns
recent sessions, active projects, branches, files, and active plan.
Designed for voice assistants and quick context injection at conversation
start.

- CurrentContext dataclass with format() method in engine.py
- current_context() queries session_context + file interactions
- 12th MCP tool, read-only annotations
- 5 unit tests, tool count tests updated to 12

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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