Repository navigation
Description
Bug
Write a note tagged ['alpha','beta']. search_notes(query="tag:alpha,beta") matches it (the tool's tag: parser splits commas). The same intent via the parameter search_notes(tags="alpha,beta") returns ZERO results because coerce_list wraps the string as the single literal tag ['alpha,beta'], which matches nothing. Within one tool, comma-string tags behave two different ways. It is also inconsistent with write_note, whose documented tags convention splits comma-strings. (CLI search-notes is unaffected — it uses repeatable --tag and builds a real list.)
Root cause
src/basic_memory/mcp/tools/search.py:679-682 applies BeforeValidator(coerce_list) to tags. coerce_list (src/basic_memory/utils.py:559-572) JSON-parses array strings but for any other string returns [v] (wraps without splitting). Meanwhile the tool's own tag: query parser at search.py:882-884 explicitly splits comma-separated lists ('tag:coffee,brewing'), creating the internal inconsistency. The same coerce_list non-split also affects note_types/entity_types/categories comma-strings (search.py:646/653/661).
Suggested fix
Use a tag-aware coercer for the search_notes tags parameter that splits bare comma-strings (mirroring parse_tags / the tag: shorthand), e.g. replace BeforeValidator(coerce_list) on tags with BeforeValidator(parse_tags) (parse_tags already handles list, JSON-array string, and comma-string consistently and returns [] for None — adjust to return None when empty if needed). For note_types/entity_types/categories, decide whether comma-strings are supported; if so, apply the same comma-splitting coercer so all list filters behave consistently.
Repro (failing integration test, no mocks)
This test asserts the correct behavior and fails on current main (FAILS on HEAD: AssertionError: tags='alpha,beta' param must behave like the tag: shorthand (both split commas). query_hit=True param_hit=False. (Companion test test_search_notes_tags_comma_string_matc). It was produced by an automated integration-test bug hunt and can be dropped into test-int/ as the regression test once fixed.
"""Bug hunt: search_notes internal inconsistency — the `tag:` query shorthand
splits comma-separated tags (search.py:882-884), but the `tags=` parameter does
NOT (coerce_list wraps the whole string). Same comma string, two different results
within ONE tool.
"""
import pytest
from fastmcp import Client
@pytest.mark.asyncio
async def test_tags_param_vs_tag_query_comma_consistency(mcp_server, app, test_project):
async with Client(mcp_server) as client:
# Note tagged alpha + beta
await client.call_tool(
"write_note",
{
"project": test_project.name,
"title": "Tag Shorthand Note",
"directory": "tag-shorthand",
"content": "# Tag Shorthand Note\n\nTagShorthandToken body",
"tags": ["alpha", "beta"],
},
)
# Path A: tag: query shorthand with comma list -> splits, matches
via_query = await client.call_tool(
"search_notes",
{
"project": test_project.name,
"query": "tag:alpha,beta",
"search_type": "text",
},
)
query_hit = "Tag Shorthand Note" in via_query.content[0].text
# Path B: tags= parameter with the SAME comma string
via_param = await client.call_tool(
"search_notes",
{
"project": test_project.name,
"query": "TagShorthandToken",
"search_type": "text",
"tags": "alpha,beta",
},
)
param_hit = "Tag Shorthand Note" in via_param.content[0].text
assert query_hit, "tag: query shorthand should match (sanity)"
assert param_hit == query_hit, (
"tags='alpha,beta' param must behave like the tag: shorthand "
f"(both split commas). query_hit={query_hit} param_hit={param_hit}"
)🤖 Found via automated integration-test bug hunt (Claude Code)
Activity
claude commentedon Jun 8, 2026
Claude finished @phernandez's task in 6m 41s —— View job
Triage & Fix:
search_notescomma-separated tags inconsistencyClassification: Bug · MCP Tool · Medium Priority · Simple complexity
search.py,utils.py) — confirmed root causecoerce_list→parse_tagsfortagsparametercoerce_list→coerce_comma_listfornote_types/entity_types/categoriescoerce_comma_listutility toutils.py6629a2d)buglabel to issueRoot Cause Confirmed
coerce_liston line 681 wrapped any bare string as a single-element list, sotags="alpha,beta"became["alpha,beta"]— a literal tag that matches nothing. Thetag:alpha,betashorthand parser at line 882–884 correctly called.split(","). Two code paths, one comma-string, two different outcomes.Fix Applied
src/basic_memory/utils.py— addedcoerce_comma_list:src/basic_memory/mcp/tools/search.py:tags:BeforeValidator(coerce_list)→BeforeValidator(parse_tags)— mirrors thetag:shorthand, also strips leading#note_types,entity_types,categories:BeforeValidator(coerce_list)→BeforeValidator(coerce_comma_list)— consistent comma-string handling across all list filterstests/test_coerce.py—TestCoerceCommaListunit teststest-int/mcp/test_search_integration.py— two regression tests:test_search_notes_tags_comma_string_matches_tag_query_shorthand(the exact test from the issue)test_search_notes_note_types_comma_string_splitsPush Needed
The fix is committed locally as
6629a2don branchclaude/issue-910-20260608-0212, but I was unable to push — the GitHub Actions token used in this run doesn't have write access tobasicmachines-co/basic-memory. A maintainer can push this branch manually, or re-run the workflow with the appropriate token.fix(mcp): split comma-separated tags in search_notes tags param (#932)
test(mcp): assert tags param and tag: shorthand comma equivalence
test(mcp): assert tags param and tag: shorthand comma equivalence
fix(mcp): tighten search_notes tags input and normalize for direct ca…
Merge upstream/main (v0.22.1) into fork