From 0de8e7cf2835cbb0e2f51a7d63215bdbf2ddab5d Mon Sep 17 00:00:00 2001 From: Jake Ruesink Date: Wed, 11 Nov 2026 14:21:37 -0600 Subject: [PATCH 1/3] Name creates and actions apart in dry-run notes, and document the error result From the ChatGPT regression pass on #101: the note "creates or acts on a resource" was vague. A path ending in an id with no readable GET, a collection (create), and an action now each get their own note. The README now says code is optional, spec_revision sits beside error, and failed calls are isError tool results as the MCP spec asks, with the same JSON in text and structuredContent because clients show different ones. Co-Authored-By: Claude Opus 5.5 --- apps/medusa/integration-tests/http/mcp-write.spec.ts | 10 +++++++++- packages/medusa-mcp/README.md | 8 ++++++-- packages/medusa-mcp/src/mcp/server.ts | 11 +++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/apps/medusa/integration-tests/http/mcp-write.spec.ts b/apps/medusa/integration-tests/http/mcp-write.spec.ts index 8a97b7b55..67f1004e6 100644 --- a/apps/medusa/integration-tests/http/mcp-write.spec.ts +++ b/apps/medusa/integration-tests/http/mcp-write.spec.ts @@ -232,7 +232,7 @@ medusaIntegrationTestRunner({ limits: expect.stringContaining('the real call can still be rejected'), proposed: draft, current: null, - note: expect.stringContaining('no current values'), + note: 'This creates a new resource, so no current values exist.', }); const rejected = await callTool(api, fullToken, 'write_api', { operation: 'POST /admin/products', body: draft }); @@ -280,6 +280,14 @@ medusaIntegrationTestRunner({ proposed: null, }); expect(preview.structuredContent?.limits).not.toContain('matches the published schema'); + + const action = await callTool(api, fullToken, 'write_api', { + operation: 'POST /admin/products/export', + dry_run: true, + }); + expect(action.structuredContent?.note).toBe( + 'This runs an action rather than editing fields of a resource, so there are no current values to compare.', + ); }); it('does not show current values in a dry run for a token without mcp:read', async () => { diff --git a/packages/medusa-mcp/README.md b/packages/medusa-mcp/README.md index 6f5a1d639..b2fe79701 100644 --- a/packages/medusa-mcp/README.md +++ b/packages/medusa-mcp/README.md @@ -28,8 +28,12 @@ Status: in development on `feat/medusa-mcp`. Design and plan: Arbor thread DEM-1 A dry run checks the body against the published spec only. Medusa enforces business rules in its workflows, which no spec describes: creating a product without `options` passes the schema and fails in Medusa's create workflow. So every preview says it was not executed and whether the body was checked (`schema_check`), and a failed call returns an `error` object with the phase (`schema` or `medusa`), -Medusa's `type`, `code`, and `message`, a hint for the status, and the spec revision, so an agent can correct the body -and call again. +Medusa's `type`, `code`, and `message` when Medusa sends them (`code` is often absent), and a hint for the status, so +an agent can correct the body and call again. `spec_revision` sits beside `error`, at the top of the result. + +A failed call is an MCP tool result with `isError: true`, as the MCP spec asks for execution errors, not a JSON-RPC +error. The same JSON is in `structuredContent` and in the text content, because clients differ in which one they show +the model: ChatGPT presents the result as a tool exception carrying the text. Calls run against Medusa's own API as the admin who connected, with a short-lived admin JWT, so Medusa's permissions and validators apply. A built-in blocklist (`src/mcp/policy.ts`) keeps agents away from auth, diff --git a/packages/medusa-mcp/src/mcp/server.ts b/packages/medusa-mcp/src/mcp/server.ts index 50422d942..42c674be0 100644 --- a/packages/medusa-mcp/src/mcp/server.ts +++ b/packages/medusa-mcp/src/mcp/server.ts @@ -389,9 +389,16 @@ export function buildMcpServer(registry: ApiRegistry, target: ExecutionTarget): const proposalOnly = (note: string) => ok({ ...preview, proposed: args.body ?? null, current: null, note }); const read = catalog.byKey.get(`GET ${operation.path}`); - if (!/\{[^}]+\}$/.test(operation.path) || !read || read.blocked_by) { - return proposalOnly('This operation creates or acts on a resource, so there are no current values to compare.'); + if (!/\{[^}]+\}$/.test(operation.path)) { + // A path that does not end in an id is a collection, where a write creates a new resource, or an action. + return proposalOnly( + read + ? 'This creates a new resource, so no current values exist.' + : 'This runs an action rather than editing fields of a resource, so there are no current values to compare.', + ); } + if (!read || read.blocked_by) + return proposalOnly('This resource cannot be read here, so current values are not shown.'); if (!target.scopes.includes('mcp:read')) return proposalOnly('Current values need the mcp:read scope.'); const query = declaredFor(read).query.has('fields') && fields.length ? { fields: fields.join(',') } : undefined; From 672ad7f19f6ccf01cc2ff4234ca909d8d43bc3d1 Mon Sep 17 00:00:00 2001 From: Jake Ruesink Date: Wed, 11 Nov 2026 14:29:39 -0600 Subject: [PATCH 2/3] Name the operation in dry-run notes instead of guessing what it does A GET on the same path does not prove a POST creates, and its absence does not prove an action: the variants batch endpoint creates, updates, and deletes. The note now quotes the operation's summary from the spec. The README lists the three shapes of a failed result instead of claiming they all carry the same JSON. Co-Authored-By: Claude Opus 5.5 --- apps/medusa/integration-tests/http/mcp-write.spec.ts | 4 ++-- packages/medusa-mcp/README.md | 9 +++++++-- packages/medusa-mcp/src/mcp/server.ts | 7 +++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/medusa/integration-tests/http/mcp-write.spec.ts b/apps/medusa/integration-tests/http/mcp-write.spec.ts index 67f1004e6..b796e72e6 100644 --- a/apps/medusa/integration-tests/http/mcp-write.spec.ts +++ b/apps/medusa/integration-tests/http/mcp-write.spec.ts @@ -232,7 +232,7 @@ medusaIntegrationTestRunner({ limits: expect.stringContaining('the real call can still be rejected'), proposed: draft, current: null, - note: 'This creates a new resource, so no current values exist.', + note: '"Create Product" does not target one existing resource by its path, so there are no current values to compare.', }); const rejected = await callTool(api, fullToken, 'write_api', { operation: 'POST /admin/products', body: draft }); @@ -286,7 +286,7 @@ medusaIntegrationTestRunner({ dry_run: true, }); expect(action.structuredContent?.note).toBe( - 'This runs an action rather than editing fields of a resource, so there are no current values to compare.', + '"Export Products" does not target one existing resource by its path, so there are no current values to compare.', ); }); diff --git a/packages/medusa-mcp/README.md b/packages/medusa-mcp/README.md index b2fe79701..23f768de9 100644 --- a/packages/medusa-mcp/README.md +++ b/packages/medusa-mcp/README.md @@ -32,8 +32,13 @@ Medusa's `type`, `code`, and `message` when Medusa sends them (`code` is often a an agent can correct the body and call again. `spec_revision` sits beside `error`, at the top of the result. A failed call is an MCP tool result with `isError: true`, as the MCP spec asks for execution errors, not a JSON-RPC -error. The same JSON is in `structuredContent` and in the text content, because clients differ in which one they show -the model: ChatGPT presents the result as a tool exception carrying the text. +error. ChatGPT presents such a result as a tool exception carrying the text. The result takes one of three shapes: + +| Failure | Text content | `structuredContent` | +| --- | --- | --- | +| Medusa rejected the call | The same JSON as `structuredContent` | `operation`, `status`, `body`, `error` (`phase: 'medusa'`), `spec_revision` | +| The body failed the schema | A readable list of problems | `operation`, `error` (`phase: 'schema'`, `problems`, `hint`), `spec_revision` | +| Refused before any call: unknown operation, wrong tool, blocked by policy, missing scope, rate limit, a body that is not JSON, bad path parameters | A readable message | None | Calls run against Medusa's own API as the admin who connected, with a short-lived admin JWT, so Medusa's permissions and validators apply. A built-in blocklist (`src/mcp/policy.ts`) keeps agents away from auth, diff --git a/packages/medusa-mcp/src/mcp/server.ts b/packages/medusa-mcp/src/mcp/server.ts index 42c674be0..f9114900b 100644 --- a/packages/medusa-mcp/src/mcp/server.ts +++ b/packages/medusa-mcp/src/mcp/server.ts @@ -390,11 +390,10 @@ export function buildMcpServer(registry: ApiRegistry, target: ExecutionTarget): const read = catalog.byKey.get(`GET ${operation.path}`); if (!/\{[^}]+\}$/.test(operation.path)) { - // A path that does not end in an id is a collection, where a write creates a new resource, or an action. + // The spec does not say whether a POST creates, updates, or acts, so name the operation instead of guessing. + const name = operation.summary ? `"${operation.summary}"` : 'This operation'; return proposalOnly( - read - ? 'This creates a new resource, so no current values exist.' - : 'This runs an action rather than editing fields of a resource, so there are no current values to compare.', + `${name} does not target one existing resource by its path, so there are no current values to compare.`, ); } if (!read || read.blocked_by) From 70cb1aab5c66a78a40aa48b957f350a9d46da79c Mon Sep 17 00:00:00 2001 From: Jake Ruesink Date: Wed, 11 Nov 2026 14:33:57 -0600 Subject: [PATCH 3/3] Describe the preview, not the operation, in the proposal-only note POST /admin/order-edits/{id}/request targets one order edit although its path does not end in the id, so the note now says what the preview does: current values appear only for a write to a path ending in a resource id. Co-Authored-By: Claude Opus 5.5 --- apps/medusa/integration-tests/http/mcp-write.spec.ts | 4 ++-- packages/medusa-mcp/src/mcp/server.ts | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/medusa/integration-tests/http/mcp-write.spec.ts b/apps/medusa/integration-tests/http/mcp-write.spec.ts index b796e72e6..718e4ac34 100644 --- a/apps/medusa/integration-tests/http/mcp-write.spec.ts +++ b/apps/medusa/integration-tests/http/mcp-write.spec.ts @@ -232,7 +232,7 @@ medusaIntegrationTestRunner({ limits: expect.stringContaining('the real call can still be rejected'), proposed: draft, current: null, - note: '"Create Product" does not target one existing resource by its path, so there are no current values to compare.', + note: '"Create Product": current values are shown only for a write to a path that ends in a resource id, so only the proposal is shown.', }); const rejected = await callTool(api, fullToken, 'write_api', { operation: 'POST /admin/products', body: draft }); @@ -286,7 +286,7 @@ medusaIntegrationTestRunner({ dry_run: true, }); expect(action.structuredContent?.note).toBe( - '"Export Products" does not target one existing resource by its path, so there are no current values to compare.', + '"Export Products": current values are shown only for a write to a path that ends in a resource id, so only the proposal is shown.', ); }); diff --git a/packages/medusa-mcp/src/mcp/server.ts b/packages/medusa-mcp/src/mcp/server.ts index f9114900b..6a820525b 100644 --- a/packages/medusa-mcp/src/mcp/server.ts +++ b/packages/medusa-mcp/src/mcp/server.ts @@ -390,10 +390,11 @@ export function buildMcpServer(registry: ApiRegistry, target: ExecutionTarget): const read = catalog.byKey.get(`GET ${operation.path}`); if (!/\{[^}]+\}$/.test(operation.path)) { - // The spec does not say whether a POST creates, updates, or acts, so name the operation instead of guessing. + // The spec does not say whether a POST creates, updates, or acts, so the note names the operation and states what + // the preview does rather than guessing what the call will do. const name = operation.summary ? `"${operation.summary}"` : 'This operation'; return proposalOnly( - `${name} does not target one existing resource by its path, so there are no current values to compare.`, + `${name}: current values are shown only for a write to a path that ends in a resource id, so only the proposal is shown.`, ); } if (!read || read.blocked_by)