The RateMyEmployer MCP (Model Context Protocol) integration enables natural language interaction with your Supabase database through AI tools like Cursor. This integration provides:
- Simplified Database Access: Query your database using plain English instead of SQL
- Enhanced Developer Experience: Get instant insights and data without context switching
- Powerful Analytics: Easily analyze company ratings, review trends, and user activity
- Streamlined Workflows: Generate reports and extract insights with simple prompts
This integration is fully configured with custom stored procedures, a detailed schema, and sample queries to help you get started quickly.
- Overview
- Components
- Setup
- Usage
- Available Features
- Sample Queries
- Stored Procedures
- Using MCP in Your Code
- Troubleshooting
- Advanced Configuration
- Technical Details
- Form Verification Integration
The Model Context Protocol (MCP) enables AI tools to understand and interact with your application's data model. By integrating MCP with RateMyEmployer's Supabase database, you can:
- Query company data using natural language
- Analyze review trends and statistics
- Generate reports and insights
- Perform complex data operations with simple prompts
This integration uses Cursor's MCP implementation to connect directly to your Supabase database, providing a seamless experience for developers.
.mcp/supabase/config.json: Contains the MCP server configuration for Supabase.mcp/supabase/schema.json: Defines the database schema for the MCP server
scripts/setup-mcp.ts: Sets up the MCP server configurationscripts/setup-stored-procedures.ts: Sets up stored procedures for the MCP serverscripts/mcp-database-fixes.ts: Fixes database schema and stored procedures for MCP
scripts/mcp-stored-procedures.sql: Contains the SQL for stored proceduresscripts/mcp-database-fixes.sql: Contains SQL fixes for the database schema
scripts/mcp-sample-queries.ts: Contains sample queries for the MCP server
src/components/MCPDemoComponent.tsx: React component demonstrating MCP integrationsrc/app/mcp-demo/page.tsx: Demo page showcasing the MCP integration
- Node.js v16 or higher
- Supabase project with service role key
- Cursor IDE installed
Create a .env file in the project root with the following variables:
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
- Run the MCP setup script:
npm run mcp:setupThis script will:
- Create necessary directories
- Generate MCP configuration
- Extract database schema
- Set up stored procedures
- Update package.json with MCP scripts
- Install the stored procedures:
npm run mcp:setup-proceduresThis will create and verify the SQL functions that enhance MCP's capabilities.
Start the MCP server with:
npm run mcp:startThis will launch the MCP server and connect it to your Supabase database.
Alternatively, use the interactive runner:
npm run mcp:runnerOnce the MCP server is running, you can use natural language to interact with your database in Cursor:
- Open Cursor IDE
- Make sure the MCP server is running
- Type natural language queries in comments or as questions to the AI
For example:
// Show me the top 5 highest-rated companiesOr ask directly:
"What are the average ratings by industry?"
To see examples of the types of queries you can run with MCP:
npm run mcp:sample-queriesThis will execute several sample queries against your database and display the results.
Visit the /mcp-demo page in your browser to see the MCP integration in action. This page demonstrates how to use MCP-generated queries in your React components.
The MCP integration provides access to the following data and operations:
- Company profiles and details
- Industry and location information
- Rating statistics and trends
- Individual reviews and ratings
- Review trends over time
- Sentiment analysis and insights
- User profiles and activity
- Review history and patterns
- Contribution statistics
- Industry comparisons
- Rating distributions
- Geographical insights
- Temporal trends
Here are some examples of natural language queries you can use with MCP:
- "Show me all companies in the Technology industry"
- "Find reviews with ratings lower than 2"
- "List the top 10 highest-rated companies"
- "What's the average rating by industry?"
- "Show me the trend of review submissions over the last 6 months"
- "Which industries have the most companies with no reviews?"
- "Find companies in the Finance industry with at least 5 reviews and an average rating above 4"
- "Show me the distribution of ratings for companies in New York"
- "Compare the average ratings of companies in the Healthcare vs Technology industries"
The MCP integration includes several stored procedures that enhance its capabilities. However, due to potential compatibility issues with PostgreSQL versions and reserved keywords, we've also implemented a TypeScript-based statistics module as an alternative approach.
We've implemented a TypeScript-based statistics module in src/lib/statistics.ts that provides similar functionality to the stored procedures but with improved reliability and type safety. This module includes:
getIndustryStatistics: Returns statistics grouped by industry (with reviews)getLocationStatistics: Returns statistics grouped by location (with reviews)getAllIndustryStatistics: Returns statistics for all industries (including those without reviews)getAllLocationStatistics: Returns statistics for all locations (including those without reviews)
These functions directly query the Supabase database and process the results in JavaScript, providing a more reliable alternative to stored procedures. They are used in the MCPDemoComponent and WallOfCompanies components.
Returns the average ratings for companies grouped by industry.
Parameters: None
Returns: Table with columns industry and average_rating
Example:
SELECT * FROM get_average_ratings_by_industry();Note: This stored procedure has been replaced by the getIndustryStatistics function in the TypeScript statistics module.
Returns the count of reviews submitted per month.
Parameters: None
Returns: Table with columns month and review_count
Example:
SELECT * FROM get_review_submission_trends();Returns the top-rated companies in a specific industry.
Parameters:
p_industry(text): The industry to filter byp_limit(integer): Maximum number of companies to return
Returns: Table with company details and average ratings
Example:
SELECT * FROM get_top_companies_by_industry('Technology', 5);Returns the most recent reviews for a specific company.
Parameters:
p_company_id(integer): The ID of the companyp_limit(integer): Maximum number of reviews to return
Returns: Table with review details
Example:
SELECT * FROM get_recent_reviews_for_company(123, 10);Searches for companies by name or location.
Parameters:
p_search_term(text): The search term to look forp_limit(integer): Maximum number of companies to return
Returns: Table with company details
Example:
SELECT * FROM search_companies('tech', 20);Returns the distribution of ratings across all reviews.
Parameters: None
Returns: Table with columns rating and count
Example:
SELECT * FROM get_rating_distribution();Returns companies that have no reviews.
Parameters:
p_limit(integer): Maximum number of companies to return
Returns: Table with company details
Example:
SELECT * FROM get_companies_with_no_reviews(10);import { createClient } from '@supabase/supabase-js';
import type { Database } from '@/types/supabase';
// Create a Supabase client
const supabase = createClient<Database>(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
);
// Fetch companies using a query generated by MCP
async function fetchCompanies() {
try {
const { data, error } = await supabase
.from('companies')
.select('*')
.order('created_at', { ascending: false })
.limit(10);
if (error) throw error;
return data;
} catch (error) {
console.error('Error fetching companies:', error);
throw error;
}
}MCP can generate complex queries based on natural language input. For example:
// Natural language: "Show me all companies in the Technology industry with ratings above 4"
const { data, error } = await supabase
.from('companies')
.select('*, reviews(*)')
.eq('industry', 'Technology')
.gte('average_rating', 4);// Use a stored procedure created by MCP
const { data, error } = await supabase.rpc('get_average_ratings_by_industry');
if (error) {
console.error('Error fetching average ratings:', error);
} else {
console.log('Average ratings by industry:', data);
}If you encounter errors related to missing columns like average_rating or total_reviews, you need to run the database fixes script:
npm run mcp:fix-databaseThis script will:
- Add the missing columns to the companies table
- Update the columns with calculated values based on reviews
- Create the necessary stored procedures
If you see errors like "Could not find the function public.exec_sql", run the database fixes script:
npm run mcp:fix-databaseIf that doesn't work, you'll need to execute the SQL script directly in the Supabase SQL Editor:
- Open the Supabase dashboard
- Navigate to the SQL Editor
- Copy the contents of
scripts/mcp-database-fixes.sql - Execute the script
Important Note: Due to limitations in the Supabase JavaScript client, some operations can only be performed directly in the SQL Editor. If you encounter persistent errors with the TypeScript approach, using the SQL script directly is the recommended solution.
If stored procedures are not working correctly, try:
-
Running the database fixes script:
npm run mcp:fix-database
-
Then re-run the stored procedures setup:
npm run mcp:setup-procedures
-
Restart the MCP server:
npm run mcp:start
To verify that the MCP integration is working correctly:
-
Run the sample queries:
npm run mcp:sample-queries
-
Check the MCP demo page:
npm run dev # Navigate to http://localhost:3000/mcp-demo -
Test stored procedures directly:
-- In Supabase SQL Editor SELECT * FROM get_average_ratings_by_industry();
For the MCP integration to work correctly, the database schema must include:
-
Companies Table:
id: Primary keyname: Company nameindustry: Industry categorylocation: Company locationaverage_rating: Average rating (calculated from reviews)total_reviews: Total number of reviews
-
Reviews Table:
id: Primary keycompany_id: Foreign key to companies tablerating: Numeric rating (1-5)title: Review titlepros: Pros textcons: Cons textcreated_at: Timestamp
-
Required Functions:
exec_sql(sql text): Helper function for executing dynamic SQLget_average_ratings_by_industry(): Returns average ratings by industryget_companies_with_no_reviews(): Returns companies with no reviewsget_top_companies_by_industry(industry_name TEXT): Returns top companies in an industryget_recent_reviews_for_company(company_id_param INTEGER): Returns recent reviews for a companyget_review_submission_trends(): Returns review submission trends by monthsearch_companies(search_term TEXT): Searches for companies by name, industry, or locationget_rating_distribution(): Returns the distribution of ratings
The MCP schema is automatically generated from your database. If you need to customize it:
- Edit the
.mcp/supabase/schema.jsonfile - Add or modify table and field descriptions
- Restart the MCP server
To add custom stored procedures:
- Edit the
scripts/mcp-stored-procedures.sqlfile - Add your new procedure definitions
- Run
npm run mcp:setup-proceduresto install them
The MCP server can be used with other AI tools that support the Model Context Protocol. Refer to the specific tool's documentation for integration instructions.
The MCP integration consists of several key components:
-
Configuration Files:
.mcp/supabase/config.json: Main configuration for the MCP server.mcp/supabase/schema.json: Database schema with detailed field descriptions
-
Setup Scripts:
scripts/setup-mcp.ts: Main setup script that configures the MCP integrationscripts/setup-stored-procedures.ts: Script to install SQL stored proceduresscripts/mcp-sample-queries.ts: Examples of queries you can run with MCP
-
SQL Components:
scripts/mcp-stored-procedures.sql: SQL functions that enhance query capabilities
-
UI Components:
src/components/MCPDemoComponent.tsx: React component demonstrating MCP integrationsrc/app/mcp-demo/page.tsx: Demo page showcasing the MCP integration
| Script | Description |
|---|---|
npm run mcp:setup |
Sets up the MCP server configuration |
npm run mcp:start |
Starts the MCP server |
npm run mcp:sample-queries |
Runs sample queries against the MCP server |
npm run mcp:setup-procedures |
Sets up stored procedures for the MCP server |
npm run mcp:runner |
Launches the interactive MCP server runner |
The RateMyEmployer project includes comprehensive form verification and Supabase data validation tools that work alongside the MCP integration.
| Script | Description |
|---|---|
npm run verify:supabase |
Verifies data integrity in Supabase |
npm run test:form-validation |
Tests form validation logic |
npm run test:form-submissions |
Tests form submission process |
npm run monitor:submissions |
Monitors form submissions in real-time |
npm run verify:all |
Runs all verification scripts |
The form validation testing tools ensure that:
- All required fields are properly validated
- Field-specific validations (email format, URL format, etc.) work correctly
- Min/max length constraints are enforced
- Numeric range constraints (ratings 1-5) are respected
- Enum constraints (dropdown options) are validated
The Supabase data verification tools check:
- Primary keys are correctly assigned
- Foreign key relationships are maintained
- Timestamps (created_at, updated_at) are set correctly
- Enum values match expected options
- Numeric constraints are enforced
- Text fields respect length constraints
- Required fields are never null
- Default values are applied correctly
The form verification tools complement the MCP integration by ensuring data integrity. When using MCP to query your database, you can be confident that the data meets the expected validation criteria.
For more detailed information on form verification, refer to the scripts in the scripts/ directory:
verify-supabase-data.tstest-form-validation.tstest-form-submissions.tsmonitor-form-submissions.ts