Direct Database Access MCP Server
Enables chat-based interaction with PostgreSQL databases, supporting table listing, queries, write operations, and saved parameterized queries, deployable as a remote MCP server via Cloudflare Workers.
README
About
- MCP SERVER where allow you chat with your database(Postgresql) using AI
- You can deploy this MCP server as a remote MCP server using Cloudflare Workers
Key features
- List the tables of your database
- Query the tables of your database
- Execute write operations like INSERT/UPDATE/DELETE (privileged users only)
- Create queries and saved to execute later. PS: you can create queries with parameters and save the queries to execute later.
- All operations sent to Cloudflare Workers will check the api-key sent in the header
Folder structure
- src/
- database/ // Database connection and utils
- tools/ // Tools implementation
- repositories/ // Repositories implementation
Transport Protocols
This MCP server supports both modern and legacy transport protocols:
/mcp- Streamable HTTP (recommended): Uses a single endpoint with bidirectional communication, automatic connection upgrades, and better resilience for network interruptions/sse- Server-Sent Events (legacy): Uses separate endpoints for requests/responses, maintained for backward compatibility
For new implementations, use the /mcp endpoint as it provides better performance and reliability.
Prerequisites
- Node.js installed on your machine
- A Cloudflare account (free tier works)
- A PostgreSQL database (local or hosted)
Step 1: Install Wrangler CLI
Install Wrangler globally to manage your Cloudflare Workers:
npm install -g wrangler
Step 2: Authenticate with Cloudflare
Log in to your Cloudflare account:
wrangler login
This will open a browser window where you can authenticate with your Cloudflare account.
Step 3: Clone and Install dependencies
Clone the repo directly & install dependencies: pnpm install.
Environment Variables Setup
Before running the MCP server, you need to configure several environment variables for authentication and database access.
Create Environment Variables File
-
Create your
.dev.varsfile from the example:cp .dev.vars.example .dev.vars -
Configure all required environment variables in
.dev.vars:ACCESS_TOKEN=random_value_to_use_as_api_key DATABASE_URL=postgresql://username:password@localhost:5432/database_name
Database setup
- To save the queries to execute later you will need execute the SQL script on your database. PS: you need to execute the script named instructions.sql only once.
Run the server locally
wrangler dev
This makes the server available at http://localhost:8792
Production Deployment
Deploy
Deploy the MCP server to make it available on your workers.dev domain
wrangler deploy
Access the remote MCP server from Kilo Code and Vscode
You can access the remote MCP server from Kilo Code and Vscode using the following configuration:
// Kilocode MCP
{
"mcpServers": {
"direct-database-mcp-server-prod": {
"url": "url_cloudflare_workers_generated_after_deployed/sse",
"headers": {
"api-key": "Bearer same_value_of_ACCESS_TOKEN"
}
}
}
}
// Vscode MCP
{
"servers": {
"direct-database-mcp-server-prod": {
"url": "https://my-mcp-server.tiagorosadacost.workers.dev/sse",
"headers": {
"api-key": "Bearer 701cdccb-e605-423f-a778-66ed0698117f"
}
}
}
}
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.