Skip to content

refactor(mcp): fold schema tools into bm_schema - #1959

Merged
phernandez merged 3 commits into
mainfrom
test/mcp-bm-schema-port
Oct 29, 2026
Merged

phernandez merged 3 commits into
mainfrom
test/mcp-bm-schema-port

Conversation

@phernandez

@phernandez phernandez commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Remove the legacy schema_validate / schema_infer / schema_diff functions. bm_schema and the bm schema CLI now use the same code.

  • Moved the report renderers, guidance text and the validate/infer/diff logic from src/basic_memory/mcp/tools/schema.py into src/basic_memory/mcp/tools/note_schemas.py, and deleted schema.py. In note_schemas.py, bm_schema checks its arguments, opens one SchemaClient, and dispatches to _validate, _infer or _diff.
  • bm schema validate/infer/diff (src/basic_memory/cli/commands/schema.py) now call bm_schema(command=...).
  • Dropped the three schema_* re-exports from src/basic_memory/mcp/tools/__init__.py.
  • Updated a stale schema_validate() mention in a schema_router.py comment.

bm_schema's name, signature, annotations, description and output are unchanged.

User-visible CLI changes

  • bm schema now resolves its project with the helper bm tool uses. I moved run_tool's default-project logic into command_utils.project_or_default, and both commands call it. This has two effects:
    • --project is no longer checked against the local project map. A 'workspace/project' name or a project id reaches bm_schema and routes as it does under bm tool. An unknown project now fails with the tool's error, prefixed "Error during schema validate: ...". It used to say "No project found named: X".
    • With no --project and no default project configured, bm schema exits 1 with "Error: no default project is set; pass --project.", the same as bm tool. It used to pass None to the tool.
  • Removed the bm schema infer zero-notes branch. It printed "No notes found with type: X". It could no longer run, because the tool refuses an infer with no notes (NOT_FOUND) and the CLI already prints that refusal. Users now see "No notes found of type 'X'" and exit 0, as they did before through the error path.

All other flags and output are unchanged.

Tests

MCP: tests/mcp/test_tool_schema.py became tests/mcp/test_tool_bm_schema.py.

  • All 18 real-path tests call bm_schema(command=...).
  • 6 new real-path tests cover:
    • warning and error lines
    • infer excluded fields and infer JSON
    • infer with no notes
    • every drift section
    • no drift and diff JSON
    • diff with a schema but no notes

CLI: the mocked tests that patched basic_memory.mcp.tools.schema_* (11 in tests/cli/test_cli_schema.py, 5 in tests/cli/test_json_output.py) are replaced by test-int/cli/test_schema_commands_integration.py.

  • Its 13 tests run bm schema against a real test project, with notes written through bm tool write.
  • They cover the table, JSON, --strict, identifier-vs-type targets, --threshold, --save, nothing-to-report messages, an invalid schema (exit 1), drift and no drift, a project id passed as --project, and an unknown --project.
  • tests/cli/test_cli_schema.py keeps only the two tests that use no mocks: the routing-flag conflict and run_schema_tool.

Removed entries: the schema_* entries in tests/implementation_mcp.py and tests/mcp/test_tool_contracts.py.

Dropped

  • test_schema_{validate,infer,diff}_error_propagates. They mocked SchemaClient to raise RuntimeError, the tool has no handler for that case, so they covered no branch.
  • The mocked CLI tests listed above. Real-project tests replace them.

Not tested

  • The "no default project" branch in project_or_default, which bm tool also left untested. Saving a config with default_project=None in the test-int fixtures still left a default in place, and cli/** is excluded from coverage.

Verification

  • just fast-check passes. ty needs uv sync --extra milvus locally.
  • just test-unit-sqlite -k on the touched and dependent tests (bm_schema, cli schema, json output, tool contracts, bm_project, v1 registration, required project, manual regressions, cli consumers, tool_search, tool_read_note, cli_exit): all pass.
  • just test-unit-postgres -k "test_tool_bm_schema or test_cli_schema or test_json_output or test_tool_contracts or test_tool_bm_project": 65 passed.
  • just test-int-sqlite -k "test_schema_commands_integration or test_tool_commands_integration": 19 passed. just test-int-postgres -k test_schema_commands_integration: 13 passed.
  • note_schemas.py has 100% coverage from test_tool_bm_schema.py plus test_tool_bm_project.py.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CMYVL1x91B8kJxy7nn2GU8

Rename tests/mcp/test_tool_schema.py to test_tool_bm_schema.py and call
bm_schema(command="validate"/"infer"/"diff") instead of the unpublished
schema_validate/schema_infer/schema_diff functions.

Drop the three error-propagation tests that patched SchemaClient methods
with AsyncMock: they only asserted that an exception propagates, which no
branch in the tool handles.

Add real-path tests for the report paths the dropped and legacy tests did
not reach through bm_schema: warning and error lines, infer exclusions and
JSON, infer with no notes, every drift section, no drift, diff JSON, and
diff with a schema but no notes. schema.py and note_schemas.py stay at
100% coverage.

schema.py stays: `bm schema validate/infer/diff` still call it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMYVL1x91B8kJxy7nn2GU8
Signed-off-by: phernandez <paul@basicmachines.co>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T17:54:52.315824Z 14f8823 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Move the report renderers, guidance text and the validate/infer/diff
logic from mcp/tools/schema.py into note_schemas.py and delete
schema.py. Point `bm schema validate/infer/diff` at bm_schema and drop
the schema_* re-exports from mcp/tools/__init__.py.

CLI changes:
- With no --project and no default project, `bm schema` now exits 1
  with "pass --project" instead of passing None to the tool.
- Remove the infer zero-notes branch: bm_schema refuses an infer with no
  notes, and the CLI already prints that refusal.

Tests:
- Replace the mocked CLI schema tests (tests/cli/test_cli_schema.py,
  tests/cli/test_json_output.py) with real-project runs in
  test-int/cli/test_schema_commands_integration.py.
- Drop the schema_* entries from tests/implementation_mcp.py and
  tests/mcp/test_tool_contracts.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMYVL1x91B8kJxy7nn2GU8
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez phernandez changed the title test(mcp): port schema tool tests to bm_schema refactor(mcp): fold schema tools into bm_schema Oct 29, 2026
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 20fb86f12e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/basic_memory/cli/commands/schema.py Resolved
Move bm tool's default-project resolution into
command_utils.project_or_default and use it in run_tool and in the three
`bm schema` commands. `bm schema` no longer checks --project against the
local project map, so a 'workspace/project' name or a project id reaches
bm_schema and routes the same way it does under `bm tool`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMYVL1x91B8kJxy7nn2GU8
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 14f8823f09

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@phernandez
phernandez merged commit 7a75843 into main Oct 29, 2026
55 checks passed
@phernandez
phernandez deleted the test/mcp-bm-schema-port branch October 29, 2026 18:14
phernandez added a commit that referenced this pull request Oct 29, 2026
## Why

`just release v1.0.0` pre-flight-checks for a `## v1.0.0` heading on
`main`, so the changelog has to land first.

## What changed

`CHANGELOG.md`: the Unreleased section becomes `## v1.0.0 (2026-10-29)`.
Its existing items are kept, and the 60 or so commits since #1871 are
added:

- **Breaking:**
- the MCP surface is only `bm_*`, with the old tools deleted (#1944,
#1947, #1959, #1962–#1964)
  - `project` is required (#1934)
  - the ChatGPT adapters moved to Cloud
  - `bm tool` mirrors the tools (#1943)
  - the POSIX verbs are rebuilt and `bm tail` is removed (#1960)
  - cloud sync/bisync are removed (#1953)
  - `bm schema` project resolution (#1959)
  - LiteLLM is an optional extra
- **Features:** text-file line ranges in `bm_read`; chat imports return
their file paths.
- **Bug fixes:** including the three found in the 1.0 live test (#1971,
#1972, #1974), with contributor credits for @Flynn-Kawolsky (#1957),
@SWSAmor (#1951) and @MbappeWU (#1948).
- **Security:** the CodeRabbit deep-scan hardening batch.

I checked the entries against PR bodies rather than titles, and
corrected #1954, #1948 and #1967 to describe what they actually fixed.

The date is today; change it if the tag lands tomorrow.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01CMYVL1x91B8kJxy7nn2GU8

Signed-off-by: phernandez <paul@basicmachines.co>
Co-authored-by: Claude Opus 5.5 <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