Instruction file imported from ryanmosz/Studybara (
.cursor/rules/custom-rules/mcp-quick-patterns.mdc). Copyright stays with the author.
MCP Quick Patterns
Description: Common patterns and examples for effective MCP usage with direct database access
Quick Command Templates
1. Adding a Database Column
"Add a [column_name] to the [table_name] table with:
- Direct migration via MCP
- Updated TypeScript types
- UI changes in relevant components"
2. Creating a New Feature
"Build [feature_name] with:
- Database schema (create and apply via MCP)
- Component structure
- Service functions
- Full implementation"
3. Debugging Database Issues
"Debug why [issue]. Check:
- Current schema via MCP
- Query data directly
- View logs
- Security advisors"
4. Schema Analysis
"Analyze current database structure and:
- List all tables
- Check RLS policies
- Review security issues
- Suggest improvements"
Common Patterns by Task Type
Database Operations (Direct via MCP)
Agent Executes Directly:
// Query current schema
mcp_supabase_list_tables({ schemas: ["public"] })
// Create and apply migration
mcp_supabase_apply_migration({
name: "add_favorites_table",
query: `CREATE TABLE favorites (...)`
})
// Verify changes
mcp_supabase_execute_sql("SELECT * FROM favorites LIMIT 1")
UI Development
Agent Executes Everything:
- Creates components
- Implements features
- Installs packages
- Updates types
- Tests locally
Debugging with MCP
Agent Can Now:
// Check data
mcp_supabase_execute_sql("SELECT COUNT(*) FROM messages WHERE sender_id IS NULL")
// View logs
mcp_supabase_get_logs({ service: "postgres" })
// Get security issues
mcp_supabase_get_advisors({ type: "security" })
Local + Database Setup
Agent Executes All:
# Local setup
npm install @supabase/supabase-js
# Database setup via MCP
mcp_supabase_apply_migration({
name: "initial_schema",
query: "CREATE TABLE ..."
})
# Verify and commit
git add .
git commit -m "feat: complete setup"
Effective MCP Usage
Direct Database Access
mcp_supabase_execute_sql()- Query data directlymcp_supabase_apply_migration()- Create schema changesmcp_supabase_list_tables()- Inspect structuremcp_supabase_get_advisors()- Check security
Project Analysis (RepoPrompt)
mcp_RepoPrompt_get_codemap()- Analyze code structuremcp_RepoPrompt_search()- Find patternsmcp_RepoPrompt_read_file()- Read specific files
Combined Power
// 1. Check current schema
const tables = mcp_supabase_list_tables()
// 2. Search for related code
const usage = mcp_RepoPrompt_search({
pattern: "supabase.from('messages')",
mode: "content"
})
// 3. Apply migration
mcp_supabase_apply_migration({
name: "update_messages_table",
query: "ALTER TABLE messages ADD COLUMN ..."
})
// 4. Update code locally
edit_file("src/types/database.ts", updatedTypes)
Pro Tips
- Query Before Migrating: Always check current state first
- Verify After Changes: Use execute_sql to confirm
- Monitor Security: Regular advisor checks
- Use Branches: Test big changes on dev branches
- Combine MCPs: Use both for complete solutions
Example: Full Feature Flow
Request: "Add a favorites feature"
Agent executes everything:
// 1. Check schema
mcp_supabase_list_tables({ schemas: ["public"] })
// 2. Create migration
mcp_supabase_apply_migration({
name: "create_favorites_table",
query: `
CREATE TABLE favorites (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID REFERENCES profiles(id),
message_id UUID REFERENCES messages(id),
created_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(user_id, message_id)
);
CREATE POLICY "Users manage own favorites"
ON favorites FOR ALL
TO authenticated
USING (auth.uid() = user_id);
`
})
// 3. Verify it worked
mcp_supabase_execute_sql("SELECT * FROM pg_tables WHERE tablename = 'favorites'")
// 4. Generate TypeScript types
mcp_supabase_generate_typescript_types()
// 5. Create service
create_file("src/services/favorites.ts", favoriteService)
// 6. Create UI
create_file("src/components/FavoriteButton.tsx", component)
// 7. Test with query
mcp_supabase_execute_sql("SELECT * FROM favorites WHERE user_id = 'test-id'")
// 8. Commit
git_commit("feat: add favorites feature with database")
Division of Labor (Updated)
Agent Handles (via MCP):
- ✅ Database queries (SELECT)
- ✅ Schema migrations
- ✅ Security analysis
- ✅ Log viewing
- ✅ Type generation
- ✅ All local operations
Human Only Needed For:
- Production deployment approval
- API key management
- Authentication provider setup
- Billing/usage monitoring
- Custom domain configuration
Remember
- Agent has direct database access via MCP
- Most operations are now fully automated
- No more copy-paste SQL workflows
- Instant verification of changes
- Better debugging with logs and queries
- Security monitoring built-in