MCP server for Nile's Postgres platform - Manage and query Postgres databases, tenants, users, auth using LLMs
<p align="center"> <a href="https://thenile.dev" target="_blank"><img width="96px" src="https://www.thenile.dev/about-logo.png" /></a> <h2 align="center">Nile MCP Server <br/> <img src="https://img.shields.io/npm/v/@niledatabase/server"/> </h2> <p align="center"> <a href="https://thenile.dev/docs/ai-embeddings/nile-mcp-server"><strong>Explore the Documentation ↗️</strong></a> <br /> <br /> <a href="https://discord.gg/akRKRPKA">Join our Discord Community</a> 🔵 <a href="https://thenile.dev">Visit the Nile Website</a> 🔵 <a href="https://github.com/orgs/niledatabase/discussions">Report Issues and Suggest Enhancements</a> </p> </p> [](https://smithery.ai/server/@niledatabase/nile-mcp-server) # Unleash the Power of LLMs with Nile: An Expert's Guide to the Model Context Protocol (MCP) Server This document provides an in-depth guide to the Nile MCP Server, a robust implementation of the Model Context Protocol (MCP) designed to seamlessly integrate Large Language Models (LLMs) with the Nile database platform. This server empowers LLM applications with direct access to your data, enabling sophisticated AI-driven workflows. ## Core Capabilities The Nile MCP Server offers a comprehensive suite of features, meticulously crafted for optimal performance and ease of integration: * **Database Lifecycle Management:** Effortlessly create, list, retrieve details, and delete databases within your Nile environment. * **Secure Credential Handling:** Generate and manage database credentials with robust security protocols. * **Geographic Region Selection:** Dynamically list available regions for database deployment, optimizing for latency and compliance. * **Direct SQL Query Execution:** Execute complex SQL queries directly against your Nile databases, unlocking powerful data analysis capabilities. * **Full MCP Compliance:** Adherence to the Model Context Protocol ensures seamless interoperability with a wide range of LLM applications. * **TypeScript Foundation:** Built with TypeScript, guaranteeing type safety, maintainability, and a superior developer experience. * **Comprehensive Error Management:** Benefit from detailed error handling and informative messages, streamlining debugging and issue resolution. * **Rigorous Testing:** A comprehensive test suite, powered by Jest, ensures the reliability and stability of the server. * **Automated Environment Configuration:** Streamlined configuration through automatic loading of environment variables from `.env` files. * **Schema-Driven Input Validation:** Robust input validation using Zod, preventing errors and ensuring data integrity. ## Installation: A Step-by-Step Guide ### Stable Release For production environments, install the stable version: ```bash npm install @niledatabase/nile-mcp-server
To explore the latest features and enhancements, install the alpha/preview version:
npm install @niledatabase/nile-mcp-server@alpha
This command installs the package within your node_modules
directory (e.g., node_modules/@niledatabase/nile-mcp-server/dist/
).
For granular control and customization:
# Clone the repository git clone https://github.com/yourusername/nile-mcp-server.git cd nile-mcp-server # Install dependencies npm install # Build the project npm run build
Choose the method that best suits your development or production needs:
Direct Node Execution:
node dist/index.js
Development Mode (with Hot Reloading):
npm run dev
Upon successful startup, the server will log key initialization steps:
To gracefully shut down the server, press Ctrl+C
.
Look for the following log messages to confirm the server is running correctly:
[info] Starting Nile MCP Server...
[info] Loading environment variables...
[info] Environment variables loaded successfully
[info] Creating server instance...
[info] Tools initialized successfully
[info] Setting up stdio transport...
[info] Server started successfully
These logs indicate that the server is ready to receive commands from LLM clients like Claude Desktop.
Create a .env
file in the root directory to store your Nile credentials:
NILE_API_KEY=your_api_key_here NILE_WORKSPACE_SLUG=your_workspace_slug
To obtain your Nile API key, log in to the Nile console, navigate to your workspace's Security section, and generate a new key.
npm run build
{ "mcpServers": { "nile-database": { "command": "node", "args": [ "/path/to/your/nile-mcp-server/dist/index.js" ], "env": { "NILE_API_KEY": "your_api_key_here", "NILE_WORKSPACE_SLUG": "your_workspace_slug" } } } }
Important: Replace the placeholders with your actual values:
/path/to/your/nile-mcp-server
: The absolute path to your project directory.your_api_key_here
: Your Nile API key.your_workspace_slug
: Your Nile workspace slug.npm run build
Open Cursor.
Navigate to Settings (⌘,) > Features > MCP Servers.
Click "Add New MCP Server".
Configure the server:
Name: nile-database
(or any descriptive name).
Command:
env NILE_API_KEY=your_key NILE_WORKSPACE_SLUG=your_workspace node /absolute/path/to/nile-mcp-server/dist/index.js
Important: Replace the placeholders with your actual values:
your_key
: Your Nile API key.your_workspace
: Your Nile workspace slug./absolute/path/to
: The absolute path to your project directory.Click "Save".
Verify the green indicator confirms a successful connection.
Restart Cursor for the changes to take effect.
The server supports two distinct operational modes:
This mode leverages standard input/output for communication, ensuring compatibility with Claude Desktop and Cursor.
Server-Sent Events (SSE) mode enables real-time, event-driven communication over HTTP.
To enable SSE mode:
MCP_SERVER_MODE=sse
in your .env
file.http://localhost:3000/sse
http://localhost:3000/messages
Example SSE usage with curl
:
# In terminal 1 - Listen for events curl -N http://localhost:3000/sse # In terminal 2 - Send commands curl -X POST http://localhost:3000/messages \ -H "Content-Type: application/json" \ -d '{ "type": "function", "name": "list-databases", "parameters": {} }'
After configuring the MCP server in Cursor, use natural language to interact with your Nile databases.
Create a new database named "my_app" in AWS_US_WEST_2 region
List all my databases
Get details for database "my_app"
Delete database "test_db"
Create a users table in my_app database with columns:
- tenant_id (UUID, references tenants)
- id (INTEGER)
- email (VARCHAR, unique per tenant)
- name (VARCHAR)
- created_at (TIMESTAMP)
Create a products table in my_app database with columns:
- tenant_id (UUID, references tenants)
- id (INTEGER)
- name (VARCHAR)
- price (DECIMAL)
- description (TEXT)
- created_at (TIMESTAMP)
Execute this query on my_app database:
SELECT * FROM users WHERE tenant_id = 'your-tenant-id' LIMIT 5
Run this query on my_app:
INSERT INTO users (tenant_id, id, email, name)
VALUES ('tenant-id', 1, '[email protected]', 'John Doe')
Show me all products in my_app database with price > 100
Show me the schema for the users table in my_app database
Add a new column 'status' to the users table in my_app database
Create an index on the email column of the users table in my_app
The server provides a rich set of tools for interacting with Nile databases:
create-database
name
(string): Database name.region
(string): AWS_US_WEST_2
(Oregon) or AWS_EU_CENTRAL_1
(Frankfurt).list-databases
get-database
name
(string): Database name.delete-database
name
(string): Database name.list-credentials
databaseName
(string): Database name.create-credential
databaseName
(string): Database name.list-regions
execute-sql
databaseName
(string): Database name.query
(string): SQL query to execute.connectionString
(string, optional): Pre-existing connection string.read-resource
databaseName
(string): Database name.resourceName
(string): Resource name (table/view).list-resources
databaseName
(string): Database name.list-tenants
databaseName
(string): Database name.create-tenant
databaseName
(string): Database name.tenantName
(string): Name for the new tenant.delete-tenant
databaseName
(string): Database name.tenantName
(string): Name for the tenant.Here are example commands for Claude Desktop:
# Database Management
Please create a new database named "my-app" in the AWS_US_WEST_2 region.
Can you list all my databases?
Get the details for database "my-app".
Delete the database named "test-db".
# Connection String Management
Get a connection string for database "my-app".
# Connection string format: postgres://<user>:<password>@<region>.db.thenile.dev:5432/<database>
# Example: postgres://cred-123:[email protected]:5432/my-app
# SQL Queries
Execute SELECT * FROM users LIMIT 5 on database "my-app"
Run this query on my-app database: SELECT COUNT(*) FROM orders WHERE status = 'completed'
Using connection string "postgres://user:pass@host:5432/db", execute this query on my-app: SELECT * FROM products WHERE price > 100
All tools return responses in a standardized format:
The server handles various error scenarios:
Claude cannot access the tools:
npm run build
).Database creation fails:
Credential operations fail:
nile-mcp-server/
├── src/
│ ├── server.ts # MCP server implementation
│ ├── tools.ts # Tool implementations
│ ├── types.ts # Type definitions
│ ├── logger.ts # Logging utilities
│ ├── index.ts # Entry point
│ └── __tests__/ # Test files
│ └── server.test.ts
├── dist/ # Compiled JavaScript
├── logs/ # Log files directory
├── .env # Environment configuration
├── .gitignore # Git ignore file
├── package.json # Project dependencies
└── tsconfig.json # TypeScript configuration
server.ts
: Main server implementation with tool registration and transport handling.tools.ts
: Implementation of database operations and SQL query execution.types.ts
: TypeScript interfaces for database operations and responses.logger.ts
: Structured logging with daily rotation and debug support.index.ts
: Server startup and environment configuration.server.test.ts
: Comprehensive test suite.# Install dependencies npm install # Build the project npm run build # Start the server in production mode node dist/index.js # Start the server using npm script npm start # Start in development mode with auto-rebuild npm run dev # Run tests npm test
npm run build
: Compiles TypeScript to JavaScript.npm start
: Starts the server in production mode.npm run dev
: Starts the server in development mode with auto-rebuild.npm test
: Runs the test suite.npm run lint
: Runs ESLint for code quality checking.npm run clean
: Removes build artifacts.The project includes a comprehensive test suite that covers:
Run the tests with:
npm test
The server uses structured logging with the following features:
🐍 ☁️ Biomedical research server providing access to PubMed, ClinicalTrials.gov, and MyVariant.info.
🐍 MCP server that provides SQL analysis, linting, and dialect conversion using [SQLGlot](https://github.com/tobymao/sqlglot)
🐍 🏠 All-in-one MCP server for Postgres development and operations, with tools for performance analysis, tuning, and health checks
Supabase MCP Server with support for SQL query execution and database exploration tools