CSV to PostgreSQL

Loads CSVs into PostgreSQL with validation, fast COPY loading, and detailed error reporting.
  • python

1

GitHub Stars

python

Language

6 months ago

First Indexed

2 months ago

Catalog Refreshed

Documentation & install

Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.

Installation

Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "mylocalaichat-mcp-csv-postgres": {
      "command": "uv",
      "args": [
        "tool",
        "run",
        "--from",
        "mcp-csv-postgres",
        "mcp-csv-postgres"
      ]
    }
  }
}

You can load CSV files into PostgreSQL with validation, fast bulk loading, and progress tracking using a dedicated MCP server. It validates your CSVs, uses PostgreSQL COPY for efficient inserts, and reports exact validation errors and import progress so you can trust the results.

How to use

Run the server locally or expose it for MCP clients, then invoke the tool to load a CSV into PostgreSQL. The server exposes a tool named load_csv_to_postgres that takes a CSV file path and optional database details. You can configure the MCP client to start the server using the provided stdio commands and then call the tool with the appropriate arguments.

How to install

Prerequisites: ensure you have Python and the MCP runtime available. Install the CSV to PostgreSQL MCP server package from PyPI, or use the development workflow if you are building from source.

pip install mcp-csv-postgres

Or using the MCP runtime tool:

uv pip install mcp-csv-postgres

Configuration and operation

To run the MCP server locally, you start the server via the MCP runtime (uv) and register the server under a name such as mcp_csv_postgres. The following configurations illustrate how you wire the server into your MCP client for two common scenarios.

{
  "mcpServers": {
    "mcp_csv_postgres": {
      "command": "uv",
      "args": [
        "tool",
        "run",
        "--from",
        "mcp-csv-postgres",
        "mcp-csv-postgres"
      ]
    }
  }
}
{
  "mcpServers": {
    "mcp_csv_postgres_dev": {
      "command": "uv",
      "args": [
        "tool",
        "run",
        "--from",
        "/path/to/mcp-csv-postgres",
        "--python",
        "3.10",
        "mcp-csv-postgres"
      ]
    }
  }
}

How to run the server and load a CSV

Start the MCP server using the stdio approach shown above, then call the load_csv_to_postgres tool with the path to your CSV. The tool accepts the following parameters: file_path (required), dbname (optional, defaults to csvimports), host (optional), port (optional), user (optional), password (optional), and table_name (optional; if not provided, it is derived from the filename). The server returns a success message with the database, table, and number of rows loaded, or an error with detailed validation or database information.

Testing and examples

Quickly test the server by running the test sequence that creates sample CSVs, loads them into PostgreSQL, and verifies error reporting. The test harness demonstrates validation errors and detailed progress output.

There is a sample dataset available for manual experimentation. You can drive the tool from Python by calling the tool function that executes load_csv_to_postgres with a sample file, then inspect the output text for success messages.

Development and testing notes

The server is structured to validate CSV structure and provide exact error details, perform efficient loading using PostgreSQL COPY, and track progress with a progress indicator. If a validation error occurs, you will receive the precise line and column information to fix the CSV before reloading.

Available tools

load_csv_to_postgres

Loads a CSV file into PostgreSQL with validation, progress tracking, and optional database/table configuration. Returns a success message with database, table, and rows loaded or a detailed error message for validation or database issues.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational