Supabase MCP Server

repository·main·Indexed 41 days ago

https://github.com/coleam00/supabase-mcp

A Model Context Protocol (MCP) interface built with the FastMCP Python SDK that allows AI agents to perform CRUD operations on Supabase PostgreSQL databases via Stdio transport. It provides tools for reading, creating, updating, and deleting table records using environment variables SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY for authentication.

Tokens
1.4K
Snippets
5
Records
8
Agent score
2%

What's inside Supabase MCP Server

  1. Overview of Supabase MCP Server capabilities

    main

    The Supabase MCP Server implements the Model Context Protocol (MCP) using the FastMCP Python SDK. It provides AI assistants with a standardized interface to interact with a Supabase (PostgreSQL) database via Stdio transport.

    Available MCP Tools include:

    • Read records: Retrieve data from tables.
    • Create records: Insert new data into tables.
    • Update records: Modify existing data in tables.
    • Delete records: Remove data from tables.
  2. Configure the Supabase MCP Server environment

    main

    To use the Supabase MCP Server, you must provide the following environment variables to authenticate the Supabase client and connect to your project:

    • SUPABASE_URL: The URL of your Supabase project.
    • SUPABASE_SERVICE_ROLE_KEY: The service role key for Supabase authentication (required for performing administrative database operations).
  3. Configure Supabase MCP Server environment variables

    main

    To use the Supabase MCP server, you must provide the following environment variables so the server can authenticate with your Supabase project:

    • SUPABASE_URL: The URL of your Supabase project.
    • SUPABASE_SERVICE_KEY: The service role key for your Supabase project.

    If these variables are missing, the server will raise a ValueError during initialization.

  4. Create records in a Supabase table

    main

    Use the create_table_records tool to insert new data. You can insert either a single record or a batch of multiple records.

    Arguments:

    • table_name (str): Name of the target table.
    • records (Dict[str, Any] | List[Dict[str, Any]]): A dictionary for a single record or a list of dictionaries for multiple records.

    Returns: A dictionary containing the created data, the count of records created, and a status string ("success" or "error").

    # To create a single record
    create_table_records(
        table_name="users",
        records={"name": "John Doe", "email": "john@example.com"}
    )
    
    # To create multiple records
    create_table_records(
        table_name="users",
        records=[
            {"name": "John Doe", "email": "john@example.com"},
            {"name": "Jane Smith", "email": "jane@example.com"}
        ]
    )
  5. Update records in a Supabase table

    main

    Use the update_table_records tool to modify existing data. You must provide filters to identify which rows should be updated to avoid updating unintended records.

    Arguments:

    • table_name (str): Name of the table.
    • updates (Dict[str, Any]): Dictionary of column-value pairs containing the new values.
    • filters (Dict[str, Any]): Dictionary of column-value pairs used to match rows for updating.

    Returns: A dictionary containing the updated data, the count of affected rows, and a status string.

    # To update all active users' status
    update_table_records(
        table_name="users",
        updates={"status": "premium"},
        filters={"is_active": True}
    )
  6. Read rows from a Supabase table

    main

    Use the read_table_rows tool to query data from a specific table. You can select specific columns, apply equality filters, set a limit on results, and define the sort order.

    Arguments:

    • table_name (str): Name of the table.
    • columns (str, default: "*"): Comma-separated list of columns to select.
    • filters (Dict[str, Any], optional): Dictionary of column-value pairs for equality filtering (eq).
    • limit (int, optional): Maximum number of rows to return.
    • order_by (str, optional): Column to order results by.
    • ascending (bool, default: True): Sort direction.

    Returns: A list of dictionaries, where each dictionary represents a row.

    # To get all users
    read_table_rows(table_name="users")
    
    # To get specific columns
    read_table_rows(table_name="users", columns="id,name,email")
    
    # To filter rows
    read_table_rows(table_name="users", filters={"is_active": True})
    
    # To limit results
    read_table_rows(table_name="users", limit=10)
    
    # To order results
    read_table_rows(table_name="users", order_by="created_at", ascending=False)
  7. Delete records from a Supabase table

    main

    Use the delete_table_records tool to remove data. You must provide filters to specify which records should be deleted.

    Arguments:

    • table_name (str): Name of the table.
    • filters (Dict[str, Any]): Dictionary of column-value pairs used to match rows for deletion.

    Returns: A dictionary containing the deleted data, the count of deleted rows, and a status string.

    # To delete inactive users
    delete_table_records(
        table_name="users",
        filters={"is_active": False}
    )