Skip to content

[6.x] Refresh records built from project config between operations - #20583

Merged
brandonkelly merged 1 commit into
6.xfrom
rias/cms-2657-6x-stdio-mcp-server-doesnt-see-project-config
Nov 13, 2026
Merged

brandonkelly merged 1 commit into
6.xfrom
rias/cms-2657-6x-stdio-mcp-server-doesnt-see-project-config

Conversation

@riasvdv

@riasvdv riasvdv commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

#20641 made long-lived processes (Octane workers and the stdio MCP server) reload the project config before each operation. The services that hold records built from it still kept what they had loaded, so configuration_get returned stale records. The revision came from the fresh project config, so an update with a current expectedRevision passed and saved the stale values over changes made in the control panel or CLI.

PrepareCraftForNextOperation::prepare() now refreshes those services as well:

 PrepareCraftForNextOperation::prepare()
   ProjectConfig::reset()
+  Fields::refreshFields()
+  EntryTypes::refreshEntryTypes()
+  Volumes::reset()
+  SiteGroups::refreshGroups()
+  ImageTransforms::reset()
   Cms::setDefaultTimezone()
   ProjectConfigRoutes::refresh()

Sections, sites, and routes are already scoped or refreshed.

Evidence

New test in tests/Feature/Mcp/StdioTest.php:

serve: create field → get → (another process sets its instructions) → get → update name
expect second get shows the outside instructions
expect update succeeds and keeps the outside instructions
  • Before (6.x): Failed asserting that null is identical to 'Changed elsewhere', and the update saved instructions: null.
    After: passes. Also passing: tests/Feature/Mcp (370), OctaneWorkerTest, and composer ci.

Before this rebase, a real craft:mcp:serve process with craft:project-config:set run between messages also showed stale entry types, site groups, and volumes.

Related issues

@linear-code

linear-code Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

CMS-2657

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

📚 Storybook previews

@craftcms/ui — open Storybook

No changed components detected in this Storybook.

resources/js — open Storybook

No changed components detected in this Storybook.

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the changes that refresh project configuration between stdio requests.

No open issues 🎉

What changed in this PR

Refreshes project-config state between requests in long-running stdio MCP sessions, addressing the stale reads, overwritten external changes, and persistent write failures reported in #20568.

Changes:

  • Clears facade and once() caches, resets loaded project config, and refreshes cached configuration records for each request.
  • Adds a regression test that simulates external changes between messages and checks fresh values, updated revisions, and preservation of those changes when saving.
File Description
tests/​Feature/​Mcp/​StdioTest.php Adds between-message change simulation and assertions for configuration freshness and safe updates.
src/​Mcp/​StdioEventDispatcher.php Resets request-local state and configuration caches before processing each stdio request.

Review effort: Balanced

Long-lived processes, such as Octane workers and the stdio MCP server,
already reload the project config before each operation, but the
fields, entry types, volumes, site groups, and image transforms
services kept the records they had loaded. The stdio MCP server then
returned stale records, and an update with a current expectedRevision
saved those stale values over changes made in the control panel or CLI.

PrepareCraftForNextOperation now refreshes those services too.

Fixes #20568

Amp-Thread-ID: https://ampcode.com/threads/T-01a1c684-2755-73e3-9764-31efd573c59b
Co-authored-by: Amp <amp@ampcode.com>
@riasvdv
riasvdv force-pushed the rias/cms-2657-6x-stdio-mcp-server-doesnt-see-project-config branch from 762f4be to d8682ce Compare November 12, 2026 21:06
@riasvdv riasvdv changed the title [6.x] Reload project config state for each stdio MCP request [6.x] Refresh records built from project config between operations Nov 12, 2026
@brandonkelly
brandonkelly merged commit 3835006 into 6.x Nov 13, 2026
22 checks passed
@brandonkelly
brandonkelly deleted the rias/cms-2657-6x-stdio-mcp-server-doesnt-see-project-config branch November 13, 2026 05:16
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.

3 participants