Skip to content

feat(mcp): shared parameter types, refusals and resolver for bm_* tools - #1835

Merged
phernandez merged 7 commits into
mainfrom
feat/1829-tool-foundations
Oct 23, 2026
Merged

phernandez merged 7 commits into
mainfrom
feat/1829-tool-foundations

Conversation

@phernandez

Copy link
Copy Markdown
Member

Bottom of the 1.0 tool-surface stack. Closes #1829 (tracking #1827).

What

  • mcp/tool_params.py: the parameter types every bm_* tool will use, each carrying the description a model reads and the hidden aliases older callers and host tools send.
    • NoteIdentifier (alias file_path), DirectoryPath
    • ProjectParam (alias project_id). parse_project classifies it once into ProjectByName or ProjectById, so routing never gets both.
    • Since (aliases timeframe, after_date), Page, PageSize (max 100)
    • Filters (alias metadata_filters), Items (alias entity_types; "entity" reads as "note")
  • mcp/refusals.py: refusal(code, message, try_instead=...) builds the tool error every refusal raises, as text or JSON (MCP tools report refusals inconsistently (isError false for read_content/read_note/move_note refusals) #1813).
  • mcp/note_targets.py: the one resolver.
    • open_project_target routes a target through the POSIX tools' resolve_project_path_route and opens the project client.
    • resolve_note resolves exactly: a miss is NOT_FOUND pointing to bm_search, and a bare project name is INVALID_ARGUMENTS pointing to bm_list.

No tool uses these yet; #1830–#1832 stack on this branch.

Deviations from #1829

  • Old-name alias middleware moves to 1.0 tools: registration cleanup, names, titles, annotations #1833. It maps old tool calls onto new tools, which only matters once the old tools are removed.
  • workspace is not a hidden alias. workspace + project combine two values into one, which a parameter alias cannot express. project="workspace/project" already routes, and the project description says so.

Tests

  • tests/mcp/test_tool_params.py: a probe tool on a throwaway FastMCP server checks aliases, string coercion, bounds and that the schema lists only primary names. Plus parse_project, item translation and refusal formats.
  • tests/mcp/test_note_targets.py: the real ASGI stack checks routing by name, by external id and by <project>/ prefix; NOT_FOUND; bare project names; and that non-404 failures pass through.
  • just fast-test on both files: 27 passed. just fast-check: lint, format and typecheck clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_018CoZ3jWnMJsyQsik4tPySk

phernandez and others added 3 commits October 23, 2026 05:59
Foundations for the 1.0 tool surface (#1829, tracking #1827). Every bm_* tool
will name its target, project, time window, paging, filters and item kinds the
same way, so the types live in one module with the description a model reads
and the hidden aliases older callers and host tools use:

- NoteIdentifier (alias file_path) and DirectoryPath
- ProjectParam (alias project_id), classified once by parse_project into a
  name or an external id so routing never receives both
- Since (aliases timeframe, after_date), Page, PageSize (max 100)
- Filters (alias metadata_filters) and Items (alias entity_types; "entity"
  reads as "note")

refusals.refusal() builds the tool error every bm_* refusal raises: the code,
what was wrong, and the call to try instead, as text or JSON (#1813).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018CoZ3jWnMJsyQsik4tPySk
Signed-off-by: phernandez <paul@basicmachines.co>
The shared resolver for the 1.0 tools (#1829). open_project_target()
classifies the `project` argument, lets a '<project>/path' prefix choose or
confirm the project through the POSIX tools' routing, and yields a client for
that project. resolve_note() resolves the routed target to an external id with
strict matching: a miss is a NOT_FOUND refusal pointing to bm_search, and a bare
project name is an INVALID_ARGUMENTS refusal pointing to bm_list. Other
resolution failures pass through unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018CoZ3jWnMJsyQsik4tPySk
Signed-off-by: phernandez <paul@basicmachines.co>
open_project_target() now refuses a target that climbs out of its project
('../x', '~', an absolute path, or a symlink out of a local project) with an
OUTSIDE_PROJECT refusal, before any tool reads or writes. Remote projects are
checked lexically; only a local project's root is resolved against the
filesystem (#1807). A leading '/' anchors at the project root, so '/' and
'/specs' stay valid targets. The refusal follows the caller's output_format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018CoZ3jWnMJsyQsik4tPySk
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez
phernandez added this pull request to stack #1841 October 23, 2026 14:13
@phernandez
phernandez marked this pull request as ready for review October 23, 2026 14:16
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-23T16:55:26.178282Z 9ee1d18 New commits
ℹ️ 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.

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

ℹ️ 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/mcp/note_targets.py Resolved
Comment thread src/basic_memory/mcp/tool_params.py Resolved
Codex review on #1835:
- open_project_target takes `kind`. A "path" (a directory, or a file to
  create) must not climb out of the project; an "identifier" resolves
  through the project-scoped API and is not checked as a path, so a note
  titled 'Home ~ Plan' can be addressed by title.
- items=[null] reaches validation and is refused instead of being dropped
  into the default note search.

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

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

ℹ️ 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/mcp/tool_params.py Resolved
Comment thread src/basic_memory/mcp/tool_params.py Resolved
Comment thread src/basic_memory/mcp/note_targets.py Resolved
items='[null]' or '[null, "relation"]' went through parse_str_list,
which drops nulls, so the malformed request became a default or
relation-only search. A JSON-array string is now decoded first and gets
the same null check as a native list. Codex review on #1835.

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

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

ℹ️ 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/mcp/note_targets.py Resolved
Two notes with one title make the strict resolve answer 409; resolve_note
passed that through as a raw client error, so JSON callers got text. It
now matches on the API's status: 404 is NOT_FOUND, 409 is AMBIGUOUS with
the API's detail naming the candidates. Codex review on #1835.

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

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

ℹ️ 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/mcp/note_targets.py Resolved
A project prefix that conflicts with `project`, an unqualified path in a
multi-project session, and an ambiguous mount raised routing exceptions
that reached the client as plain text. open_project_target turns them
into INVALID_ARGUMENTS / AMBIGUOUS refusals with routing's own message,
so JSON callers get the refusal shape. Codex review on #1835.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018CoZ3jWnMJsyQsik4tPySk
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez
phernandez merged commit b978f31 into main Oct 23, 2026
33 checks passed
@phernandez
phernandez deleted the feat/1829-tool-foundations branch October 23, 2026 19:04
phernandez added a commit that referenced this pull request Oct 23, 2026
Codex review on #1835:
- open_project_target takes `kind`. A "path" (a directory, or a file to
  create) must not climb out of the project; an "identifier" resolves
  through the project-scoped API and is not checked as a path, so a note
  titled 'Home ~ Plan' can be addressed by title.
- items=[null] reaches validation and is refused instead of being dropped
  into the default note search.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018CoZ3jWnMJsyQsik4tPySk
Signed-off-by: phernandez <paul@basicmachines.co>
phernandez added a commit that referenced this pull request Oct 23, 2026
items='[null]' or '[null, "relation"]' went through parse_str_list,
which drops nulls, so the malformed request became a default or
relation-only search. A JSON-array string is now decoded first and gets
the same null check as a native list. Codex review on #1835.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018CoZ3jWnMJsyQsik4tPySk
Signed-off-by: phernandez <paul@basicmachines.co>
phernandez added a commit that referenced this pull request Oct 23, 2026
Two notes with one title make the strict resolve answer 409; resolve_note
passed that through as a raw client error, so JSON callers got text. It
now matches on the API's status: 404 is NOT_FOUND, 409 is AMBIGUOUS with
the API's detail naming the candidates. Codex review on #1835.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018CoZ3jWnMJsyQsik4tPySk
Signed-off-by: phernandez <paul@basicmachines.co>
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.0 tools: shared foundations (identifier, project, since, filters, errors, aliases)

1 participant