Skip to content

fix(mcp): search content_list by q - #752

Open
edrpls wants to merge 1 commit into
emdash-cms:mainfrom
edrpls:fix/content-list-search
Open

edrpls wants to merge 1 commit into
emdash-cms:mainfrom
edrpls:fix/content-list-search

Conversation

@edrpls

@edrpls edrpls commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

The MCP content_list tool can't search. To find an entry in a large collection, an agent has to page through all of it and filter the results itself. The REST list (?q=, #1226) and the admin can both search on the server.

This adds a q parameter to content_list:

  • It is passed to handleContentList, so it runs the same search the REST list uses: title or name, slug, and searchable fields; word prefixes on collections with search enabled.
  • It uses the same schema as the REST contentListQuery.q (trimmed, 1–200 characters), so a blank q is rejected rather than quietly listing everything.
  • The draft scoping is unchanged: a caller who can't read drafts still only sees published entries.

Rebased and narrowed (2026-10-06). This branch was 884 commits behind main. It used to also move ContentPickerModal to server-side search, but main now does that already (it landed with #1928), so that half is dropped. The old branch and its review history are in the earlier commits on this PR.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes. Scope verified: tsgo --noEmit for packages/core, after building its workspace dependencies. The repo-wide script was not run locally.
  • pnpm lint passes. Scope verified: oxlint --type-aware --deny-warnings on the touched files.
  • pnpm test passes (or targeted tests for my change). tests/integration/mcp/content-misc.test.ts: 35/35.
  • pnpm format has been run (oxfmt on the touched files)
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). No admin strings changed.
  • I have added and reviewed the user-facing changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/...
  • I have included screenshots below if this PR changes the UI

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 5.5 (Claude Code)

Screenshots / test output

Not applicable (no UI change).

There are two integration tests in content-misc.test.ts:

  • q filters the list;
  • a blank q is an error, matching REST.

Both fail with the server.ts change reverted: the MCP SDK drops the unknown q, so test 1 gets every post back and test 2 gets no error.

@changeset-bot

changeset-bot Bot commented Apr 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c3bfba9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/plugin-test Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
create-emdash Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 1,912 lines across 29 files. Large PRs are harder to review and more likely to be closed without review.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@github-actions

Copy link
Copy Markdown
Contributor

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
packages/admin/src/locales/ar/messages.po Localization changed, will be marked as complete.
packages/admin/src/locales/de/messages.po Localization changed, will be marked as complete.
packages/admin/src/locales/en/messages.po Source changed, localizations will be marked as outdated.
packages/admin/src/locales/es-419/messages.po Localization changed, will be marked as complete.
packages/admin/src/locales/eu/messages.po Localization changed, will be marked as complete.
packages/admin/src/locales/fa/messages.po Localization changed, will be marked as complete.
packages/admin/src/locales/fr/messages.po Localization changed, will be marked as complete.
packages/admin/src/locales/ja/messages.po Localization changed, will be marked as complete.
packages/admin/src/locales/ko/messages.po Localization changed, will be marked as complete.
packages/admin/src/locales/pseudo/messages.po Localization changed, will be marked as complete.
packages/admin/src/locales/pt-BR/messages.po Localization changed, will be marked as complete.
packages/admin/src/locales/zh-CN/messages.po Localization changed, will be marked as complete.
packages/admin/src/locales/zh-TW/messages.po Localization changed, will be marked as complete.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@pkg-pr-new

pkg-pr-new Bot commented Apr 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@752

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@752

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@752

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@752

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@752

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@752

emdash

npm i https://pkg.pr.new/emdash@752

create-emdash

npm i https://pkg.pr.new/create-emdash@752

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@752

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@752

@emdash-cms/plugin-test

npm i https://pkg.pr.new/@emdash-cms/plugin-test@752

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@752

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@752

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@752

@emdash-cms/registry-loader

npm i https://pkg.pr.new/@emdash-cms/registry-loader@752

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/@emdash-cms/registry-moderation@752

@emdash-cms/registry-verification

npm i https://pkg.pr.new/@emdash-cms/registry-verification@752

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@752

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@752

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@752

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@752

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@752

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@752

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@752

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@752

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@752

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@752

commit: c3bfba9

@github-actions

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

This PR has been inactive for 14 days. It will be closed automatically in 7 days if there is no further activity.

If you're still working on this, please push an update or leave a comment.

@edrpls

edrpls commented May 16, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on upstream main (f28eb7b). Resolved orthogonal conflicts with #750 (sort headers, since merged) — <ContentList> now takes both sort/onSortChange and searchQuery/onSearchChange props; router threads sort + debounced search through the same TanStack Query key; fetchContentList accepts both orderBy/order and q; describe("orderBy"), describe("search"), and describe("sortable headers") test blocks coexist. Locale .po files reset to upstream for Lunaria re-extraction.

Local test runs after rebase, on top of f28eb7b:

  • packages/core/tests/database/repositories/content.test.ts: 51/51 pass (includes 6 new search tests)
  • packages/core/tests/unit/api/content-handlers.test.ts: 33/33 pass
  • packages/admin/tests/components/ContentList.test.tsx: 38/38 pass

Bumping out of stale-warning territory.

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right fix for a real bug. Moving the content picker and MCP content_list to the server-side q search introduced in #1226 is the correct architecture, and the implementation fits EmDash's patterns. The picker now uses useInfiniteQuery with keepPreviousData to avoid flashing empty lists between keystrokes, and it correctly keeps the load-more button available while searching. The MCP tool exposes q and passes it through to the handler layer, reusing the same SQL-safe repository path as the REST route.

I checked the picker refactor, the MCP schema and tool wiring, the new MCP integration test, the underlying handleContentList/ContentRepository.findMany search implementation, and the current ContentList component. The four findings from the prior review are addressed: the three ContentList issues (trusting the server total in search mode, keeping the search input visible, and showing a "no results" state instead of the empty-collection prompt for zero-result searches) are already fixed on this branch, and this PR fixes the picker's load-more-during-search issue.

Headline conclusion: The PR is clean and ready to land after addressing two minor nits — an MCP schema inconsistency and a test organization issue. No blocking logic, security, or convention problems.

Comment thread packages/core/src/mcp/server.ts Resolved
@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Jul 20, 2026
edrpls added a commit to edrpls/emdash that referenced this pull request Jul 20, 2026
…h test

Address review feedback on emdash-cms#752:

- MCP `content_list` `q` now uses `.trim().min(1).max(200)`, matching the
  REST `contentListQuery` contract. It previously accepted empty/whitespace
  `q` and silently ignored it; it now rejects it, so the MCP and REST
  interfaces accept and reject the same inputs.
- Move the `content_list` search test out of the unrelated
  "soft-delete visibility" describe into a dedicated "content_list search"
  block.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@edrpls

edrpls commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged current main (36e9e66) — the branch was 2 commits behind after the last sync.

On the two red E2E checks from the previous run: they're the invite-flow spec (user appears in the users list — [email protected] not visible within 15s), which this PR cannot plausibly affect. The diff against main is 4 files — ContentPickerModal.tsx, mcp/server.ts, the MCP test, and the changeset — and touches nothing in the users, invite, or auth path. Main's own CI is green on 11 of its last 12 runs, and the same E2E suite passes on my other open PRs, so this reads as a flaky/timing failure rather than a regression. I don't have rerun rights on the repo, so this merge doubles as a fresh CI trigger — if the shard goes green on this run that settles it.

Local verification on the merged head: full packages/core suite green (5094 passing), MCP integration suite 321 passing, lint and typecheck clean for both emdash and @emdash-cms/admin.

edrpls added a commit to edrpls/emdash that referenced this pull request Aug 8, 2026
…h test

Address review feedback on emdash-cms#752:

- MCP `content_list` `q` now uses `.trim().min(1).max(200)`, matching the
  REST `contentListQuery` contract. It previously accepted empty/whitespace
  `q` and silently ignored it; it now rejects it, so the MCP and REST
  interfaces accept and reject the same inputs.
- Move the `content_list` search test out of the unrelated
  "soft-delete visibility" describe into a dedicated "content_list search"
  block.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@edrpls
edrpls force-pushed the fix/content-list-search branch from 36e9e66 to 02e5c05 Compare August 8, 2026 14:14
@edrpls

edrpls commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@ascorbic gentle ping on this one — it's been open since April and is in a ready state: rebased onto current main, CI fully green, both emdashbot review passes addressed (the second concluded "clean and ready to land after two nits", and those nits landed with regression tests). Zero unresolved threads.

If you'd rather route it through the bot first, I can't apply bot:review myself (no label permissions) — reapplying it would kick a fresh pass. Happy to rebase again if it drifts before you get to it.

@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Aug 12, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right fix for a real bug. Moving ContentPickerModal and the MCP content_list tool onto the server-side ?q= search introduced in #1226 is the correct architecture for large collections, and the implementation follows EmDash’s existing patterns.

I checked the picker refactor, the MCP tool/schema wiring, the new MCP integration tests, the underlying handleContentList/ContentRepository search path, and the REST contentListQuery schema. The four ContentList issues from the prior review remain resolved on this branch, and the previous MCP schema inconsistency is now fixed: the MCP q shape matches the REST schema exactly (z.string().trim().min(1).max(200).optional()).

Headline conclusion: the PR is clean and nearly ready to land. There are a couple of remaining low-grade nits — one stale test-file header and an explanatory JSX comment that violates the comment-discipline convention — plus a minor UX inconsistency in the picker empty state. None of these are blockers.


Findings

  • [suggestion] packages/admin/src/components/ContentPickerModal.tsx:203

    This JSX comment narrates the change rather than explaining non-obvious code. AGENTS.md says comments must not be PR/reviewer-facing narrative; the hasNextPage && condition already expresses that load-more stays available. Remove it.

    							{hasNextPage && (
    
  • [suggestion] packages/admin/src/components/ContentPickerModal.tsx:156

    The empty-state uses the raw searchQuery to decide whether to show the search-specific prompt. Because searchParam falls back to undefined when the input is whitespace-only, a user typing only spaces sees "Try adjusting your search" even though the server is not actually filtering. Use the effective search term instead.

    						{searchParam ? (
    
  • [suggestion] packages/core/tests/integration/mcp/content-misc.test.ts:2

    The file header no longer matches the file contents: the new content_list search describe block is not listed. Update the docblock so future readers know this file covers the content_list q parameter.

    /**
     * MCP content tools — coverage for the remaining tools and edges.
     *
     * Covers:
     *   - content_duplicate
     *   - content_permanent_delete
     *   - content_translations + locale handling on create/get
     *   - _rev optimistic concurrency (happy + race)
     *   - Soft-delete visibility (content_get / content_list filtering)
     *   - content_list search by `q`
     *   - Edit-while-trashed
     *   - Idempotency (publish twice, unpublish-on-draft, schedule + publish)
     */
    

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Aug 12, 2026
@edrpls

edrpls commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

All three findings from the fresh review pass are addressed in 12f892e:

  • Picker empty-state now gates on the effective searchParam — a whitespace-only query no longer claims a search is filtering.
  • Narrative JSX comment above the load-more condition removed.
  • MCP test header now lists the content_list search-by-q coverage.

Verified locally: lint clean, MCP suite 29/29, full admin browser suite 1363/1363.

@edrpls
edrpls force-pushed the fix/content-list-search branch from 12f892e to 822fd3f Compare August 16, 2026 06:46
edrpls added a commit to edrpls/emdash that referenced this pull request Aug 16, 2026
…h test

Address review feedback on emdash-cms#752:

- MCP `content_list` `q` now uses `.trim().min(1).max(200)`, matching the
  REST `contentListQuery` contract. It previously accepted empty/whitespace
  `q` and silently ignored it; it now rejects it, so the MCP and REST
  interfaces accept and reject the same inputs.
- Move the `content_list` search test out of the unrelated
  "soft-delete visibility" describe into a dedicated "content_list search"
  block.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@edrpls
edrpls force-pushed the fix/content-list-search branch from 822fd3f to 3b98339 Compare August 16, 2026 07:12
@github-actions github-actions Bot added stale and removed stale labels Aug 30, 2026
@github-actions github-actions Bot added stale and removed stale labels Sep 14, 2026
The MCP `content_list` tool had no search, so an agent looking for an
entry in a large collection had to page through all of it and filter the
results itself. It now takes `q`, passed to `handleContentList` like the
REST list's `?q=`, with the same schema (trimmed, 1-200 characters), so a
blank `q` is rejected rather than listing everything.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@edrpls
edrpls force-pushed the fix/content-list-search branch from 3b98339 to c3bfba9 Compare October 6, 2026 05:34
@edrpls edrpls changed the title fix(admin): extend server-side content search to the content picker and MCP fix(mcp): search content_list by q Oct 6, 2026
@edrpls

edrpls commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and narrowed. main's ContentPickerModal already searches on the server (it landed with #1928), so this PR is now just the MCP half: content_list gains q, with the same schema and the same search as the REST list's ?q=. I've updated the title and description to match. Two integration tests fail without the change; 35/35 pass with it.

@github-actions github-actions Bot added review/needs-review No maintainer or bot review yet and removed needs-rebase review/needs-rereview New commits since the last review labels Oct 6, 2026
@swissky swissky added the bot:review Trigger an emdashbot code review on this PR label Nov 5, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach is right. The PR is narrowed to the MCP half: content_list now accepts q and passes it to handleContentList, so MCP reuses the REST search path. Draft scoping is preserved and the MCP q schema matches the REST contract. The new integration tests cover both filtering and blank-q rejection. The earlier schema, test-grouping and header concerns are resolved, and the picker findings are out of scope for the narrowed diff. One issue remains, raised by only one reviewer: the new q description promises word-prefix matching more broadly than the implementation supports. The other reviewer did not raise it, but did not disagree with it either.


Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol.

.optional()
.describe(
"Search the collection's title or name, slug, and searchable fields. Case-insensitive; collections with search enabled match word prefixes.",
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] The new tool description says collections with search enabled match word prefixes, but enabling search is not sufficient. canUseFtsForListFilter() in api/handlers/content.ts returns false on PostgreSQL, when the index is missing, or when it does not cover the display columns; those paths use substring matching instead. This description is exposed to MCP clients as the search contract, so agents can incorrectly assume prefix-only results on supported configurations. Qualify the prefix behavior, for example: “Case-insensitive substring search, or word-prefix matching when an eligible SQLite FTS5 index is available.” (Raised by openai/gpt-6.1-sol; anthropic/claude-opus-5-5 did not mention it.)

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Nov 5, 2026
@danielmlr danielmlr removed the overlap label Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants