Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix: a write answered without the record it changed

Damian Legawiecdd4ada2d0f48
diff --git a/spree/mcp/lib/spree/mcp/tool_adapter.rb b/spree/mcp/lib/spree/mcp/tool_adapter.rb
index 8a9924e2aa..0ca43188a0 100644
--- a/spree/mcp/lib/spree/mcp/tool_adapter.rb
+++ b/spree/mcp/lib/spree/mcp/tool_adapter.rb
@@ -129,20 +129,14 @@ module Spree
return result.to_s unless result.is_a?(Hash)
summary = result[:summary].presence
- return "#{summary}\n#{JSON.generate(result)}" if summary && record_list?(result)
- return summary if summary
+ return JSON.generate(result) if summary.nil?
+ # The summary alone says what was done but not what it did it to,
+ # so a write answered "Orders cancel R1002" and the model had to
+ # fetch the order again to report the new status. Every other key
+ # travels with it.
+ return summary if result.keys == [:summary]
- JSON.generate(result)
- end
-
- # A page of records the caller can fetch individually.
- #
- # Only `records` counts. A report's rows look similar but are
- # computed figures that exist nowhere else — summarising them as
- # "returned 2 results" hands the model a row count where it asked
- # for the numbers.
- def record_list?(result)
- result.key?(:records)
+ "#{summary}\n#{JSON.generate(result)}"
end
end
end
diff --git a/spree/mcp/spec/requests/spree/api/v3/admin/mcp_spec.rb b/spree/mcp/spec/requests/spree/api/v3/admin/mcp_spec.rb
index 55d154d30f..c3c6863220 100644
--- a/spree/mcp/spec/requests/spree/api/v3/admin/mcp_spec.rb
+++ b/spree/mcp/spec/requests/spree/api/v3/admin/mcp_spec.rb
@@ -295,6 +295,20 @@ RSpec.describe 'Admin MCP endpoint', type: :request do
let(:order) { create(:completed_order_with_totals, store: store) }
let(:fulfillment) { order.shipments.first }
+ # A write used to answer with its summary line alone — "Orders cancel
+ # R1002" — so a model had to fetch the record again to report what
+ # changed, and an assistant reading only the text could not confirm the
+ # write at all.
+ it 'answers a write with the record it changed' do
+ body = post_rpc('tools/call',
+ { name: 'orders_cancel', arguments: { 'order' => order.prefixed_id } },
+ headers: { 'Authorization' => "Bearer #{token}" })
+
+ expect(body.dig('result', 'isError')).to be(false)
+ expect(body.dig('result', 'structuredContent', 'record', 'status')).to eq('canceled')
+ expect(body.dig('result', 'content', 0, 'text')).to include('canceled')
+ end
+
it 'marks a fulfillment delivered through the real workflow' do
fulfillment.update!(status: 'fulfilled')