Introduction
A major trend in the world of AI tools right now is something called the Model Context Protocol (MCP). After researching and implementing it in one of my sample projects, I wanted to share an overview of MCP in this blog post.
What is Model Context Protocol
Model Context Protocol (MCP) is a flexible standard that allows AI tools to connect not just to databases, but to a wide range of resources such as APIs, file systems, document stores, and even real-time event streams. Its goal is to make it easy for AI applications to interact with all sorts of data and services using a common approach, so you can add new capabilities without a lot of extra work. While MCP can power integrations with web services, files, and custom plugins, in this post I’ll focus specifically on how it can be used to connect AI tools to databases, since that’s where I’ve found it most immediately useful and impactful. Another great feature is that it enables users who aren’t familiar with writing queries to perform various operations on a database. Based on your request, it will automatically generate and execute the appropriate query directly on the database.
First thing first, we need a database
To showcase this example, we need to create a database. We’ll create a Postgres database and deploy it on our machine using the Coolify platform, which we covered in this article: https://jafforge.com/posts/coolify/. This allows us to deploy a database in just two clicks.
Since this is a demo database, we’ll create it with standard data and enable public access.
Disclaimer: Public access is not recommended for production apps, but it’s acceptable for this example to showcase how it works.
Database Ready
Now that our database is ready, we’ll use DBeaver to connect and add some dummy data.
After connecting, we’ll run the following query to create the table:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100) UNIQUE,
city VARCHAR(100),
address VARCHAR(150),
age INT,
is_active BOOLEAN,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Next, let’s insert some dummy data:
INSERT INTO users (name, email)
VALUES
('Diana Prince', 'diana.prince@example.com'),
('Ethan Hunt', 'ethan.hunt@example.com'),
('Frodo Baggins', 'frodo.baggins@example.com'),
('Grace Hopper', 'grace.hopper@example.com'),
('Hank Moody', 'hank.moody@example.com'),
('Isla Fisher', 'isla.fisher@example.com'),
('Jack Sparrow', 'jack.sparrow@example.com'),
('Katniss Everdeen', 'katniss.e@example.com'),
('Luke Skywalker', 'luke.skywalker@example.com'),
('Maria Hill', 'maria.hill@example.com'),
('Neo Anderson', 'neo.anderson@example.com'),
('Olivia Wilde', 'olivia.wilde@example.com'),
('Peter Parker', 'peter.parker@example.com'),
('Quentin Beck', 'quentin.beck@example.com'),
('Rachel Green', 'rachel.green@example.com'),
('Steve Rogers', 'steve.rogers@example.com'),
('Tony Stark', 'tony.stark@example.com'),
('Uma Thurman', 'uma.thurman@example.com'),
('Viktor Reznov', 'viktor.reznov@example.com'),
('Wanda Maximoff', 'wanda.maximoff@example.com');
Now let’s check the database to see if all the data was saved correctly.
Everything looks good. Now let’s proceed with adding this database to Cursor AI via MCP. (I’m using Cursor AI since I’m currently experimenting with it, but the logic is similar for all AI tools that support MCP.)
Adding postgres via MCP to Cursor
First, open Cursor IDE, go to Settings, and navigate to Tools and Integration.
Add a new MCP server and fill in all the details.
Note: For the connection, you can either provide a full connection string (including host, password, port, user, etc.) or specify a config object. Cursor supports both. For this example, I used a connection string.
Once saved, if all credentials are correct, Cursor will be able to access your database.
Let’s retrieve the tables present
Now let’s retrieve all users from users table
Next, let’s showcase an example of filtering:
Note: MCP Postgres connections only support read operations. The database is treated as a read-only model source.
Wrap up
As you can see, MCP is a really interesting concept that enables us to create new data sources for our AI agents. This technically allows both engineers and non engineers to use natural language to execute any possible query on a database without writing a single line of SQL.
I’ve tested this on another project, and the Postgres MCP integration can even suggest improvements to your tables or queries, which can have a significant impact on large databases.
All in all, I expect that more and more tools will create their own versions of MCP servers that you can integrate into your favorite AI IDEs. You can even create your own MCP if you want!
That’s all for now. Thank you for your attention!