Repository navigation
fix(mcp): require explicit project scope for note tools - #1934
Conversation
Require nonempty project scope on note, folder, context and schema tools. Preserve explicit multi-project search, resolve saved prompt defaults before dispatch, and update manual and recovery guidance. Refs #1919. Signed-off-by: phernandez <paul@basicmachines.co>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ef32ca2308
ℹ️ 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".
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
|
@codex review latest head a25097e. The test-only follow-up aligns default-project, qualified permalink, compact discovery, and root-navigation integration flows with the explicit scope contract. Full MCP integration suite: 336 passed. just fast-check passes. Prior prompt findings remain fixed; all canonical skills and tool manuals are updated. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
## Why #1934 made `project` required on the note tools. Cloud's hosted `bm_agent` now follows the same contract (basic-memory-cloud branch `core-required-project-scope`), but `bm-agent(3)` still listed `project=None`. ## What changed - SYNOPSIS: `bm_agent(command, project, agent=None, ...)`, the same layout #1934 gave `bm-edit(3)`. - DESCRIPTION: one paragraph saying every command needs `project`; for `review` and `keep_all` it only picks the workspace. Hand-owned page (`generated: hand`), so no regen. ## Testing - `uv run pytest -q --no-cov tests/test_man_pages.py tests/test_bm_tool_manual_parameters.py`: 71 passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016N9c6ouiT4Wid3arGR41Dv Signed-off-by: phernandez <paul@basicmachines.co> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
## 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>
## Summary A call that leaves out `project` on a tool that requires it now gets a Basic Memory refusal instead of pydantic's raw validation error. The refusal tells the model to call `bm_project(command='list')` to find a project. Fixes #1984. Before: ``` Missing required keyword only argument [type=missing_keyword_only_argument ...] ``` After (text): ``` INVALID_ARGUMENTS: bm_list needs `project`: the project name, 'workspace/project', or external id. Try instead: bm_project(command='list') to discover projects ``` ## Why PR #1934 made `project` required on the nine one-project tools: bm_read, bm_write, bm_edit, bm_move, bm_delete, bm_list, bm_find, bm_context and bm_schema. That is intended. But a client holding a tool list cached from before #1934 still treats `project` as optional. Its calls failed with an error that does not say what `project` is or how to find one. ## What changed - New `MissingProjectMiddleware` in `src/basic_memory/mcp/missing_project.py`. On each tool call it looks up the tool and reads its input schema. - If `project` is not in the schema's `required` list, the call passes through untouched. bm_search and bm_project are in this group. - Otherwise, if neither `project` nor its alias `project_id` is a non-blank string, it raises an `INVALID_ARGUMENTS` refusal through the existing `refusal()` helper (`src/basic_memory/mcp/refusals.py`). - The refusal uses the call's `output_format` when it is "text" or "json", else the tool's schema default. bm_context defaults to JSON, so its refusal is JSON. - `src/basic_memory/mcp/server.py` registers the middleware after the two existing ones. The check reads the schema, not a list of tool names. So it also covers tools that replace or add to the core tools on the same server instance, such as a hosted deployment's own tools. Rejected alternatives: - Making `project` default to `None` and checking it in each tool. That publishes `project` as optional again, which undoes #1934. - Catching the `ValidationError` after the call. That depends on how FastMCP wraps it, which can change between releases. ## Tests New `tests/mcp/test_missing_project.py` (54 tests, in-memory FastMCP client): - Each of the nine tools refuses `project` missing, `None`, `""` and `" "`, with `isError` set and the hint text. - `output_format="json"` gives `{"error": "INVALID_ARGUMENTS", ..., "try_instead": ...}`. bm_context with no `output_format` gives JSON too. - A test-only tool with `project: ProjectParam` is refused the same way, which shows the check reads the schema. - `project` or `project_id` set passes through. A tool with an optional `project` is untouched. bm_search keeps its own scope refusal. Unknown tools still get FastMCP's error. - The shipped `mcp` instance has the middleware and refuses `bm_list` with no project. Local runs on this branch: - `BASIC_MEMORY_ENV=test uv run pytest -q --no-cov -n 8 --timeout 60 tests/mcp`: `1234 passed, 4 warnings in 976.43s`. - `ruff check`, `ruff format --check`, `ty check` and `pyright` on the changed files: clean. Updated integration tests (second commit, `139b36e8`): - `test-int/mcp/test_default_project_mode_integration.py` (2 tests) and `test-int/mcp/test_single_project_mcp_integration.py` asserted pydantic's old text (`Missing required keyword only argument`, `at least 1 character`). They now match `INVALID_ARGUMENTS: bm_write needs \`project\``. - `test-int/mcp/test_param_aliases_integration.py::test_read_rejects_removed_pagination` checks that bm_read rejects `page`. It left out `project`, so the new refusal answered first. It now passes `project` and still asserts `unexpected_keyword_argument`. ## Rollback Remove the `mcp.add_middleware(MissingProjectMiddleware())` line in `server.py`. Tracking: BMEM-68. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Drew Cain <groksrc@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Why
The 1.0 Haiku benchmark found 16 path/project refusals versus three on v0.24.1. Every affected call omitted
projectin a multi-project session:bm_read(identifier="notes/plan.md")could be refused as “no project 'notes'.” Make scope an explicit input contract instead of relying on path inference or recovery after dispatch.Closes #1919.
What Changed
projectonbm_read,bm_write,bm_edit,bm_move,bm_delete,bm_list,bm_find,bm_context, andbm_schema, including single-project and constrained sessions.project,projects, orall_projects=Trueexplicitly. Requireprojectforbm_project(command="recent"); project discovery, creation and bundled manuals remain available without a selected project.bm_list(path="/", project=...)list that project's root. Project discovery usesbm_project(command="list")../skillsworkflow. Update scope guidance in all 18 MCP-using skills, scope all 204 documented project-scoped calls, refresh the combined-skill router and onboarding reference, and regenerate Pi's four bundled references. The CI-only and local-doctor skills use no affected MCP calls.Implementation Details
The shared project parameter rejects missing, null and blank values at the MCP boundary, while preserving project names,
workspace/project, UUIDs and the hiddenproject_idcompatibility alias. Required parameters are reflected in the advertised schemas. Search and project management retain optional schema fields because their commands support alternative explicit scopes or unscoped discovery; those conditional requirements are enforced before project I/O.Existing qualified-path agreement, workspace isolation, revision guards and exact note resolution remain in place. Saved prompts resolve their configured default at their entrypoint, then pass it explicitly; when no project resolves, they direct the caller to discovery. Recovery examples retain scope so a suggested read/list/edit is valid under the new contract.
Testing
just fast-check: passed (lint, formatting and fulltycheck).just package-check: passed across Claude Code, Codex, shared skills/archive builds, Hermes, OpenClaw, Tau and Pi. Pi reference regeneration leaves its checked-in copies clean.uv run pytest tests/mcp -q -n 4 --dist loadfile --no-cov: 1,989 passed on the initial implementation.uv run pytest tests/mcp/test_required_project.py tests/mcp/test_prompt_tool_delegation.py tests/mcp/test_prompts.py tests/mcp/test_recent_activity_prompt_modes.py tests/test_skills_dist.py -q --no-cov: 138 passed after the prompt/skill follow-up.uv run pytest test-int/mcp/test_index_readiness_integration.py test-int/mcp/test_edit_note_integration.py test-int/mcp/test_deferred_manual_contracts.py test-int/bughunt_fixes/test_cli_tool_read_note_security_error.py -q --no-cov: 43 passed.uv run pytest test-int/mcp -q -n 4 --dist loadfile --no-cov: 336 passed after updating legacy default/permalink/navigation integration contracts. Includes rejection of missing scope with a configured default and blank scope under a server constraint.just man-regen: generated all affected registry-owned SYNOPSIS/PARAMETERS blocks; rerun leaves the tree unchanged.uv run pytest tests/test_man_pages.py tests/test_bm_tool_manual_parameters.py -q --no-cov: 71 passed.just doctor: passed the sandboxed write/index/search self-test.New regressions cover required schemas and pre-I/O rejection for missing/null/blank scope, UUID alias reads, discovery without scope, same-path reads in separate projects, both explicit cross-project search alternatives, unresolved prompt/adapter scope and dispatching a scoped checksum-conflict recovery call.
Risks / Follow-ups
This deliberately changes the 1.0 MCP contract. Clients must refresh cached schemas and supply scope even when a project constraint or qualified identifier previously supplied it implicitly. Multi-project search remains available; default-project fallback is not restored at the tool boundary. Hosted wrappers and external callers retain their own entrypoint contracts and must pass explicit scope when delegating to these tools.
Local validation used SQLite; PostgreSQL validation is left to CI. The Haiku benchmark motivated this change but has not been rerun against this commit, so no new token/refusal reduction claim is made.