📚 BookStore MCP - Complete Setup Guide
🎯 Project Overview
Full-featured bookstore MCP server với 6 tools và 4 interactive widgets, sử dụng Fractal MCP SDK chính thống.
Features:
✅ 6 MCP Tools: search, detail, cart, checkout, history
✅ 4 React Widgets: với useWidgetProps, useWidgetState, useLayout, useGlobalContext
✅ Zod Validation: Type-safe input schemas
✅ Structured Content: Proper widget props
✅ Dark/Light Theme: Responsive design
✅ In-Memory Database: 8 sample books
📦 Step 1: Create Project
📝 Step 2: Create File Structure
Sao chép nội dung từ các artifacts vào files tương ứng:
package.json- từ artifact "package.json"tsconfig.json- từ artifact "tsconfig.json"src/server/types.ts- từ artifact "src/server/types.ts"src/server/database.ts- từ artifact "src/server/database.ts"src/server/index.ts- từ artifact "src/server/index.ts - BookStore MCP Server"src/ui/BookListWidget.tsx- từ artifact "src/ui/BookListWidget.tsx"src/ui/BookDetailWidget.tsx- từ artifact "src/ui/BookDetailWidget.tsx"src/ui/CartWidget.tsx- từ artifact "src/ui/CartWidget.tsx"src/ui/OrderHistoryWidget.tsx- từ artifact "src/ui/OrderHistoryWidget.tsx"
📥 Step 3: Install Dependencies
🏗️ Step 4: Build Project
Or if error run
Expected output:
🚀 Step 5: Start Server Locally
Expected console output:
🧪 Step 6: Test Local Server
Terminal 1 (Server):
Terminal 2 (Test):
Bạn sẽ thấy UI với thông tin server!
🌐 Step 7: Deploy to Render
7.1 Push to GitHub
7.2 Deploy on Render
Truy cập https://render.com
Click "New +" → "Web Service"
Connect GitHub repository
Settings:
Name:
bookstore-mcpEnvironment:
NodeBuild Command:
npm install && npm run buildStart Command:
npm startInstance Type: Free
Click "Create Web Service"
7.3 Get URL
Sau khi deploy xong (3-5 phút):
Test: Mở URL trong browser, bạn sẽ thấy server info page!
🔗 Step 8: Connect to ChatGPT
Method 1: Direct URL (Recommended)
Mở ChatGPT → Settings (⚙️)
Click "Apps SDK" (hoặc "Integrations")
Click "Add App"
Nhập URL:
https://bookstore-mcp-xxxx.onrender.comChatGPT sẽ auto-discover MCP endpoint
Click "Connect"
Method 2: MCP Endpoint
Nếu method 1 không work:
URL:
https://bookstore-mcp-xxxx.onrender.com/mcpTransport: SSE (Server-Sent Events)
No authentication required
💬 Step 9: Test in ChatGPT
Sau khi connect thành công, thử các lệnh:
ChatGPT sẽ:
✅ Show text response
✅ Render interactive widget UI
✅ Widget có dark/light theme
✅ Data update real-time
🐛 Troubleshooting
Issue 1: Build fails
Issue 2: Widget không hiển thị
Check:
Fix:
Issue 3: ChatGPT connection failed
Verify endpoints:
Common fixes:
Đảm bảo Render service đang running (không sleep)
Check Render logs for errors
Verify PORT env variable (Render auto-sets this)
Issue 4: Module not found errors
📊 Architecture
🎨 Customization
Add new book:
Edit src/server/database.ts:
Add new tool:
Edit src/server/index.ts:
Modify widget UI:
Edit src/ui/*.tsx files, then:
📚 Resources
Fractal MCP SDK: https://github.com/fractal-mcp/sdk
OpenAI Apps SDK: https://developers.openai.com/apps-sdk/
Model Context Protocol: https://modelcontextprotocol.io
Render Docs: https://render.com/docs
✅ Success Checklist
Project created với đúng structure
Dependencies installed
Build successful (có dist/ui/*/index.html)
Server chạy local (port 8000)
Deployed to Render
ChatGPT connected
All 6 tools hoạt động
Widgets hiển thị đúng
Theme switching works
🎉 Done!
Bạn đã có một BookStore MCP Server hoàn chỉnh với:
✅ 6 powerful tools
✅ 4 beautiful widgets
✅ Full Fractal MCP SDK features
✅ ChatGPT integration
✅ Production-ready code
Next steps:
Add more books to database
Implement user authentication
Add payment processing
Deploy to production domain
Share with community!
Happy coding! 📚🚀