# ElectricSQL MCP

> ElectricSQL Sync Engine MCP brings real-time data from Postgres directly to your AI client. It lets you fetch structured subsets of database information, track changes over time, and query live application data right within your chat window.

## Overview
- **Category:** developer-tools
- **Price:** Free
- **Tags:** postgres, real-time-sync, data-streaming, incremental-updates, http-api, database-sync

## Description

This MCP connects your AI agent straight into a Postgres database, letting it stream live data without needing complex backend setups. You can ask questions about specific tables or monitor system state in real-time. It handles initial data dumps—getting the whole picture at once—and then keeps you updated as records change, using efficient log offsets for incremental syncs. Need to query a niche group of records? Use advanced filtering and subset snapshots, letting your agent handle complex 'WHERE' clauses that would normally break a URL. Because Vinkius hosts this MCP, connecting it is simple: link up once from any compatible client, and you immediately gain access to live database context for analysis or debugging.

## Tools

### get_shape
Use this tool to pull an initial snapshot of data from Postgres using a standard GET request.

### post_shape
Send complex queries and sync subsets of data out of Postgres by submitting them via POST.

## Prompt Examples

**Prompt:** 
```
Sync the 'public.items' table from the beginning using get_shape.
```

**Response:** 
```
I'm initiating the initial sync for 'public.items' with offset -1. I've retrieved 150 rows. The shape handle is 'items-handle-xyz'. Would you like to see the data or wait for live updates?
```

**Prompt:** 
```
Use post_shape to get the first 10 rows of 'orders' where status is 'pending', ordered by date.
```

**Response:** 
```
Querying 'orders' via POST... I found 10 pending orders. The most recent is Order #502 from today. I've used the limit and order_by parameters as requested.
```

**Prompt:** 
```
Start a live sync for the 'messages' table to watch for new entries.
```

**Response:** 
```
Live sync enabled for 'messages'. I am now long-polling the ElectricSQL engine. I will notify you immediately when new rows are detected in the database.
```

## Capabilities

### Initial Data Snapshots
Fetch a complete, historical snapshot of a data table using an initial sync call.

### Complex Subset Queries
Query specific groups of records—for example, only 'pending' orders in the last month—using advanced filtering methods.

### Real-time Data Streaming
Keep your agent continuously updated as data changes in the underlying Postgres database via long-polling or SSE.

## Use Cases

### Debugging a User Flow Issue
A backend developer notices a user reported an incorrect order total. Instead of running manual SQL queries across multiple tables, they ask their agent to use post_shape to query the 'orders' and 'line_items' tables for that specific user ID. The agent returns all relevant data shapes, confirming where the calculation failed.

### Monitoring System Health
A product manager needs to see if a new feature is causing errors in real-time. They set up a live sync on the 'error_logs' table. As soon as an error is written to Postgres, the agent immediately alerts them and provides the full context of the failure.

### Analyzing Campaign Leads
A marketing team wants to see all leads from a specific zip code who haven't opened an email in 30 days. They use post_shape, defining complex WHERE clauses for both geography and activity status. The agent returns only the actionable subset of contacts.

### Initial Project Context Build
A new data analyst needs to understand a legacy system's structure. Using get_shape with an offset=-1, they pull a full snapshot of the 'user_profiles' table, giving their agent enough context to answer structural questions immediately.

## Benefits

- You get live data streams. Instead of polling a database every few seconds, the agent stays connected and gets instant updates whenever records change.
- Complex filtering is simple. You don't have to write complicated API endpoints for niche queries; you just tell the agent what subset of data you need.
- It handles massive datasets efficiently. The built-in support for limits and offsets means you can browse huge tables without hitting memory or URL length restrictions.
- Use get_shape for initial dumps. When you start a project, you can pull an entire table snapshot quickly using this tool to establish context immediately.
- The whole process avoids complex plumbing. You connect your AI agent through Vinkius, and the data sync handles itself, letting you focus on logic, not infrastructure.

## How It Works

The bottom line is that your AI client sees your Postgres data as if it were local memory, giving you live application insight without writing a single integration script.

1. Subscribe to this MCP and provide your specific Electric Service URL, pointing it toward your live Postgres instance.
2. Your AI client initiates a data request using the appropriate method—either requesting an initial sync or setting up a continuous stream.
3. The agent receives structured, filtered data (a 'shape') directly into its context, allowing it to answer questions based on the current database state.

## Frequently Asked Questions

**How does ElectricSQL Sync Engine MCP handle large datasets?**
It supports pagination and limits, allowing you to efficiently browse massive tables without overloading the system. This prevents errors related to dataset size.

**Is this good for continuous monitoring?**
Yes. You can enable live streaming via long-polling or SSE, meaning your agent updates instantly whenever new rows are added to a table like 'messages'.

**Do I need to write SQL code to use the MCP?**
No. While the underlying mechanism uses SQL concepts (shapes and WHERE clauses), you interact with it naturally by simply asking your agent questions about the data.

**What is the difference between get_shape and post_shape?**
Use get_shape for initial, basic snapshots. Use post_shape when you need to send complex filtering parameters or detailed subsets of data that exceed simple GET request limits.

**Can I sync multiple tables at once using ElectricSQL Sync Engine MCP?**
Yes, you can define and manage shapes across several different Postgres tables within the same agent workflow to get a holistic view of your application state.