Skip to content

fix(mcp): preserve distinct block search results by relationship ID - #2414

Draft
carlomarmo wants to merge 1 commit into
Open-Source-Legal:mainfrom
carlomarmo:fix/mcp-block-search-identity
Draft

carlomarmo wants to merge 1 commit into
Open-Source-Legal:mainfrom
carlomarmo:fix/mcp-block-search-identity

Conversation

@carlomarmo

Copy link
Copy Markdown

Summary

MCP block search results are deduplicated by document, label and truncated preview text. Two distinct relationships in the same document can share that preview, so one result disappears even when their full text differs.

Expose relationship_id on block hits and deduplicate by that stable identity. Repeated hits for the same relationship still retain the first ranked result; distinct relationships and hits without an identity remain separate.

Changes

  • Add the relationship ID to the block formatter, consistent with passage annotation_id.
  • Keep the pure deduplication helper beside the formatters and import it into tools.py, retaining its existing import path for callers.
  • Defer the document-model import to the lookup branch so formatting with the existing pre-fetched lookup is database-independent.
  • Add five focused regression tests and update the existing duplicate-block fixture to provide an identity.
  • Add a changelog fragment. Retrieval, permission filtering and ranking are unchanged.

Test plan

  • python -m unittest opencontractserver.mcp.tests.test_search_results -v: all five tests pass against the production formatter/helper.

  • The same tests with the unchanged baseline deduplication helper fail in three expected cases: identical truncated previews, identical full text on distinct relationships, and missing IDs.

  • Covers repeated-relationship collapse, retention of the first ranked hit, passage identity and ordering.

  • Database-backed MCP tests and the full backend suite were not run locally: this workspace has no Docker or PostgreSQL services. These remain for repository CI.

  • Changed-file pre-commit hooks pass: whitespace, EOF, changelog, pyupgrade, Black, isort and flake8.

  • Full-project mypy checks 1,642 files and reports the same two errors reproduced on unchanged base 1e859dc (1,641 files):

    • opencontractserver/tests/test_coverage_core_scalars.py:45: ListValueNode.values expects a tuple.
    • config/graphql/automation.py:151: CollectedFields has no values attribute.
      Both runs also log the same optional pdfredact import warning. No new mypy errors.
  • git diff --check and changelog validation pass.

Checklist

  • Focused formatter/deduplication regression tests pass locally
  • Changelog fragment added
  • No new dependencies, migrations or frontend changes
  • Full pre-commit check green (existing mypy errors reproduced on the base)
  • Database-backed MCP integration tests validated in CI

Draft pending integration CI and resolution of the existing type-check baseline.

This branch has not been deployed

No deployments
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