Skip to content

feat(mcp): minimal mem_find_project tool - #661

Open
carlosmoradev wants to merge 2 commits into
Gentleman-Programming:mainfrom
carlosmoradev:feat/mcp-find-project-minimal
Open

feat(mcp): minimal mem_find_project tool#661
carlosmoradev wants to merge 2 commits into
Gentleman-Programming:mainfrom
carlosmoradev:feat/mcp-find-project-minimal

Conversation

@carlosmoradev

@carlosmoradev carlosmoradev commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Draft PR for #304. Dropped the preview field to keep the diff tiny. It only returns
Project, MatchCount, and TopRank (using FTS5 bm25). All MCP tool count tests updated.

Summary by CodeRabbit

  • New Features

    • Added project discovery through memory relevance search.
    • Search results display project names, relevance rankings, and match counts.
    • Supports matching all search terms or any individual search term.
    • Available in the default agent toolset.
  • Bug Fixes

    • Added validation for empty searches and unsupported matching modes.
    • Search results are limited, consistently ranked, and exclude unavailable projects.

Fixes #304

Fixes #304

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds project-level memory relevance search through the mem_find_project MCP tool. The store groups and ranks full-text matches by project. The agent profile, registration, validation, formatting, and tests are updated.

Changes

Project relevance search

Layer / File(s) Summary
Store project search
internal/store/store.go, internal/store/store_test.go
Adds ProjectMatch and SearchProjects. The store groups observation matches by project and orders them by rank and match count. Tests cover matching modes, limits, filtering, and errors.
MCP project discovery tool
internal/mcp/mcp.go, internal/mcp/mcp_test.go
Registers mem_find_project, adds it to the agent profile, validates inputs, formats ranked results, and updates tool-count expectations. Tests cover success and error responses.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MCPClient
  participant handleFindProject
  participant Store
  MCPClient->>handleFindProject: query and match_mode
  handleFindProject->>Store: SearchProjects(query, match_mode, limit)
  Store-->>handleFindProject: ranked ProjectMatch results
  handleFindProject-->>MCPClient: formatted project list or tool error
Loading

Suggested labels: type:feature

Suggested reviewers: gentleman-programming

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the addition of the mem_find_project MCP tool.
Linked Issues check ✅ Passed The changes implement cross-project project grouping, match counts, relevance ranks, MCP registration, validation, and error handling required by issue #304.
Out of Scope Changes check ✅ Passed The store, MCP tool, and tests are directly related to the cross-project relevance routing objective in issue #304.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

@carlosmoradev
carlosmoradev marked this pull request as ready for review July 25, 2026 12:30

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/mcp/mcp_test.go`:
- Line 2257: Expand the tests around mem_find_project beyond tool registration
by invoking its handler with deterministic fixtures. Cover a successful search
result, missing query, invalid match_mode, no results, and store failures,
asserting each response and error behavior; keep the existing registration
assertion intact.

In `@internal/mcp/mcp.go`:
- Line 1199: Update the result formatting in the mem_find_project output around
TopRank so nearby computed ranks remain distinguishable and the returned value
preserves sufficient numeric precision; replace the fixed two-decimal formatting
in the fmt.Fprintf call with a precision-preserving representation while keeping
the existing project and match-count fields unchanged.

In `@internal/store/store_test.go`:
- Around line 8834-8906: Expand TestSearchProjects to cover empty queries,
any-mode matching, exclusion of deleted or blank-project observations,
zero/limited result bounds, query-error propagation, and deterministic TopRank
ordering. Use the existing test store and search-related helpers to create each
scenario, assert expected results and errors, and retain the current all-mode
grouping assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: acd92883-37d2-4a57-a6eb-7e1c4f617217

📥 Commits

Reviewing files that changed from the base of the PR and between 763a6ba and 485e7f4.

📒 Files selected for processing (4)
  • internal/mcp/mcp.go
  • internal/mcp/mcp_test.go
  • internal/store/store.go
  • internal/store/store_test.go

Comment thread internal/mcp/mcp_test.go
Comment thread internal/mcp/mcp.go Outdated
Comment thread internal/store/store_test.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/store/store_test.go`:
- Around line 8944-8948: The relevance-ordering tests need assertions beyond
result counts. In internal/store/store_test.go:8944-8948, update the limit-one
case to assert the sole result is the controlled high-relevance project-b. In
internal/mcp/mcp_test.go:7490-7495, assert project-one appears before
project-two and that each formatted result includes its match count and rank:
field; both sites require direct deterministic test coverage.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a9ef7ddc-6485-40aa-80c0-41c2ed4f38c2

📥 Commits

Reviewing files that changed from the base of the PR and between 485e7f4 and c537a47.

📒 Files selected for processing (3)
  • internal/mcp/mcp.go
  • internal/mcp/mcp_test.go
  • internal/store/store_test.go

Comment on lines +8944 to +8948
name: "limit restricts results",
query: "auth",
matchMode: "all",
limit: 1, // Should return only top 1 project
expectLen: 1,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Assert the relevance-ordering contract.

The PR requires mem_find_project to return projects ordered by relevance. These tests can pass if the store returns the wrong top project or the MCP handler reverses the ordered results.

  • internal/store/store_test.go#L8944-L8948: Assert that the controlled high-relevance fixture, project-b, is the single result for limit: 1.
  • internal/mcp/mcp_test.go#L7490-L7495: Assert that project-one occurs before project-two, and assert each formatted result includes its match count and rank: field.

As per path instructions, **/*_test.go must provide deterministic coverage.

📍 Affects 2 files
  • internal/store/store_test.go#L8944-L8948 (this comment)
  • internal/mcp/mcp_test.go#L7490-L7495
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/store/store_test.go` around lines 8944 - 8948, The
relevance-ordering tests need assertions beyond result counts. In
internal/store/store_test.go:8944-8948, update the limit-one case to assert the
sole result is the controlled high-relevance project-b. In
internal/mcp/mcp_test.go:7490-7495, assert project-one appears before
project-two and that each formatted result includes its match count and rank:
field; both sites require direct deterministic test coverage.

Source: Path instructions

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.

feat(mcp): add mem_find_project tool for cross-project relevance routing

1 participant