A Go implementation of the Model Context Protocol (MCP) server that provides database connectivity tools for LLMs. This server enables AI assistants like Claude to interact with PostgreSQL and MySQL databases through a standardized protocol.
- Pure HTTP Transport: No SSE, just simple request-response over HTTP POST
- Database Support: PostgreSQL and MySQL adapters with full query capabilities
- MCP Protocol: Implements MCP specification version 2024-11-05
- Extensible Architecture: Easy to add new database adapters
- Session Management: Optional session support with configurable TTL
- OAuth Mock: Built-in OAuth endpoints for Claude Code compatibility
- Docker Support: Run in containers with proper host database access
- Clone the repository:
git clone https://github.com/yourusername/mcp-storage.git
cd mcp-storage
- Set up environment variables:
cp .env.example .env
# Edit .env to add your database connection strings
- Build and run:
make build
make run
# Build and run with Docker Compose
docker-compose up -d
# View logs
docker-compose logs -f mcp-storage
# Stop
docker-compose down
Create a .env
file based on .env.example
:
# Server Configuration
PORT=5435
HOST=0.0.0.0
LOG_LEVEL=info
# PostgreSQL Adapter (optional)
POSTGRES_URL=postgresql://user:password@localhost:5432/dbname?sslmode=disable
# MySQL Adapter (optional)
MYSQL_URL=user:password@tcp(localhost:3306)/dbname?charset=utf8mb4&parseTime=True
Control log verbosity with the LOG_LEVEL environment variable:
# Available levels: trace, debug, info, warn, error
LOG_LEVEL=debug ./mcp-storage
postgres_schemas
- List all schemas in the databasepostgres_schema_ddls
- Get DDL statements for a schemapostgres_query_select
- Execute SELECT queries
mysql_query_select
- Execute SELECT queriesmysql_schema_ddls
- Get DDL statements for a schema
# Test with Python client
make test-mcp
# Test with debug output
make test-mcp-debug
# Test specific tool
python3 test_client.py --tool postgres_schemas
# Health check
curl http://localhost:5435/health
# Initialize
curl -X POST http://localhost:5435/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "Test Client",
"version": "1.0.0"
}
}
}'
/mcp-storage/
├── main.go # Entry point
├── config.go # Environment configuration
├── adapter.go # Database adapter interface
├── postgres.go # PostgreSQL implementation
├── mysql.go # MySQL implementation
├── protocol.go # MCP protocol types
├── jsonrpc.go # JSON-RPC handler
├── transport.go # HTTP transport layer
├── tools.go # Tool implementations
├── session.go # Session management
├── logger.go # Logging utilities
├── test_client.py # Python test client
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose setup
└── Makefile # Build commands
- Create a new adapter file (e.g.,
redis.go
) - Implement the
DatabaseAdapter
interface - Register in
main.go
- Add tools in
tools.go
make build # Build the server
make run # Run locally
make run-debug # Run with debug logging
make lint # Run linters
make clean # Clean build artifacts
make docker-build # Build Docker image
make docker-up # Start with Docker
make docker-logs # View Docker logs
This server is designed to work with Claude Desktop via the MCP protocol. Configure it in Claude's settings to enable database access through the chat interface.
Add to your Claude Desktop config:
{
"mcpServers": {
"mcp-storage": {
"command": "docker",
"args": ["run", "-p", "5435:5435", "--env-file", ".env", "mcp-storage"],
"type": "http",
"url": "http://localhost:5435"
}
}
}
The server also works with Cursor AI. Add the following to your Cursor settings:
- Open Cursor Settings (Cmd/Ctrl + ,)
- Search for "MCP" in the settings
- Add a new MCP server with these settings:
- Name: mcp-storage
- Command: http://localhost:5435
- Transport: HTTP
Or add directly to your Cursor configuration file:
{
"mcpServers": {
"mcp-storage": {
"transport": "http",
"url": "http://localhost:5435"
}
}
}
- Run the server:
docker-compose up -d
- Restart Cursor to connect to the MCP server
- The database tools will be available in your AI chat
- Always use read-only database credentials when possible
- The server only allows SELECT queries for safety
- Use SSL/TLS connections for production databases
- Never expose the server directly to the internet
- Validate and sanitize all inputs
MIT License - see LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.