building-storefronts
medusajs/medusa-agent-skills
Frontend integration for Medusa storefronts: SDK usage, React Query patterns, and API calling rules.
What is building-storefronts?
Essential skill for building storefront features with Medusa. Covers SDK integration, React Query data fetching patterns, and critical rules for calling custom API routes and built-in endpoints. Required for all storefront development tasks including planning, research, and implementation.
- Use Medusa JS SDK for all API requests (never regular fetch)
- Integrate SDK methods for built-in endpoints and custom routes
- Implement React Query patterns for data fetching and mutations
- Handle optimistic updates, cache invalidation, and error states
- Display prices correctly without dividing by 100
- Manage loading, error, and success states in UI components
How to install building-storefronts
npx skills add https://github.com/medusajs/medusa-agent-skills --skill building-storefronts- Medusa JS SDK installed in your project
- React Query (TanStack Query) for data management
- Understanding of async/await and JavaScript promises
How to use building-storefronts
- 1.Locate where the Medusa SDK is instantiated in your project
- 2.Use sdk.store.* or sdk.admin.* methods for built-in endpoints
- 3.Use sdk.client.fetch() for custom API routes with plain JavaScript objects
- 4.Wrap data fetching in useQuery hooks for GET requests
- 5.Wrap mutations in useMutation hooks for POST/DELETE requests
- 6.Invalidate relevant queries in onSuccess callbacks to refresh data
- 7.Implement onError callbacks to handle and display failures to users
- 8.Always display prices as-is without dividing by 100
Use cases
- Calling custom Medusa API routes from a React storefront
- Fetching product lists and details using SDK methods
- Implementing product reviews or ratings with mutations
- Building checkout flows with optimistic updates and error handling
- Displaying product prices and inventory from Medusa backend
- Frontend developers building Medusa storefronts
- React developers integrating Medusa SDK
- Full-stack developers implementing storefront features
- Teams building custom storefronts on Medusa platform
building-storefronts FAQ
Always use the Medusa JS SDK. Regular fetch() is missing required headers (publishable API key for store, auth for admin) and will cause authentication/authorization errors.
Use sdk.client.fetch('/store/my-route') with a plain JavaScript object for the body. Never use JSON.stringify() - the SDK handles serialization automatically.
Prices from Medusa are stored as-is ($49.99 = 49.99, not in cents). Display them directly without dividing by 100.
Use useQuery for GET requests and useMutation for POST/DELETE requests. Invalidate queries in onSuccess callbacks to refresh data after mutations.
Load the references/frontend-integration.md file which contains step-by-step SDK patterns, complete React Query examples, and correct vs incorrect code comparisons.
Full instructions (SKILL.md)
Source of truth, from medusajs/medusa-agent-skills.
name: building-storefronts description: Load automatically when planning, researching, or implementing Medusa storefront features (calling custom API routes, SDK integration, React Query patterns, data fetching). REQUIRED for all storefront development in ALL modes (planning, implementation, exploration). Contains SDK usage patterns, frontend integration, and critical rules for calling Medusa APIs.
Medusa Storefront Development
Frontend integration guide for building storefronts with Medusa. Covers SDK usage, React Query patterns, and calling custom API routes.
When to Apply
Load this skill for ANY storefront development task, including:
- Calling custom Medusa API routes from the storefront
- Integrating Medusa SDK in frontend applications
- Using React Query for data fetching
- Implementing mutations with optimistic updates
- Error handling and cache invalidation
Also load building-with-medusa when: Building the backend API routes that the storefront calls
CRITICAL: Load Reference Files When Needed
The quick reference below is NOT sufficient for implementation. You MUST load the reference file before writing storefront integration code.
Load this reference when implementing storefront features:
- Calling API routes? → MUST load
references/frontend-integration.mdfirst - Using SDK? → MUST load
references/frontend-integration.mdfirst - Implementing React Query? → MUST load
references/frontend-integration.mdfirst
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | SDK Usage | CRITICAL | sdk- |
| 2 | React Query Patterns | HIGH | query- |
| 3 | Data Display | HIGH (includes CRITICAL price rule) | display- |
| 4 | Error Handling | MEDIUM | error- |
Quick Reference
1. SDK Usage (CRITICAL)
sdk-always-use- ALWAYS use the Medusa JS SDK for ALL API requests - NEVER use regular fetch()sdk-existing-methods- For built-in endpoints, use existing SDK methods (sdk.store.product.list(),sdk.admin.order.retrieve())sdk-client-fetch- For custom API routes, usesdk.client.fetch()sdk-required-headers- SDK automatically adds required headers (publishable API key for store, auth for admin) - regular fetch() missing these headers causes errorssdk-no-json-stringify- NEVER use JSON.stringify() on body - SDK handles serialization automaticallysdk-plain-objects- Pass plain JavaScript objects to body, not stringssdk-locate-first- Always locate where SDK is instantiated in the project before using it
2. React Query Patterns (HIGH)
query-use-query- UseuseQueryfor GET requests (data fetching)query-use-mutation- UseuseMutationfor POST/DELETE requests (mutations)query-invalidate- Invalidate queries inonSuccessto refresh data after mutationsquery-keys-hierarchical- Structure query keys hierarchically for effective cache managementquery-loading-states- Always handleisLoading,isPending,isErrorstates
3. Data Display (HIGH)
display-price-format- CRITICAL: Prices from Medusa are stored as-is ($49.99 = 49.99, NOT in cents). Display them directly - NEVER divide by 100
4. Error Handling (MEDIUM)
error-on-error- ImplementonErrorcallback in mutations to handle failureserror-display- Show error messages to users when mutations failerror-rollback- Use optimistic updates with rollback on error for better UX
Critical SDK Pattern
ALWAYS pass plain objects to the SDK - NEVER use JSON.stringify():
// ✅ CORRECT - Plain object
await sdk.client.fetch("/store/reviews", {
method: "POST",
body: {
product_id: "prod_123",
rating: 5,
}
})
// ❌ WRONG - JSON.stringify breaks the request
await sdk.client.fetch("/store/reviews", {
method: "POST",
body: JSON.stringify({ // ❌ DON'T DO THIS!
product_id: "prod_123",
rating: 5,
})
})
Why this matters:
- The SDK handles JSON serialization automatically
- Using JSON.stringify() will double-serialize and break the request
- The server won't be able to parse the body
Common Mistakes Checklist
Before implementing, verify you're NOT doing these:
SDK Usage:
- Using regular fetch() instead of the Medusa JS SDK (causes missing header errors)
- Not using existing SDK methods for built-in endpoints (e.g., using sdk.client.fetch("/store/products") instead of sdk.store.product.list())
- Using JSON.stringify() on the body parameter
- Manually setting Content-Type headers (SDK adds them)
- Hardcoding SDK import paths (locate in project first)
- Not using sdk.client.fetch() for custom routes
React Query:
- Not invalidating queries after mutations
- Using flat query keys instead of hierarchical
- Not handling loading and error states
- Forgetting to disable buttons during mutations (isPending)
Data Display:
- CRITICAL: Dividing prices by 100 when displaying (prices are stored as-is: $49.99 = 49.99, NOT in cents)
Error Handling:
- Not implementing onError callbacks
- Not showing error messages to users
- Not handling network failures gracefully
How to Use
For detailed patterns and examples, load reference file:
references/frontend-integration.md - SDK usage, React Query patterns, API integration
The reference file contains:
- Step-by-step SDK integration patterns
- Complete React Query examples
- Correct vs incorrect code examples
- Query key best practices
- Optimistic update patterns
- Error handling strategies
When to Use MedusaDocs MCP Server
Use this skill for (PRIMARY SOURCE):
- How to call custom API routes from storefront
- SDK usage patterns (sdk.client.fetch)
- React Query integration patterns
- Common mistakes and anti-patterns
Use MedusaDocs MCP server for (SECONDARY SOURCE):
- Built-in SDK methods (sdk.admin., sdk.store.)
- Official Medusa SDK API reference
- Framework-specific configuration options
Why skills come first:
- Skills contain critical patterns like "don't use JSON.stringify" that MCP doesn't emphasize
- Skills show correct vs incorrect patterns; MCP shows what's possible
- Planning requires understanding patterns, not just API reference
Integration with Backend
⚠️ CRITICAL: ALWAYS use the Medusa JS SDK - NEVER use regular fetch()
When building features that span backend and frontend:
- Backend (building-with-medusa skill): Module → Workflow → API Route
- Storefront (this skill): SDK → React Query → UI Components
- Connection:
- Built-in endpoints: Use existing SDK methods (
sdk.store.product.list()) - Custom API routes: Use
sdk.client.fetch("/store/my-route") - NEVER use regular fetch() - missing publishable API key causes errors
- Built-in endpoints: Use existing SDK methods (
Why the SDK is required:
- Store routes need
x-publishable-api-keyheader - Admin routes need
Authorizationand session headers - SDK handles all required headers automatically
- Regular fetch() without headers → authentication/authorization errors
See building-with-medusa for backend API route patterns.
Related skills
More from medusajs/medusa-agent-skills and the wider catalog.

building-with-medusa
Comprehensive patterns and rules for Medusa backend development—modules, workflows, API routes, and data models.

db-generate
Generate database migrations for Medusa modules with a single command.

db-migrate
Execute Medusa database migrations to apply pending schema changes.

learning-medusa
Interactive bootcamp-style tutorial for learning Medusa development by building a brands feature.

new-user
Create a new admin user in Medusa with email and password.

storefront-best-practices
Essential patterns and integration guidance for building modern ecommerce storefronts with any framework.