-
Notifications
You must be signed in to change notification settings - Fork 0
HTTP Transport
This page explains how to run mysql-mcp as an HTTP server using Server-Sent Events (SSE) for MCP protocol communication.
Use HTTP mode when:
- Deploying the server to a remote location (cloud, Docker container)
- Multiple AI clients need to connect to the same database
- You need OAuth 2.1 authentication for enterprise security
- Running the server as a standalone service accessible over a network
Use stdio mode (default) when:
- Running locally with Claude Desktop or Cursor IDE
- Single-user development environment
- Simplest setup with no network configuration needed
💡 Tip: Most users should use stdio mode. HTTP mode is for advanced deployments.
# Build the project first
npm run build
# Start HTTP server on port 3000
node dist/cli.js --transport http --port 3000 --mysql mysql://user:password@localhost:3306/database# Run with port mapping
docker run -p 3000:3000 writenotenow/mysql-mcp \
--transport http \
--port 3000 \
--mysql mysql://user:password@host.docker.internal:3306/database| Endpoint | Method | Purpose |
|---|---|---|
/sse |
GET | Establish MCP connection via Server-Sent Events |
/messages |
POST | Send JSON-RPC messages to the server |
/health |
GET | Health check endpoint (returns {"status":"healthy"}) |
/.well-known/oauth-protected-resource |
GET | OAuth 2.1 metadata (when OAuth is enabled) |
| Argument | Environment Variable | Default | Description |
|---|---|---|---|
--transport |
- | stdio |
Transport type (stdio, http, or sse) |
--port |
PORT |
3000 |
HTTP server port |
--host |
HOST |
localhost |
HTTP server host |
--cors-origins |
CORS_ORIGINS |
- | Comma-separated allowed origins |
node dist/cli.js \
--transport http \
--port 3000 \
--host 0.0.0.0 \
--cors-origins "https://example.com,https://app.example.com" \
--mysql mysql://user:password@localhost:3306/databaseHTTP mode supports OAuth 2.1 authentication for enterprise deployments:
node dist/cli.js \
--transport http \
--port 3000 \
--mysql mysql://user:password@localhost:3306/database \
--oauth-enabled \
--oauth-issuer https://your-keycloak.com/realms/mysql-mcp \
--oauth-audience mysql-mcpSee the OAuth page for complete setup instructions.
Test your HTTP server with MCP Inspector:
# Start the server
node dist/cli.js --transport http --port 3000 --mysql mysql://...
# In another terminal, connect Inspector
npx @modelcontextprotocol/inspector http://localhost:3000/sseTo connect a custom MCP client to your HTTP server:
-
Establish SSE connection: Send a GET request to
/sse - Receive messages: Listen for Server-Sent Events on the connection
-
Send messages: POST JSON-RPC messages to
/messages
Example using curl:
# Health check
curl http://localhost:3000/health
# Establish SSE connection (will stream events)
curl -N http://localhost:3000/sse
# Send a message (in another terminal)
curl -X POST http://localhost:3000/messages \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'# Build image
docker build -t mysql-mcp .
# Run container with port mapping
docker run -d \
--name mysql-mcp-server \
-p 3000:3000 \
mysql-mcp \
--transport http \
--port 3000 \
--mysql mysql://user:password@host.docker.internal:3306/databaseversion: '3.8'
services:
mysql-mcp:
image: writenotenow/mysql-mcp:latest
ports:
- "3000:3000"
command:
- --transport
- http
- --port
- "3000"
- --mysql
- mysql://user:password@mysql:3306/database
environment:
- MYSQL_POOL_SIZE=20
depends_on:
- mysql
mysql:
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: database
volumes:
- mysql-data:/var/lib/mysql
volumes:
mysql-data:- Push Docker image to ECR
- Create ECS task definition with port 3000 exposed
- Configure ALB to route traffic to the container
- Set environment variables for MySQL connection
# Build and push to GCR
gcloud builds submit --tag gcr.io/PROJECT_ID/mysql-mcp
# Deploy to Cloud Run
gcloud run deploy mysql-mcp \
--image gcr.io/PROJECT_ID/mysql-mcp \
--port 3000 \
--set-env-vars MYSQL_HOST=...,MYSQL_USER=...,MYSQL_PASSWORD=... \
--command "--transport,http,--port,3000"az container create \
--resource-group myResourceGroup \
--name mysql-mcp \
--image writenotenow/mysql-mcp:latest \
--ports 3000 \
--environment-variables \
MYSQL_HOST=... \
MYSQL_USER=... \
MYSQL_PASSWORD=... \
--command-line "--transport http --port 3000"Problem: Client cannot connect to /sse endpoint
Solutions:
- Verify server is running:
curl http://localhost:3000/health - Check firewall rules allow port 3000
- Ensure
--host 0.0.0.0if connecting from another machine - Check Docker port mapping:
-p 3000:3000
Problem: Browser-based clients show CORS errors
Solution: Add allowed origins:
--cors-origins "https://your-client-domain.com"Problem: Requests return 401 Unauthorized
Solutions:
- Verify OAuth issuer URL is correct
- Check token audience matches
--oauth-audience - Ensure JWKS URI is accessible from the server
- See OAuth troubleshooting section
- Configuration - General configuration options
- OAuth - OAuth 2.1 authentication setup
- MCP-Inspector - Testing with MCP Inspector
- MCP Protocol Specification - Official MCP docs
mysql-mcp • v2.0.0 • MIT License
mysql-mcp Wiki
Getting Started
Tools
Advanced Topics
Links