This project has been archived by its maintainers, and is no longer receiving any updates.
CSV to PostgreSQL MCP Server
An MCP (Model Context Protocol) server that loads CSV files into PostgreSQL databases with validation and progress tracking.
Features
- CSV Validation: Validates CSV structure and provides detailed error messages
- Efficient Loading: Uses PostgreSQL COPY command for fast bulk loading
- Progress Tracking: Shows progress bar for long-running imports
- Flexible Configuration: Optional database name (defaults to
csvimports) - Error Reporting: Exact line numbers and column information for validation errors
Installation
From PyPI
pip install csv-postgres-loader
Or using uv:
uv pip install csv-postgres-loader
From Source
Clone the repository and install with uv:
git clone https://github.com/raviramadoss/mcp-csv-postgres.git
cd mcp-csv-postgres
uv sync --all-extras
Usage
As MCP Server
Option 1: After installing from PyPI
Add to your Claude Desktop configuration file (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"csv-postgres-loader": {
"command": "uv",
"args": [
"tool",
"run",
"--from",
"csv-postgres-loader",
"csv-postgres-loader"
]
}
}
}
Option 2: For local development
{
"mcpServers": {
"csv-postgres-loader": {
"command": "uv",
"args": [
"tool",
"run",
"--from",
"/path/to/mcp-csv-postgres",
"--python",
"3.10",
"csv-postgres-loader"
]
}
}
}
Or run directly from command line:
csv-postgres-loader
Tool: load_csv_to_postgres
Loads a CSV file into PostgreSQL database.
Parameters:
file_path(required): Path to the CSV filedbname(optional): Database name (default:csvimports)host(optional): PostgreSQL host (default:localhost)port(optional): PostgreSQL port (default:5432)user(optional): PostgreSQL user (default:postgres)password(optional): PostgreSQL passwordtable_name(optional): Table name (derived from filename if not provided)
Returns:
- Success message with database name, table name, and rows loaded
- Error message with detailed validation or database errors
Testing the Server
Quick Test
Run the test script to see the server in action:
uv run python test_server.py
This will:
- Create sample CSV files
- Test loading them into PostgreSQL
- Test validation error reporting
- Show detailed output
Manual Testing with Sample Data
A sample CSV file is provided in sample_data.csv. To test manually:
# In Python/IPython
import asyncio
from csv_postgres_loader.server import call_tool
result = asyncio.run(call_tool(
"load_csv_to_postgres",
{"file_path": "sample_data.csv"}
))
print(result[0].text)
Using with MCP Inspector
To test with the MCP Inspector tool:
npx @modelcontextprotocol/inspector uv run csv-postgres-loader
VS Code Launch Configurations
The .vscode/launch.json includes:
- Run MCP Server: Start the server in debug mode
- Test MCP Server with Sample CSV: Run the test script
- Run All Tests: Execute full test suite
- Run Specific Test: Debug a single test file
Development
Running Tests
uv run pytest
Code Coverage
uv run pytest --cov-report=html
Coverage report will be available in htmlcov/index.html.
Current coverage: >90%
Pre-commit Hooks
Pre-commit hooks are configured to run tests before each commit:
uv run pre-commit install
uv run pre-commit run --all-files
Architecture
Modules
-
validator.py: CSV validation with detailed error reporting
- File existence and readability checks
- CSV structure validation
- Row consistency validation
- Automatic dialect detection
-
database.py: PostgreSQL database operations
- Connection management
- Database creation
- Table creation from CSV headers
- Row counting
-
loader.py: CSV loading using COPY command
- Progress tracking with tqdm
- Efficient bulk loading
- Error handling and rollback
-
server.py: MCP server implementation
- stdio transport
- Tool registration
- Error handling
Error Handling
The server provides detailed error messages:
- Validation Errors: Exact line numbers and description of CSV issues
- Database Errors: Connection, permission, and SQL errors
- File Errors: Permission, encoding, and file not found errors
Examples
Loading a CSV file
{
"tool": "load_csv_to_postgres",
"arguments": {
"file_path": "/path/to/data.csv"
}
}
With custom database
{
"tool": "load_csv_to_postgres",
"arguments": {
"file_path": "/path/to/data.csv",
"dbname": "mydb",
"table_name": "my_table"
}
}
License
MIT
Metadata
Release files for csv-postgres-loader 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| csv_postgres_loader-0.1.0.tar.gz | 7.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| csv_postgres_loader-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.9 kB
Release files / csv_postgres_loader-0.1.0.tar.gz
| Download URL | csv_postgres_loader-0.1.0.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d7098b6875078b4b6ebcfe241275e07c24ffbcd31e4615f0196121b1ebcaf37f
|
|
BLAKE2b-256 checksum How to use checksums |
2b11ea5d66433786cfb053dc3beaddc0a8b3798bce9ec9d883061d338a1022ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|
Release files / csv_postgres_loader-0.1.0-py3-none-any.whl
| Download URL | csv_postgres_loader-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5b1cf66e2dcb9bc83e07881e49f8a2d42175286e2e99d26d358c2c880a78dc2f
|
|
BLAKE2b-256 checksum How to use checksums |
d93bdc239ba2f0a0617a655c5ec6cdcefe4d20d6db8d66233e1cfa9b3801f50f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|
Security for csv-postgres-loader 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.