MCPDatabases

by alvnavraii

369 downloads
Not rated
GitHub

About

MCP Server to manage PostGress and SQLite. In fact, you could use any Database Engine

Details

Author
alvnavraii
Downloads
369
Categories
Other, Database

- CRUD operations: create, read, update, delete records.
- Table management: create, alter, drop tables.
- Data migration between PostgreSQL and SQLite.
- Execute custom SQL queries for analysis.

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name MCPDatabases
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Run the MCP server with python3 main.py. Configure services in mcp_config.json or claude_desktop_config.json using command, args with --engine and --url flags for each database engine. The server exposes tools for queries, inserts, updates, deletes, and table alterations.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "mcpdatabases": {
            "SqliteManagement": {
                "command": "/home/slendy/MCPProjects/DataBase/.venv/bin/python",
                "args": [
                    "/home/slendy/MCPProjects/DataBase/main.py",
                    "--engine",
                    "sqlite",
                    "--url",
                    "sqlite:////home/slendy/MCPProjects/DataBase/ecommerce.db"
                ]
            },
            "PostgressManagement": {
                "command": "/home/slendy/MCPProjects/DataBase/.venv/bin/python",
                "args": [
                    "/home/slendy/MCPProjects/DataBase/main.py",
                    "--engine",
                    "postgresql",
                    "--url",
                    "postgresql://postgres:postgres@localhost:5433/ecommerce"
                ]
            }
        }
    }
}

McpServers

{
    "SqliteManagement": {
        "command": "/home/slendy/MCPProjects/DataBase/.venv/bin/python",
        "args": [
            "/home/slendy/MCPProjects/DataBase/main.py",
            "--engine",
            "sqlite",
            "--url",
            "sqlite:////home/slendy/MCPProjects/DataBase/ecommerce.db"
        ]
    },
    "PostgressManagement": {
        "command": "/home/slendy/MCPProjects/DataBase/.venv/bin/python",
        "args": [
            "/home/slendy/MCPProjects/DataBase/main.py",
            "--engine",
            "postgresql",
            "--url",
            "postgresql://postgres:postgres@localhost:5433/ecommerce"
        ]
    }
}

๐Ÿ—„๏ธ DataBase Project (PostgreSQL & SQLite Management)

> โšก There is an alternative version of this project with Server-Sent Events (SSE) support:
> mcpDataBasesSSE on GitHub

This project is designed to manage and migrate data between PostgreSQL and SQLite databases, making it easier to perform CRUD operations and administration for applications that require flexibility between database engines.

๐Ÿ“ Main Structure

- main.py: ๐Ÿ–ฅ๏ธ MCP server with tools to query, insert, update, delete, and modify tables in the PostgreSQL database. - connection.py: ๐Ÿ”— Manages the connection to the PostgreSQL database. - migrate_postgres_to_sqlite.py: ๐Ÿ”„ Script to migrate all tables and their data from PostgreSQL to SQLite. - ecommerce.db: ๐Ÿ—ƒ๏ธ SQLite database generated from the migration (optional).

โš™๏ธ Features

- CRUD operations: โž• Create, ๐Ÿ”Ž Read, โœ๏ธ Update, and โŒ Delete records in PostgreSQL database tables. - Table management: ๐Ÿ—๏ธ Easily create, ๐Ÿ› ๏ธ alter, and ๐Ÿ—‘๏ธ drop tables. - Data migration: ๐Ÿ”„ Automatically transfer structure and data between PostgreSQL and SQLite. - Advanced queries: ๐Ÿงฎ Run custom SQL queries for analysis or maintenance.

๐Ÿš€ Usage Examples

1. MCP Server (main.py)

- Run the MCP server to expose database management tools:
  python3 main.py
  
- Available tools: - ๐Ÿ”Ž query_db(query): Executes SELECT queries and returns results. - โž• insert_db(query): Executes INSERT statements. - โœ๏ธ update_db(query): Executes UPDATE statements. - โŒ delete_db(query): Executes DELETE statements. - ๐Ÿ—๏ธ create_table(query): Executes CREATE TABLE statements. - ๐Ÿ› ๏ธ alter_table(query): Executes ALTER TABLE statements. - ๐Ÿ—‘๏ธ drop_table(query): Executes DROP TABLE statements.

2. Data migration between databases

- Run the migration script to copy all tables and data from PostgreSQL to SQLite:
  python3 migrate_postgres_to_sqlite.py
  
- You can adapt the script to migrate data in both directions or between different schemas.

3. CRUD operation examples

- Create a record: ๐Ÿ“
  INSERT INTO users (email, password) VALUES ('user@domain.com', 'secret');
  
- Read records: ๐Ÿ”
  SELECT * FROM products WHERE is_active = TRUE;
  
- Update records: ๐Ÿ”„
  UPDATE categories SET name = 'New Technologies' WHERE id = 1;
  
- Delete records: ๐Ÿšฎ
  DELETE FROM carts WHERE created_at < '2024-01-01';
  

๐Ÿ“Š MCP Configuration (mcp_config.json or claude_desktop_config.json)

To ensure MCP tools work properly, define each service in your configuration file (e.g., ~/.codeium/windsurf/mcp_config.json or ~/.config/Claude/claude_desktop_config.json). Example:

{
  "SqliteManagement": {
    "command": "/home/slendy/MCPProjects/DataBase/.venv/bin/python",
    "args": [
      "/home/slendy/MCPProjects/DataBase/main.py",
      "--engine", "sqlite",
      "--url", "sqlite:////home/slendy/MCPProjects/DataBase/ecommerce.db"
    ]
  },
  "PostgressManagement": {
    "command": "/home/slendy/MCPProjects/DataBase/.venv/bin/python",
    "args": [
      "/home/slendy/MCPProjects/DataBase/main.py",
      "--engine", "postgresql",
      "--url", "postgresql://user:password@localhost:5432/ecommerce"
    ]
  }
}

- Change the paths, credentials, and ports according to your environment.
- By default, PostgreSQL uses port 5432. If you already have a database on that port, you can specify another (e.g., 5433).
- Do not include real passwords in the configuration file; replace user and password with the appropriate values.
- You can add more services for other engines or databases.
- The block name (e.g., SqliteManagement) will be the MCP tool identifier.

๐Ÿ“ˆ Dependencies

- Python 3.8+ - psycopg2-binary - sqlite3 - PostgreSQL (server and configured database)

๐Ÿ“ Notes

- Make sure to properly configure the MCP services in your mcp_config.json (or claude_desktop_config.json) file following the example above. - Also configure the connection credentials in connection.py according to your environment and database. - After changes to the database structure, restart the MCP server to avoid connection issues. - You can adapt the scripts to migrate or manage other catalogs as needed.

---

No reviews yet โ€” be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.