CoryFrench/openai_mcp_server
If you are the rightful owner of openai_mcp_server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The PostgreSQL MCP Server is a versatile server that provides tools for interacting with PostgreSQL databases, supporting both MCP and HTTP modes for different integration needs.
PostgreSQL MCP Server
A Model Context Protocol (MCP) server that provides PostgreSQL database tools. This server can run in two modes:
- MCP Mode: Standard JSON-RPC 2.0 protocol for OpenAI integration
- HTTP Mode: REST API for microservices architecture
Features
- PostgreSQL Tools: Query and explore PostgreSQL databases with automatic server detection
- Dual Transport: Supports both stdio (MCP) and HTTP transports
- Automatic Server Detection: Switches between local and remote PostgreSQL servers
- Docker Ready: Containerized for microservices deployment
Installation
- Install dependencies:
npm install
- Create environment configuration:
cp .env.example .env
- Edit
.env
with your PostgreSQL credentials:
# PostgreSQL Configuration
PG_LOCAL_HOST=10.0.2.221
PG_REMOTE_HOST=50.172.126.210
PG_PORT=5432
PG_USER=cursor
PG_PASSWORD=your_password
PG_DATABASE=postgres
PG_SSL=false
# Server Configuration
SERVER_NAME=PostgreSQL MCP Server
SERVER_VERSION=1.0.0
Usage
For OpenAI Integration (MCP Protocol)
Run the server in MCP mode using stdio transport:
npm run mcp
# or
npm start
Then configure OpenAI to use this server:
import { MCPServerStdio } from 'openai/mcp';
const server = new MCPServerStdio({
params: {
command: "npm",
args: ["run", "mcp"],
cwd: "/path/to/openai_mcp_server"
}
});
For Microservices (HTTP API)
Run the server in HTTP mode:
npm run http
The server will be available at http://localhost:14500
with these endpoints:
GET /health
- Server health checkGET /tools
- List available toolsPOST /execute
- Execute a toolGET /
- Server information
Example tool execution:
curl -X POST http://localhost:14500/execute \
-H "Content-Type: application/json" \
-d '{
"toolName": "postgres_ultra_simple",
"arguments": {"query": "SELECT version();"}
}'
Docker Deployment
The included Docker setup runs in HTTP mode for microservices integration:
docker-compose up openai-mcp-server
Access via reverse proxy: http://localhost/api/openai-mcp/
Available Tools
PostgreSQL Tools
test_tool
: Simple test tool for debuggingpostgres_ultra_simple
: Execute basic SQL queriespostgres_single_table
: Get information about a specific tablepostgres_list_tables
: List all database tablespostgres_describe_table
: Get detailed table schemapostgres_query_builder
: Advanced query building and executionpostgres_connection_test
: Test database connectivitypostgres_performance_stats
: Get database performance metrics
Smart Features
Automatic PostgreSQL Server Detection
The system automatically detects which PostgreSQL server is accessible:
- Attempts connection to local server (
PG_LOCAL_HOST
) - Falls back to remote server (
PG_REMOTE_HOST
) if local fails - Provides clear error messages if both fail
Flexible Configuration
- Password is optional (warns but doesn't fail if missing)
- Supports both local development and production environments
- Configurable SSL settings for secure connections
Development
Available Scripts
npm start
- Run MCP server (stdio transport)npm run mcp
- Run MCP server (stdio transport)npm run http
- Run HTTP API servernpm run dev
- Development mode with auto-restart (MCP)npm run dev:mcp
- Development mode (MCP)npm run dev:http
- Development mode (HTTP)
Project Structure
openai_mcp_server/
āāā server.mjs # MCP server (stdio transport)
āāā http-server.mjs # HTTP API server
āāā run-server.js # Executable wrapper
āāā tools/ # Tool implementations
ā āāā index.mjs # Tool registry
ā āāā postgres/ # PostgreSQL tools
ā āāā test-tool.mjs # Test tool
āāā utils/ # Utilities
ā āāā config.mjs # Configuration management
ā āāā logging.mjs # Logging utilities
āāā .env # Environment variables
Security
- Read-only database operations (SELECT queries only)
- Environment variable validation
- Secure container configuration with non-root user
- CORS headers for web integration
Troubleshooting
Connection Issues
- Verify PostgreSQL credentials in
.env
- Check network connectivity to database servers
- Ensure PostgreSQL server allows connections from your IP
- Review server logs for detailed error messages
Docker Issues
- Ensure containers are running:
docker-compose ps
- Check logs:
docker-compose logs openai-mcp-server
- Restart if needed:
docker-compose restart openai-mcp-server
License
ISC