
netanelbollag/simple-psql-mcp
Developer toolsЭта страница переведена автоматически. Технические детали смотрите в оригинале. Открыть оригинал
A beginner-friendly MCP server template featuring a PostgreSQL connector with clean, easy-to-understand code.
Обзор
This is a template project for those looking to build their own MCP servers. I designed it to be dead simple to understand and adapt - the code is straightforward with MCP docs attached so you can quickly get up to speed. TL;DR - It's a way to write plugins for AI Model Context Protocol (MCP) is a standard way for LLMs to interact with external tools and data. In a nutshell: - allow the LLM to execute commands (like running a database query) - are data you can attach to conversations (like attaching a file to a prompt) - are templates that generate consistent LLM instructions 1. - execute_query - Run SQL queries against your database - test_connection - Verify the database connection is working 2. - db://tables - List of all tables in the schema - db://tables/{table_name} - Schema information for a specific table - db://schema - Complete schema information for all tables in the database 3.
README
Показан фрагмент оригинального README. Открыть оригинал.
Simple PostgreSQL MCP Server
This is a template project for those looking to build their own MCP servers. I designed it to be dead simple to understand and adapt - the code is straightforward with MCP docs attached so you can quickly get up to speed.
What is MCP?
TL;DR - It’s a way to write plugins for AI
Model Context Protocol (MCP) is a standard way for LLMs to interact with external tools and data. In a nutshell:
- Tools allow the LLM to execute commands (like running a database query)
- Resources are data you can attach to conversations (like attaching a file to a prompt)
- Prompts are templates that generate consistent LLM instructions
Features
This PostgreSQL MCP server implements:
-
Tools
execute_query- Run SQL queries against your databasetest_connection- Verify the database connection is working
-
Resources
db://tables- List of all tables in the schemadb://tables/{table_name}- Schema information for a specific tabledb://schema- Complete schema information for all tables in the database
-
Prompts
- Query generation templates
- Analytical query builders
- Based on the templates in this repo
Prerequisites
- Python 3.8+
- uv - Modern Python package manager and installer
- npx (included with Node.js)
- PostgreSQL database you can connect to
Quick Setup
-
Create a virtual environment and install dependencies:
# Create a virtual environment with uv uv venv # Activate the virtual environment source .venv/bin/activate # On Windows: .venv\Scripts\activate # Install dependencies uv pip install -r requirements.txt -
Run the server with the MCP Inspector:
# Replace with YOUR actual database credentials npx @modelcontextprotocol/inspector uv --directory . run postgres -e DSN=postgresql://username:password@hostname:port/database -e SCHEMA=publicNote: If this is your first time running npx, you’ll be prompted to approve the installation. Type ‘y’ to proceed.
After running this command, you’ll see the MCP Inspector interface launched in your browser. You should see a message like:
MCP Inspector is up and running at http://localhost:5173If the browser doesn’t open automatically, copy and paste the URL into your browser. You should see something like this:
-
Using the Inspector:
- Click the “Connect” button in the interface (unless there’s an error message in the console on the bottom left)
- Explore the “Tools”, “Resources”, and “Prompts” tabs to see available functionality
- Try clicking on listed commands or typing resource names to retrieve resources and prompts
- The interface allows you to test queries and see how the MCP server responds
-
Take a look at the official docs
Установка
npx @modelcontextprotocol/inspector uv --directory . run postgres -e DSN=postgresql://username:password@hostname:port/database -e SCHEMA=publicКонфигурация
{
"mcpServers": {
"postgres": {
"command": "/path/to/uv",
"args": [
"--directory",
"/path/to/simple-psql-mcp",
"run",
"postgres"
],
"env": {
"DSN": "postgresql://username:password@localhost:5432/my-db",
"SCHEMA": "public"
}
}
}
}