You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+63-45Lines changed: 63 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -23,9 +23,9 @@
23
23
24
24
## Overview
25
25
26
-
**Postgres Pro** is an open source Model Context Protocol (MCP) server built to support you and your AI agents throughout the **entire development process**—from initial coding, through testing and deployment, and to production tuning and maintenance.
26
+
**Postgres MCP Pro** is an open source Model Context Protocol (MCP) server built to support you and your AI agents throughout the **entire development process**—from initial coding, through testing and deployment, and to production tuning and maintenance.
27
27
28
-
Postgres Pro does much more than wrap a database connection.
28
+
Postgres MCP Pro does much more than wrap a database connection.
29
29
30
30
Features include:
31
31
@@ -70,16 +70,18 @@ Features include:
70
70
</tr>
71
71
</table>
72
72
73
-
For additional background on why we built Postgres Pro, see [our launch blog post](https://www.crystaldba.ai/blog/post/announcing-postgres-mcp-server-pro).
73
+
Postgres MCP Pro supports both the [Standard Input/Output (stdio)](https://modelcontextprotocol.io/docs/concepts/transports#standard-input%2Foutput-stdio) and [Server-Sent Events (SSE)](https://modelcontextprotocol.io/docs/concepts/transports#server-sent-events-sse) transports, for flexibility in different environments.
74
+
75
+
For additional background on why we built Postgres MCP Pro, see [our launch blog post](https://www.crystaldba.ai/blog/post/announcing-postgres-mcp-server-pro).
74
76
75
77
## Demo
76
78
77
79
*From Unusable to Lightning Fast*
78
80
79
81
-**Challenge:** We generated a movie app using an AI assistant, but the SQLAlchemy ORM code ran painfully slowly
80
-
-**Solution:** Using Postgres Pro with Cursor, we fixed the performance issues in minutes
82
+
-**Solution:** Using Postgres MCP Pro with Cursor, we fixed the performance issues in minutes
81
83
82
-
**We used the Cursor AI agent and Postgres Pro to:**
84
+
**We used the Cursor AI agent and Postgres MCP Pro to:**
83
85
- 🚀 Fix performance - including ORM queries, indexing, and caching
84
86
- 🛠️ Fix bugs that require connecting data to code
85
87
- 🧠 Add new features from single prompts
@@ -112,12 +114,12 @@ However, it often makes sense to use whichever method you are most familiar with
112
114
113
115
### Installation
114
116
115
-
Choose one of the following methods to install Postgres Pro:
117
+
Choose one of the following methods to install Postgres MCP Pro:
116
118
117
119
#### Option 1: Using Docker
118
120
119
-
Pull the Postgres Pro MCP server Docker image.
120
-
This image contains all necessary dependencies, providing a reliable way to run Postgres Pro in a variety of environments.
121
+
Pull the Postgres MCP Pro MCP server Docker image.
122
+
This image contains all necessary dependencies, providing a reliable way to run Postgres MCP Pro in a variety of environments.
- Linux: Uses `172.17.0.1` or the appropriate host address automatically
@@ -234,7 +236,7 @@ Replace `postgresql://...` with your [Postgres database connection URI](https://
234
236
235
237
##### Access Mode
236
238
237
-
Postgres Pro supports multiple *access modes* to give you control over the operations that the AI agent can perform on the database:
239
+
Postgres MCP Pro supports multiple *access modes* to give you control over the operations that the AI agent can perform on the database:
238
240
-**Unrestricted Mode**: Allows full read/write access to modify data and schema. It is suitable for development environments.
239
241
-**Restricted Mode**: Limits operations to read-only transactions and imposes constraints on resource utilization (presently only execution time). It is suitable for production environments.
240
242
@@ -251,35 +253,51 @@ Many MCP clients have similar configuration files to Claude Desktop, and you can
251
253
252
254
## SSE Transport
253
255
254
-
Postgres Pro supports the SSE transport, which allows you to connect to the server using a web browser.
255
-
To use the SSE transport, you need to start the server with the `--transport sse` flag.
256
+
Postgres MCP Pro supports the [SSE transport](https://modelcontextprotocol.io/docs/concepts/transports#server-sent-events-sse), which allows multiple MCP clients to share one server, possibly a remote server.
257
+
To use the SSE transport, you need to start the server with the `--transport=sse` option.
258
+
259
+
For example, with Docker run:
256
260
257
261
```bash
258
-
docker run -p 8000:8000 -e DATABASE_URI=postgresql://username:password@localhost:5432/dbname crystaldba/postgres-mcp --transport sse
Then update your MCP client configuration to call the the MCP server.
262
-
For example, in Windsurf's `mcp_config.json` you can put:
268
+
For example, in Cursor's `mcp.json` or Cline's `cline_mcp_settings.json` you can put:
263
269
264
270
```json
265
271
{
266
272
"mcpServers": {
267
273
"postgres": {
268
274
"type": "sse",
269
-
"serverUrl": "http://localhost:8000/sse"
275
+
"url": "http://localhost:8000/sse"
270
276
}
271
277
}
272
278
}
273
279
```
274
280
281
+
For Windsurf, the format in `mcp_config.json` is slightly different:
282
+
283
+
```json
284
+
{
285
+
"mcpServers": {
286
+
"postgres": {
287
+
"type": "sse",
288
+
"serverUrl": "http://localhost:8000/sse"
289
+
}
290
+
}
291
+
}
292
+
```
275
293
276
294
## Postgres Extension Installation (Optional)
277
295
278
296
To enable index tuning and comprehensive performance analysis you need to load the `pg_statements` and `hypopg` extensions on your database.
279
297
280
-
- The `pg_statements` extension allows Postgres Pro to analyze query execution statistics.
298
+
- The `pg_statements` extension allows Postgres MCP Pro to analyze query execution statistics.
281
299
For example, this allows it to understand which queries are running slow or consuming significant resources.
282
-
- The `hypopg` extension allows Postgres Pro to simulate the behavior of the Postgres query planner after adding indexes.
300
+
- The `hypopg` extension allows Postgres MCP Pro to simulate the behavior of the Postgres query planner after adding indexes.
283
301
284
302
### Installing extensions on AWS RDS, Azure SQL, or Google Cloud SQL
285
303
@@ -328,12 +346,12 @@ Ask:
328
346
329
347
The [MCP standard](https://modelcontextprotocol.io/) defines various types of endpoints: Tools, Resources, Prompts, and others.
330
348
331
-
Postgres Pro provides functionality via [MCP tools](https://modelcontextprotocol.io/docs/concepts/tools) alone.
349
+
Postgres MCP Pro provides functionality via [MCP tools](https://modelcontextprotocol.io/docs/concepts/tools) alone.
332
350
We chose this approach because the [MCP client ecosystem](https://modelcontextprotocol.io/clients) has widespread support for MCP tools.
333
351
This contrasts with the approach of other Postgres MCP servers, including the [Reference Postgres MCP Server](https://github.com/modelcontextprotocol/servers/tree/main/src/postgres), which use [MCP resources](https://modelcontextprotocol.io/docs/concepts/resources) to expose schema information.
334
352
335
353
336
-
Postgres Pro Tools:
354
+
Postgres MCP Pro Tools:
337
355
338
356
| Tool Name | Description |
339
357
|-----------|-------------|
@@ -369,36 +387,36 @@ Postgres Pro Tools:
369
387
**Postgres Utilities**
370
388
-[Dexter](https://github.com/DexterDB/dexter). A tool for generating and testing hypothetical indexes on PostgreSQL.
371
389
-[PgHero](https://github.com/ankane/pghero). A performance dashboard for Postgres, with recommendations.
372
-
Postgres Pro incorporates health checks from PgHero.
390
+
Postgres MCP Pro incorporates health checks from PgHero.
373
391
-[PgTune](https://github.com/le0pard/pgtune?tab=readme-ov-file). Heuristics for tuning Postgres configuration.
374
392
375
393
## Frequently Asked Questions
376
394
377
-
*How is Postgres Pro different from other Postgres MCP servers?*
395
+
*How is Postgres MCP Pro different from other Postgres MCP servers?*
378
396
There are many MCP servers allow an AI agent to run queries against a Postgres database.
379
-
Postgres Pro does that too, but also adds tools for understanding and improving the performance of your Postgres database.
397
+
Postgres MCP Pro does that too, but also adds tools for understanding and improving the performance of your Postgres database.
380
398
For example, it implements a version of the [Anytime Algorithm of Database Tuning Advisor for Microsoft SQL Server](https://www.microsoft.com/en-us/research/wp-content/uploads/2020/06/Anytime-Algorithm-of-Database-Tuning-Advisor-for-Microsoft-SQL-Server.pdf), a modern industrial-strength algorithm for automatic index tuning.
381
399
382
-
| Postgres Pro | Other Postgres MCP Servers |
400
+
| Postgres MCP Pro | Other Postgres MCP Servers |
383
401
|--------------|----------------------------|
384
402
| ✅ Deterministic database health checks | ❌ Unrepeatable LLM-generated health queries |
| ✅ Workload analysis to find top problems | ❌ Inconsistent problem analysis |
387
405
| ✅ Simulates performance improvements | ❌ Try it yourself and see if it works |
388
406
389
-
Postgres Pro complements generative AI by adding deterministic tools and classical optimization algorithms
407
+
Postgres MCP Pro complements generative AI by adding deterministic tools and classical optimization algorithms
390
408
The combination is both reliable and flexible.
391
409
392
410
393
411
*Why are MCP tools needed when the LLM can reason, generate SQL, etc?*
394
412
LLMs are invaluable for tasks that involve ambiguity, reasoning, or natural language.
395
413
When compared to procedural code, however, they can be slow, expensive, non-deterministic, and sometimes produce unreliable results.
396
414
In the case of database tuning, we have well established algorithms, developed over decades, that are proven to work.
397
-
Postgres Pro lets you combine the best of both worlds by pairing LLMs with classical optimization algorithms and other procedural tools.
415
+
Postgres MCP Pro lets you combine the best of both worlds by pairing LLMs with classical optimization algorithms and other procedural tools.
398
416
399
-
*How do you test Postgres Pro?*
400
-
Testing is critical to ensuring that Postgres Pro is reliable and accurate.
401
-
We are building out a suite of AI-generated adversarial workloads designed to challenge Postgres Pro and ensure it performs under a broad variety of scenarios.
417
+
*How do you test Postgres MCP Pro?*
418
+
Testing is critical to ensuring that Postgres MCP Pro is reliable and accurate.
419
+
We are building out a suite of AI-generated adversarial workloads designed to challenge Postgres MCP Pro and ensure it performs under a broad variety of scenarios.
402
420
403
421
*What Postgres versions are supported?*
404
422
Our testing presently focuses on Postgres 15, 16, and 17.
@@ -417,19 +435,19 @@ You can also contact us on [Discord](https://discord.gg/4BEHC7ZM).
417
435
418
436
## Technical Notes
419
437
420
-
This section includes a high-level overview technical considerations that influenced the design of Postgres Pro.
438
+
This section includes a high-level overview technical considerations that influenced the design of Postgres MCP Pro.
421
439
422
440
### Index Tuning
423
441
424
442
Developers know that missing indexes are one of the most common causes of database performance issues.
425
443
Indexes provide access methods that allow Postgres to quickly locate data that is required to execute a query.
426
444
When tables are small, indexes make little difference, but as the size of the data grows, the difference in algorithmic complexity between a table scan and an index lookup becomes significant (typically *O*(*n*) vs *O*(*log**n*), potentially more if joins on multiple tables are involved).
427
445
428
-
Generating suggested indexes in Postgres Pro proceeds in several stages:
446
+
Generating suggested indexes in Postgres MCP Pro proceeds in several stages:
429
447
430
448
1.*Identify SQL queries in need of tuning*.
431
449
If you know you are having a problem with a specific SQL query you can provide it.
432
-
Postgres Pro can also analyze the workload to identify index tuning targets.
450
+
Postgres MCP Pro can also analyze the workload to identify index tuning targets.
433
451
To do this, it relies on the `pg_stat_statements` extension, which records the runtime and resource consumption of each query.
434
452
435
453
A query is a candidate for index tuning if it is a top resource consumer, either on a per-execution basis or in aggregate.
@@ -438,7 +456,7 @@ Generating suggested indexes in Postgres Pro proceeds in several stages:
438
456
Agents may also call `get_top_queries`, which accepts a parameter for mean vs. total execution time, then pass these queries `analyze_query_indexes` to get index recommendations.
439
457
440
458
Sophisticated index tuning systems use "workload compression" to produce a representative subset of queries that reflects the characteristics of the workload as a whole, reducing the problem for downstream algorithms.
441
-
Postgres Pro performs a limited form of workload compression by normalizing queries so that those generated from the same template appear as one.
459
+
Postgres MCP Pro performs a limited form of workload compression by normalizing queries so that those generated from the same template appear as one.
442
460
It weights each query equally, a simplification that works when the benefits to indexing are large.
443
461
444
462
2.*Generate candidate indexes*
@@ -491,7 +509,7 @@ This give the LLM additional context that it can use when responding to the inde
491
509
### Database Health
492
510
493
511
Database health checks identify tuning opportunities and maintenance needs before they lead to critical issues.
494
-
In the present release, Postgres Pro adapts the database health checks directly from [PgHero](https://github.com/ankane/pghero).
512
+
In the present release, Postgres MCP Pro adapts the database health checks directly from [PgHero](https://github.com/ankane/pghero).
495
513
We are working to fully validate these checks and may extend them in the future.
496
514
497
515
-*Index Health*. Looks for unused indexes, duplicate indexes, and indexes that are bloated. Bloated indexes make inefficient use of database pages.
@@ -516,7 +534,7 @@ We are working to fully validate these checks and may extend them in the future.
516
534
517
535
### Postgres Client Library
518
536
519
-
Postgres Pro uses [psycopg3](https://www.psycopg.org/) to connect to Postgres using asynchronous I/O.
537
+
Postgres MCP Pro uses [psycopg3](https://www.psycopg.org/) to connect to Postgres using asynchronous I/O.
520
538
Under the hood, psycopg3 uses the [libpq](https://www.postgresql.org/docs/current/libpq.html) library to connect to Postgres, providing access to the full Postgres feature set and an underlying implementation fully supported by the Postgres community.
521
539
522
540
Some other Python-based MCP servers use [asyncpg](https://github.com/MagicStack/asyncpg), which may simplify installation by eliminating the `libpq` dependency.
@@ -529,7 +547,7 @@ We remain open to revising this decision in the future.
529
547
530
548
### Connection Configuration
531
549
532
-
Like the [Reference PostgreSQL MCP Server](https://github.com/modelcontextprotocol/servers/tree/main/src/postgres), Postgres Pro takes Postgres connection information at startup.
550
+
Like the [Reference PostgreSQL MCP Server](https://github.com/modelcontextprotocol/servers/tree/main/src/postgres), Postgres MCP Pro takes Postgres connection information at startup.
533
551
This is convenient for users who always connect to the same database but can be cumbersome when users switch databases.
534
552
535
553
An alternative approach, taken by [PG-MCP](https://github.com/stuzero/pg-mcp-server), is provide connection details via MCP tool calls at the time of use.
@@ -566,15 +584,15 @@ AI amplifies longstanding challenges of protecting databases from a range of thr
566
584
Whether the threat is accidental or malicious, a similar security framework applies, with aims that fall into three categories: confidentiality, integrity, and availability.
567
585
The familiar tension between convenience and safety is also evident and pronounced.
568
586
569
-
Postgres Pro's protected SQL execution mode focuses on integrity.
587
+
Postgres MCP Pro's protected SQL execution mode focuses on integrity.
570
588
In the context of MCP, we are most concerned with LLM-generated SQL causing damage—for example, unintended data modification or deletion, or other changes that might circumvent an organization's change management process.
571
589
572
590
The simplest way to provide integrity is to ensure that all SQL executed against the database is read-only.
573
591
One way to do this is by creating a database user with read-only access permissions.
574
592
While this is a good approach, many find this cumbersome in practice.
575
-
Postgres does not provide a way to place a connection or session into read-only mode, so Postgres Pro uses a more complex approach to ensure read-only SQL execution on top of a read-write connection.
593
+
Postgres does not provide a way to place a connection or session into read-only mode, so Postgres MCP Pro uses a more complex approach to ensure read-only SQL execution on top of a read-write connection.
576
594
577
-
Postgres provides a read-only transaction mode that prevents data and schema modifications.
595
+
Postgres MCP Provides a read-only transaction mode that prevents data and schema modifications.
578
596
Like the [Reference PostgreSQL MCP Server](https://github.com/modelcontextprotocol/servers/tree/main/src/postgres), we use read-only transactions to provide protected SQL execution.
579
597
580
598
To make this mechanism robust, we need to ensure that the SQL does not somehow circumvent the read-only transaction mode, say by issuing a `COMMIT` or `ROLLBACK` statement and then beginning a new transaction.
@@ -590,7 +608,7 @@ We reject any SQL that contains `commit` or `rollback` statements.
590
608
Helpfully, the popular Postgres stored procedure languages, including PL/pgSQL and PL/Python, do not allow for `COMMIT` or `ROLLBACK` statements.
591
609
If you have unsafe stored procedure languages enabled on your database, then our read-only protections could be circumvented.
592
610
593
-
At present, Postgres Pro provides two levels of protection for the database, one at either extreme of the convenience/safety spectrum.
611
+
At present, Postgres MCP Pro provides two levels of protection for the database, one at either extreme of the convenience/safety spectrum.
594
612
- "Unrestricted" provides maximum flexibility.
595
613
It is suitable for development environments where speed and flexibility are paramount, and where there is no need to protect valuable or sensitive data.
596
614
- "Restricted" provides a balance between flexibility and safety.
@@ -604,9 +622,9 @@ Restricted mode is limited to read-only operations, and we limit query execution
604
622
We may add measures in the future to make sure that restricted mode is safe to use with production databases.
605
623
606
624
607
-
## Postgres Pro Development
625
+
## Postgres MCP Pro Development
608
626
609
-
The instructions below are for developers who want to work on Postgres Pro, or users who prefer to install Postgres Pro from source.
627
+
The instructions below are for developers who want to work on Postgres MCP Pro, or users who prefer to install Postgres MCP Pro from source.
0 commit comments