Security · Advanced
How to Safely Give an MCP Server Permission to Refund Shopify Orders

A refund is a financial side effect. Treat it as a controlled operation with narrow inputs, server-side policy checks, explicit approval, and an audit trail—not as a general-purpose command an AI assistant can freely invoke.
Connecting an MCP (Model Context Protocol) server to Shopify can make order support dramatically faster. An AI assistant can locate an order, explain its payment state, identify eligible items, and prepare a refund request. The dangerous design is letting that same assistant hold a broadly privileged Shopify token and call a refund endpoint whenever a prompt appears to justify it.
This guide builds a safer model around four boundaries:
- read-only order and payment inspection by default;
- server-side limits that the model cannot override;
- human approval for every risky refund operation; and
- structured audit events for requests, decisions, execution, and failures.
The examples are implementation patterns, not claims about a particular Shopify store, MCP implementation, employee directory, or production result. Replace the placeholder values with your own configuration and verify the behavior in a non-production environment before enabling any write operation.
1. Define the threat model before defining tools
The first mistake is to begin with a tool named refund_order. Begin with the business action and its failure modes.
What must be protected?
- Money: the refund amount must not exceed the amount allowed by your policy or the amount actually refundable.
- Customer data: order lookup should disclose only the fields needed for the support task.
- Employee authority: an assistant must not turn a support employee’s conversational request into manager-level approval.
- Operational integrity: a repeated request must not create duplicate refunds.
- Evidence: the organization must be able to reconstruct who requested, approved, attempted, and completed the action.
Assume the model can be wrong
Prompt instructions are not an authorization system. A model can misunderstand an order, follow malicious text embedded in an order note, select the wrong line item, or produce a plausible explanation for an action that policy should reject. The server must make the final authorization and validation decisions using trusted request context and Shopify’s current state.
Also assume that a user may ask for an action that is outside their role, that a tool call may be replayed, and that a downstream API may return a partial or ambiguous failure. The design should remain safe when the model is helpful but mistaken, not only when it is malicious.
2. Use capability separation instead of one powerful tool
Give the assistant a small set of capabilities. A useful split is:
| Capability | Purpose | Default permission | Side effect |
|---|---|---|---|
orders.search |
Find candidate orders using narrowly scoped fields | Support staff | None |
orders.get_summary |
Return payment, fulfillment, and refund state | Support staff | None |
refunds.quote |
Calculate an eligible refund and explain policy decisions | Support staff | None |
refunds.request |
Create a pending approval request | Support staff | Creates an internal record |
refunds.approve |
Approve a pending request | Authorized approver | Changes approval state |
refunds.execute |
Submit the approved refund to Shopify | Dedicated service identity | Financial side effect |
Do not expose refunds.execute as a general conversational tool. In a stronger design, the assistant can create a request, while a separate approval interface or workflow authorizes it. Execution then happens only after the server verifies that the approval is valid, current, tied to the exact request, and made by an eligible employee.
Why a quote tool matters
A quote operation creates a safe intermediate state. It can return:
{
"order_id": "gid://shopify/Order/EXAMPLE",
"currency": "USD",
"requested_lines": [
{
"line_item_id": "gid://shopify/LineItem/EXAMPLE",
"quantity": 1
}
],
"eligible_amount": "25.00",
"shipping_refund_allowed": false,
"reason_codes": ["ITEM_FULFILLED", "WITHIN_POLICY_WINDOW"],
"requires_approval": true,
"quote_expires_at": "2026-11-24T12:00:00Z"
}
These values are illustrative. The server should calculate them from current Shopify data and your policy, not accept them as facts supplied by the model.
3. Bind every request to a real employee identity
The MCP connection needs two distinct identities:
- The human identity that initiated or approved the action.
- The server or service identity that calls Shopify.
Do not use the service identity as a substitute for the employee. It is an execution credential, not proof that the employee was authorized. Carry a verified identity context into every tool call:
{
"actor": {
"employee_id": "employee-example",
"role": "support_agent",
"authentication_method": "enterprise_sso",
"session_id": "session-example"
},
"request_context": {
"conversation_id": "conversation-example",
"client": "internal-support-console"
}
}
This is a data-shape example. In a real system, populate the identity from a trusted authenticated session or gateway. Never let the model provide or change employee_id, role, or approval attributes in ordinary tool arguments.
Map roles to capabilities server-side
A policy can be represented as configuration, code, or a policy engine. The important property is that it is evaluated by the MCP server or an authorization service:
{
"roles": {
"support_agent": {
"allow": [
"orders.search",
"orders.get_summary",
"refunds.quote",
"refunds.request"
],
"approval_limit": "0.00"
},
"support_lead": {
"allow": [
"orders.search",
"orders.get_summary",
"refunds.quote",
"refunds.request",
"refunds.approve"
],
"approval_limit": "500.00"
},
"refund_service": {
"allow": [
"refunds.execute"
],
"machine_identity_only": true
}
}
}
Do not treat this sample as a universal policy. The appropriate roles, amounts, currencies, and approval rules depend on your organization. A useful default is that the employee who requests a refund cannot approve the same request, and the execution identity cannot approve anything.
4. Put non-negotiable limits on the server
Server-side validation is the control that remains in force even when the model supplies unexpected arguments. Validate every field against current state and policy.
Validate the order and line items
- Accept a canonical Shopify order identifier, not an ambiguous display name.
- Load the order from Shopify immediately before creating the quote.
- Confirm that each requested line item belongs to that order.
- Reject quantities greater than the remaining refundable quantity.
- Do not trust a price, tax amount, shipping amount, or currency supplied by the model.
- Reject orders in states your refund policy excludes.
Validate the amount
Calculate the amount from authoritative order and transaction data. Then apply a policy ceiling. For example:
eligible_amount =
min(
remaining_refundable_amount,
policy_maximum_for_actor,
policy_maximum_for_currency
)
Use decimal arithmetic suitable for money. Do not use binary floating-point arithmetic for currency calculations. If the requested amount differs from the server-calculated amount, stop and require the employee to review a new quote.
Validate time and freshness
Quotes and approvals should expire. A short validity period reduces the chance that an approval created for one order state is reused after the order changes. At execution time, re-read the relevant Shopify state and compare it with the approved snapshot or version.
Use an allowlist for refund reasons
Free-form explanations are useful for notes, but they should not determine policy. Store a controlled reason code such as DAMAGED_ITEM, DUPLICATE_CHARGE, or CUSTOMER_GOODWILL, then optionally store a separate human-readable note. Validate the reason code against the employee’s allowed reasons and any documentation requirements.
5. Make approval an explicit state transition
Approval should not be a phrase in a chat transcript. It should be a signed or otherwise authenticated decision over an immutable request.
A minimal state machine is:
QUOTED
-> PENDING_APPROVAL
-> APPROVED
-> EXECUTING
-> SUCCEEDED
PENDING_APPROVAL -> REJECTED
PENDING_APPROVAL -> EXPIRED
APPROVED -> CANCELLED
EXECUTING -> UNKNOWN_OUTCOME
UNKNOWN_OUTCOME is important. If the connection fails after Shopify may have accepted the refund, do not blindly retry. Mark the operation for reconciliation and query Shopify using the provider’s identifiers or transaction state.
Approval record
Store the exact decision context:
{
"refund_request_id": "refund-request-example",
"order_id": "gid://shopify/Order/EXAMPLE",
"quote_hash": "sha256-example",
"amount": "25.00",
"currency": "USD",
"reason_code": "DAMAGED_ITEM",
"requested_by": "employee-requester-example",
"approved_by": "employee-approver-example",
"approved_at": "2026-11-24T11:00:00Z",
"expires_at": "2026-11-24T12:00:00Z",
"decision": "approved"
}
The hash should cover the canonicalized request fields that matter to the decision. At execution, recompute the hash and reject the operation if the order, lines, quantity, amount, currency, or reason changed.
Prevent self-approval
Compare immutable employee identifiers, not display names or email strings typed into a prompt. If delegated approval is supported, represent the delegation in a trusted directory or policy system and log which delegation rule was used.
6. Scope the Shopify credential and the MCP exposure separately
There are two permission layers:
- What the MCP server exposes to the assistant.
- What the server’s Shopify credential can do downstream.
Both must be narrow. Hiding a tool from the model is not sufficient if the server accepts arbitrary operations or if the credential has unrelated administrative permissions.
Create a dedicated Shopify app or integration identity for this workflow where the platform and your operating model support it. Grant only the scopes required for order inspection and the approved refund path. Keep read and write credentials distinct when practical. Store credentials in a secrets manager, rotate them, and do not place them in prompts, source files, logs, or tool results.
The exact Shopify scopes and API mutations vary by API version, app type, store configuration, and refund workflow. Consult the Shopify documentation for the version you use and verify the effective permissions in the target store. This article does not assert a particular scope name or mutation shape.
7. Design tool contracts that make unsafe calls difficult
A tool schema should express the narrowest useful operation. For example, a request tool might accept:
{
"name": "refunds.request",
"description": "Create a pending refund request for an eligible Shopify order. Does not send a refund.",
"inputSchema": {
"type": "object",
"additionalProperties": false,
"required": ["order_id", "line_items", "reason_code", "customer_note"],
"properties": {
"order_id": {
"type": "string",
"description": "Canonical Shopify order ID"
},
"line_items": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"additionalProperties": false,
"required": ["line_item_id", "quantity"],
"properties": {
"line_item_id": {"type": "string"},
"quantity": {"type": "integer", "minimum": 1}
}
}
},
"reason_code": {
"type": "string",
"enum": ["DAMAGED_ITEM", "DUPLICATE_CHARGE", "CUSTOMER_GOODWILL"]
},
"customer_note": {
"type": "string",
"maxLength": 1000
}
}
}
}
The description says “does not send a refund” because tool descriptions influence model behavior. That text is helpful, but it is not a security boundary. The handler must enforce the same rule.
For the execution tool, avoid exposing arbitrary amount fields if the amount can be derived from an approved request:
{
"name": "refunds.execute",
"description": "Execute an already approved refund request. Rejects unapproved, changed, expired, or duplicate requests.",
"inputSchema": {
"type": "object",
"additionalProperties": false,
"required": ["refund_request_id"],
"properties": {
"refund_request_id": {
"type": "string"
}
}
}
}
The server should load the request, verify authorization, re-check Shopify state, enforce idempotency, and derive the final operation from the stored approved data.
8. Make retries safe
Network retries are normal. A refund endpoint that treats every retry as a new financial action is not safe.
Use an idempotency key that is generated by the server and stored with the refund request. The key should be stable for one approved operation and never reused for a different order or amount:
idempotency_key =
"refund:" + refund_request_id + ":" + approved_quote_hash
Before calling Shopify:
- Lock or atomically claim the refund request.
- Check whether this idempotency key already has a completed result.
- Check whether another worker is executing the same request.
- Call Shopify with the stored key if the API supports idempotency for the operation.
- Persist the provider response and internal outcome.
If the provider does not offer idempotency for your exact operation, use a reconciliation record and a state lock. Do not claim that a timeout means the refund failed.
9. Log enough to investigate without leaking secrets
Audit logs should answer five questions:
- Who requested the action?
- What order, lines, amount, currency, and reason were evaluated?
- Who approved or rejected the exact request?
- Which service identity attempted execution, and when?
- What did Shopify return, and how was the outcome reconciled?
Use structured events with correlation identifiers:
{
"event": "refund.execution.completed",
"timestamp": "2026-11-24T11:04:00Z",
"refund_request_id": "refund-request-example",
"order_id": "gid://shopify/Order/EXAMPLE",
"actor_id": "employee-requester-example",
"approver_id": "employee-approver-example",
"service_identity": "shopify-refund-service",
"amount": "25.00",
"currency": "USD",
"provider_reference": "provider-reference-example",
"outcome": "succeeded",
"request_correlation_id": "correlation-example"
}
Do not log access tokens, authorization headers, full payment details, unnecessary customer addresses, or complete conversation transcripts by default. Define retention, access, and redaction rules for the audit store. An audit record should be useful to an investigator without becoming a second source of sensitive customer data.
10. Reference request flow
A safe conversational flow can look like this:
- The employee asks the assistant to inspect an order.
- The assistant calls
orders.searchororders.get_summary. - The employee identifies the intended order and refund reason.
- The assistant calls
refunds.quote. - The server returns the calculated amount, affected items, policy result, and approval requirement.
- The employee confirms that the quote is correct.
- The assistant calls
refunds.request, creating a pending request. - An eligible approver reviews the request outside the model’s authority boundary.
- The server records the approval and makes the request executable.
- A controlled worker calls
refunds.executewith only the request ID. - The worker records success, failure, or unknown outcome and triggers reconciliation when needed.
The employee’s conversational confirmation in step 6 is useful for avoiding misunderstandings, but it is not the approval in step 8 unless your organization has explicitly designed and authenticated it as such. Keeping those concepts separate prevents “the user said yes” from becoming an accidental bypass.
11. Reproducible implementation checklist
Use this sequence when implementing the model in a test environment:
- Document the refund policy: eligible states, reasons, limits, currencies, approval roles, and expiry.
- Create separate read, request, approval, and execution capabilities.
- Authenticate the human at the gateway and pass trusted identity context to the server.
- Define schemas with closed objects, required fields, bounded strings, bounded quantities, and reason-code allowlists.
- Implement quote calculation from current Shopify data using decimal money arithmetic.
- Implement server-side authorization for every tool, including execution.
- Create a durable refund-request record with an immutable quote snapshot or hash.
- Require a distinct eligible approver and prevent self-approval.
- Expire quotes and approvals.
- Re-read order state immediately before execution.
- Add idempotency and an explicit unknown-outcome state.
- Emit redacted audit events for every state transition.
- Use a dedicated, least-privileged Shopify integration identity.
- Test denied calls, changed orders, duplicate calls, expired approvals, and provider timeouts.
12. Verification: prove the boundaries, not just the happy path
Before production access, run a test matrix using test orders and non-production credentials. Record observed results; do not infer them from tool descriptions.
| Test | Expected safety property |
|---|---|
Support agent calls refunds.execute directly |
Denied before any Shopify write |
| Model supplies a larger amount than the quote | Amount is ignored or rejected; no enlarged refund is sent |
| Approval is made by the requester | Approval is rejected |
| Approval is expired | Execution is rejected and a new quote is required |
| Order state changes after approval | Execution is rejected or re-quoted |
| Same request is submitted twice | At most one provider operation is created |
| Provider response times out | Outcome becomes unknown; automatic blind retry is prevented |
| Order note contains instructions to ignore policy | Note is treated as untrusted data, not as authorization |
| Credential lacks the required Shopify permission | Failure is captured without exposing secrets or falsely reporting success |
For each case, verify both the external effect and the internal evidence: authorization decision, tool handler result, stored state transition, audit event, and any Shopify reference. A test that only checks the assistant’s text is insufficient.
13. Failure cases and operational responses
“The assistant says it refunded the order, but no refund exists”
Treat the assistant’s response as untrusted presentation. Read the durable execution record and reconcile with Shopify. The user-facing status should distinguish “not attempted,” “rejected,” “failed,” and “unknown outcome.” Never mark a refund successful because the model generated a confident sentence.
“Shopify accepted the refund, but the server crashed before saving it”
Use the stored idempotency key, provider reference, and reconciliation job to find the external result. The recovery path must be able to discover a completed operation before retrying.
“An approver approved the wrong line item”
Make the approval screen display canonical order and line-item details, and bind approval to a hash of the exact request. If any detail changes, invalidate the approval.
“A support employee asks the model to use a manager’s identity”
Ignore identity fields supplied by the model or user. Derive identity from the authenticated session and evaluate the session’s actual role. Log the denied attempt if your security policy allows it.
“An order contains prompt injection text”
Separate retrieved order data from instructions. Mark customer names, notes, addresses, and product text as untrusted content. The server must still enforce role checks, amount limits, approval requirements, and state validation if the model follows malicious text.
14. Limitations
This model does not eliminate business-policy ambiguity, compromised employee accounts, Shopify outages, incorrect source data, or every possible fraud scenario. It also does not replace Shopify’s own app permissions, your identity provider, secure secret storage, incident response process, or financial reconciliation controls.
The example schemas are intentionally platform-neutral. Shopify’s available APIs, permission names, refund semantics, and version behavior can change. Verify current platform documentation and the effective behavior of the specific app and store configuration you operate.
Approval is not a substitute for least privilege. Least privilege is not a substitute for approval. Audit logs are not a substitute for prevention. The controls work as a layered system.
Conclusion
The safe answer to “How can an MCP server refund Shopify orders?” is not “give the model the refund scope.” Expose read operations broadly enough to help, make the server calculate and constrain the proposed action, turn the action into a durable approval request, require an independent authorized decision, and let a narrow execution identity perform only the approved request.
If you can delete or bypass the approval record, change the amount after approval, execute with a support employee’s ordinary session, or retry an unknown outcome blindly, the permission model is not complete yet.
Continue with the Agent Lab Journal guides or look up implementation terms in the glossary.