Skip to content

fix(mcp): validate all schema-covered types when schema_validate gets no arguments - #1060

Merged
phernandez merged 2 commits into
mainfrom
fix/1013-schema-validate-all-types
Jul 15, 2026
Merged

fix(mcp): validate all schema-covered types when schema_validate gets no arguments#1060
phernandez merged 2 commits into
mainfrom
fix/1013-schema-validate-all-types

Conversation

@phernandez

Copy link
Copy Markdown
Member

Summary

schema_validate() called with no identifier and no note_type now validates every note type that has a schema defined, returning a per-type breakdown — instead of reporting the misleading "No Notes Found of Type 'unknown'".

Root cause

  • src/basic_memory/api/v2/routers/schema_router.py: the batch path was entities = await _find_by_note_type(...) if note_type else [] — with no note_type there was no all-types branch, so the router always returned an empty report.
  • src/basic_memory/mcp/tools/schema.py: effective_type = note_type or result.note_type or "unknown" fed the empty report into the total_entities == 0 guard, rendering "No Notes Found of Type 'unknown'".

Fix

  • Router: when both parameters are absent, enumerate schema notes' target types (frontmatter entity field, matched against stored note types via generate_permalink normalization — the same rule implicit type lookup uses), validate entities across all of them, and return an aggregated ValidationReport with a new type_summaries field (TypeValidationSummary per type). The per-entity validation loop is extracted into _validate_note_entities and shared with the by-type path.
  • Schema: ValidationReport gains type_summaries: list[TypeValidationSummary] (defaults to empty, backward compatible).
  • MCP tool: detects all-types mode up front. No schemas defined returns "No Schemas Defined" guidance (or a clear JSON error); otherwise the report renders a ## By Type section, e.g. person: 1/1 valid, meeting: no notes.
  • The CLI's bm schema validate with no target flows through the same path and now works as its help text always claimed.

Test plan

  • tests/api/v2/test_schema_router.py: all-types with two schemas (one with notes, one without), no schemas defined, and target-type normalization (entity: Person covering snake_case person notes).
  • tests/mcp/test_tool_schema.py: no-args text + JSON output with schemas present, and "No Schemas Defined" guidance + JSON error with none defined (regression for the 'unknown' message).
  • uv run pytest tests/api/v2/test_schema_router.py tests/mcp/test_tool_schema.py tests/cli/test_cli_schema.py tests/mcp/test_client_schema.py — 63 passed.
  • uv run ruff check src tests test-int, uv run ruff format, just typecheck — clean.

Fixes #1013

🤖 Generated with Claude Code

@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: 670dc89e82

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/api/v2/routers/schema_router.py
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

recheck

@phernandez
phernandez force-pushed the fix/1013-schema-validate-all-types branch from 670dc89 to a8d6ea1 Compare July 15, 2026 04:42

@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: a8d6ea135c

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/api/v2/routers/schema_router.py
phernandez and others added 2 commits July 15, 2026 00:03
… no arguments

schema_validate() called without note_type or identifier returned an empty
report, which the MCP tool rendered as the misleading "No Notes Found of
Type 'unknown'" guidance (#1013).

Router: when neither parameter is given, enumerate every note type that has
a schema note (matching the frontmatter entity field against stored note
types via generate_permalink normalization, the same rule implicit type
lookup uses), validate all of them, and return an aggregated
ValidationReport with a new per-type type_summaries breakdown. The shared
per-entity validation loop is extracted into _validate_note_entities.

MCP tool: detect all-types mode up front. With no schemas defined, return
"No Schemas Defined" guidance (or a clear JSON error) instead of the
'unknown' message; otherwise render the report with a By Type section
(e.g. person: 1/1 valid, meeting: no notes). The CLI's
'bm schema validate' with no target flows through the same path and now
works as its help text always claimed.

Fixes #1013

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez
phernandez force-pushed the fix/1013-schema-validate-all-types branch from a8d6ea1 to 3e2d905 Compare July 15, 2026 05:03
@phernandez

Copy link
Copy Markdown
Member Author

All current review findings are addressed on a main-rebased head. All-types validation now discovers implicit schema targets, inline schemas, and explicit cross-type schema references. The full schema router suite passes (22 tests), with Ruff, formatting, type checking, and diff checks clean. @codex review\n\n/recheck

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 3e2d90595f

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@phernandez
phernandez merged commit e8f5220 into main Jul 15, 2026
27 checks passed
@phernandez
phernandez deleted the fix/1013-schema-validate-all-types branch July 15, 2026 05:27
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.

[BUG] schema_validate with no identifier or note_type defaults to validating type 'unknown' instead of all types

1 participant