Skip to content

Commit 890b879

Browse files
authored
Add support for mysql closes IBM#925 (IBM#927)
* Add support for mysql closes IBM#925 Signed-off-by: Mihai Criveti <[email protected]> * Add support for mysql closes IBM#925 Signed-off-by: Mihai Criveti <[email protected]> * Add support for mysql / mariadb closes IBM#925 Signed-off-by: Mihai Criveti <[email protected]> --------- Signed-off-by: Mihai Criveti <[email protected]>
1 parent 92f531e commit 890b879

21 files changed

+943
-175
lines changed

.env.example

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ DOCS_ALLOW_BASIC_AUTH=false
1515

1616
# Database Configuration
1717
# Optimized for v0.7.0 multitenancy with enhanced connection pooling and timeouts
18-
# macOS note:
19-
# If you see "sqlite3.OperationalError: disk I/O error" on macOS when running
18+
19+
# SQLite (default) - good for development and small deployments
20+
# macOS note: If you see "sqlite3.OperationalError: disk I/O error" on macOS when running
2021
# `make serve`, move the DB to a safe APFS path (avoid iCloud/Dropbox/OneDrive/Google Drive,
2122
# network shares, or external exFAT) and use an absolute path, for example:
2223
# DATABASE_URL=sqlite:////Users/$USER/Library/Application Support/mcpgateway/mcp.db
2324
DATABASE_URL=sqlite:///./mcp.db
25+
26+
# PostgreSQL - recommended for production deployments
2427
# DATABASE_URL=postgresql://postgres:mysecretpassword@localhost:5432/mcp
28+
29+
# MariaDB/MySQL - fully supported for production
30+
# For container deployment: mysql+pymysql://mysql:changeme@mariadb:3306/mcp
31+
# For localhost: mysql+pymysql://mysql:changeme@localhost:3306/mcp
2532
# DATABASE_URL=mysql+pymysql://mysql:changeme@localhost:3306/mcp
2633

2734
# Database Connection Pool Configuration (optimized for v0.7.0 multitenancy)

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
7777
DB_POOL_TIMEOUT=30 # Seconds to wait for connection before timeout (default: 30)
7878
DB_POOL_RECYCLE=3600 # Seconds before recreating connection (default: 3600)
7979
```
80+
* **Complete MariaDB & MySQL Database Support** (#925) - Full production support for MariaDB and MySQL backends:
81+
```bash
82+
# MariaDB (recommended MySQL-compatible option):
83+
DATABASE_URL=mysql+pymysql://mysql:changeme@localhost:3306/mcp
84+
85+
# Docker deployment with MariaDB 12.0.2-ubi10:
86+
DATABASE_URL=mysql+pymysql://mysql:changeme@mariadb:3306/mcp
87+
```
88+
- **36+ database tables** fully compatible with MariaDB 12.0+ and MySQL 8.4+
89+
- All **VARCHAR length issues** resolved for MySQL compatibility
90+
- **Container support**: MariaDB and MySQL drivers included in all container images
91+
- **Complete feature parity** with SQLite and PostgreSQL backends
92+
- **Production ready**: Supports all MCP Gateway features including federation, caching, and A2A agents
93+
8094
* **Enhanced JWT Configuration** - Audience, issuer claims, and improved token validation:
8195
```bash
8296
# New JWT configuration options:

Containerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ COPY . /app
2424
# Including observability packages for OpenTelemetry support
2525
RUN python3 -m venv /app/.venv && \
2626
/app/.venv/bin/python3 -m pip install --upgrade pip setuptools pdm uv && \
27-
/app/.venv/bin/python3 -m uv pip install ".[redis,postgres,alembic,observability]"
27+
/app/.venv/bin/python3 -m uv pip install ".[redis,postgres,mysql,alembic,observability]"
2828

2929
# update the user permissions
3030
RUN chown -R 1001:0 /app && \

Containerfile.lite

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ COPY pyproject.toml /app/
6868
RUN set -euo pipefail \
6969
&& python3 -m venv /app/.venv \
7070
&& /app/.venv/bin/pip install --no-cache-dir --upgrade pip setuptools wheel pdm uv \
71-
&& /app/.venv/bin/uv pip install ".[redis,postgres,observability]" \
71+
&& /app/.venv/bin/uv pip install ".[redis,postgres,mysql,observability]" \
7272
&& /app/.venv/bin/pip uninstall --yes uv pip setuptools wheel pdm \
7373
&& rm -rf /root/.cache /var/cache/dnf \
7474
&& find /app/.venv -name "*.dist-info" -type d \

docker-compose.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ services:
2424
# MCP Gateway - the main API server for the MCP stack
2525
# ──────────────────────────────────────────────────────────────────────
2626
gateway:
27-
#image: ghcr.io/ibm/mcp-context-forge:0.6.0 # Use the release MCP Context Forge image
28-
image: ${IMAGE_LOCAL:-mcpgateway/mcpgateway:latest} # Use the local latest image. Run `make docker-prod` to build it.
27+
image: ghcr.io/ibm/mcp-context-forge:0.6.0 # Use the release MCP Context Forge image
28+
#image: ${IMAGE_LOCAL:-mcpgateway/mcpgateway:latest} # Use the local latest image. Run `make docker-prod` to build it.
2929
build:
3030
context: .
3131
dockerfile: Containerfile # Same one the Makefile builds
@@ -41,7 +41,7 @@ services:
4141
- HOST=0.0.0.0
4242
- PORT=4444
4343
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD:-mysecretpassword}@postgres:5432/mcp
44-
# - DATABASE_URL=mysql+pymysql://mysql:${MYSQL_PASSWORD:-changeme}@mysql:3306/mcp
44+
# - DATABASE_URL=mysql+pymysql://mysql:${MYSQL_PASSWORD:-changeme}@mariadb:3306/mcp
4545
# - DATABASE_URL=mysql+pymysql://admin:${MARIADB_PASSWORD:-changeme}@mariadb:3306/mcp
4646
# - DATABASE_URL=mongodb://admin:${MONGO_PASSWORD:-changeme}@mongodb:27017/mcp
4747
- CACHE_TYPE=redis # backend for caching (memory, redis, database, or none)
@@ -120,15 +120,23 @@ services:
120120
# volumes: [mariadbdata:/var/lib/mysql]
121121
# networks: [mcpnet]
122122

123-
# mysql:
124-
# image: mysql:8
123+
# mariadb:
124+
# image: registry.redhat.io/rhel9/mariadb-106:12.0.2-ubi10
125125
# environment:
126126
# - MYSQL_ROOT_PASSWORD=mysecretpassword
127127
# - MYSQL_DATABASE=mcp
128128
# - MYSQL_USER=mysql
129129
# - MYSQL_PASSWORD=changeme
130-
# volumes: [mysqldata:/var/lib/mysql]
130+
# volumes: ["mariadbdata:/var/lib/mysql"]
131131
# networks: [mcpnet]
132+
# ports:
133+
# - "3306:3306"
134+
# healthcheck:
135+
# test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-pmysecretpassword"]
136+
# interval: 30s
137+
# timeout: 10s
138+
# retries: 5
139+
# start_period: 30s
132140

133141
# mongodb:
134142
# image: mongo:7

docs/docs/deployment/compose.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,23 @@ curl http://localhost:4444/health # {"status":"ok"}
9898

9999
Uncomment one service block in `docker-compose.yml` and align `DATABASE_URL`:
100100

101-
| Service block | Connection string |
102-
| --------------------- | --------------------------------------------- |
103-
| `postgres:` (default) | `postgresql://postgres:...@postgres:5432/mcp` |
104-
| `mariadb:` | `mysql+pymysql://admin:...@mariadb:3306/mcp` |
105-
| `mysql:` | `mysql+pymysql://mysql:...@mysql:3306/mcp` |
106-
| `mongodb:` | `mongodb://admin:...@mongodb:27017/mcp` |
101+
| Service block | Connection string | Notes |
102+
| --------------------- | --------------------------------------------- | ------------------------------ |
103+
| `postgres:` (default) | `postgresql://postgres:...@postgres:5432/mcp` | Recommended for production |
104+
| `mariadb:` | `mysql+pymysql://mysql:...@mariadb:3306/mcp` | **Fully supported** - MariaDB 12.0+ |
105+
| `mysql:` | `mysql+pymysql://admin:...@mysql:3306/mcp` | Alternative MySQL variant |
106+
| `mongodb:` | `mongodb://admin:...@mongodb:27017/mcp` | NoSQL option |
107107

108108
Named volumes (`pgdata`, `mariadbdata`, `mysqldata`, `mongodata`) isolate persistent data.
109109

110+
!!! info "MariaDB & MySQL Full Support"
111+
MariaDB and MySQL are **fully supported** alongside SQLite and PostgreSQL:
112+
113+
- **36+ database tables** work perfectly with MariaDB 12.0+ and MySQL 8.4+
114+
- All **VARCHAR length issues** have been resolved for MariaDB/MySQL compatibility
115+
- Simply uncomment the `mariadb:` service block in `docker-compose.yml`
116+
- Use connection string: `mysql+pymysql://mysql:changeme@mariadb:3306/mcp`
117+
110118
---
111119

112120
## 🔄 Lifecycle cheatsheet

docs/docs/deployment/kubernetes.md

Lines changed: 139 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,151 @@ spec:
9696

9797
You can load your `.env` as a ConfigMap:
9898

99-
```bash
100-
kubectl create configmap mcpgateway-env --from-env-file=.env
99+
=== "With SQLite (Default)"
100+
```bash
101+
# Create .env file
102+
cat > .env << EOF
103+
HOST=0.0.0.0
104+
PORT=4444
105+
DATABASE_URL=sqlite:///./mcp.db
106+
JWT_SECRET_KEY=your-secret-key
107+
BASIC_AUTH_USER=admin
108+
BASIC_AUTH_PASSWORD=changeme
109+
MCPGATEWAY_UI_ENABLED=true
110+
MCPGATEWAY_ADMIN_API_ENABLED=true
111+
EOF
112+
113+
kubectl create configmap mcpgateway-env --from-env-file=.env
114+
```
115+
116+
=== "With MariaDB"
117+
```bash
118+
# Create .env file
119+
cat > .env << EOF
120+
HOST=0.0.0.0
121+
PORT=4444
122+
DATABASE_URL=mysql+pymysql://mysql:changeme@mariadb-service:3306/mcp
123+
JWT_SECRET_KEY=your-secret-key
124+
BASIC_AUTH_USER=admin
125+
BASIC_AUTH_PASSWORD=changeme
126+
MCPGATEWAY_UI_ENABLED=true
127+
MCPGATEWAY_ADMIN_API_ENABLED=true
128+
EOF
129+
130+
kubectl create configmap mcpgateway-env --from-env-file=.env
131+
```
132+
133+
=== "With MySQL"
134+
```bash
135+
# Create .env file
136+
cat > .env << EOF
137+
HOST=0.0.0.0
138+
PORT=4444
139+
DATABASE_URL=mysql+pymysql://mysql:changeme@mysql-service:3306/mcp
140+
JWT_SECRET_KEY=your-secret-key
141+
BASIC_AUTH_USER=admin
142+
BASIC_AUTH_PASSWORD=changeme
143+
MCPGATEWAY_UI_ENABLED=true
144+
MCPGATEWAY_ADMIN_API_ENABLED=true
145+
EOF
146+
147+
kubectl create configmap mcpgateway-env --from-env-file=.env
148+
```
149+
150+
=== "With PostgreSQL"
151+
```bash
152+
# Create .env file
153+
cat > .env << EOF
154+
HOST=0.0.0.0
155+
PORT=4444
156+
DATABASE_URL=postgresql://postgres:changeme@postgres-service:5432/mcp
157+
JWT_SECRET_KEY=your-secret-key
158+
BASIC_AUTH_USER=admin
159+
BASIC_AUTH_PASSWORD=changeme
160+
MCPGATEWAY_UI_ENABLED=true
161+
MCPGATEWAY_ADMIN_API_ENABLED=true
162+
EOF
163+
164+
kubectl create configmap mcpgateway-env --from-env-file=.env
101165
```
102166

103167
> Make sure it includes `JWT_SECRET_KEY`, `AUTH_REQUIRED`, etc.
104168

105169
---
106170

171+
## 🗄 Database Deployment Examples
172+
173+
### MySQL Deployment
174+
175+
```yaml
176+
apiVersion: apps/v1
177+
kind: Deployment
178+
metadata:
179+
name: mysql
180+
spec:
181+
replicas: 1
182+
selector:
183+
matchLabels:
184+
app: mysql
185+
template:
186+
metadata:
187+
labels:
188+
app: mysql
189+
spec:
190+
containers:
191+
- name: mysql
192+
image: mysql:8
193+
env:
194+
- name: MYSQL_ROOT_PASSWORD
195+
value: mysecretpassword
196+
- name: MYSQL_DATABASE
197+
value: mcp
198+
- name: MYSQL_USER
199+
value: mysql
200+
- name: MYSQL_PASSWORD
201+
value: changeme
202+
ports:
203+
- containerPort: 3306
204+
volumeMounts:
205+
- name: mysql-storage
206+
mountPath: /var/lib/mysql
207+
volumes:
208+
- name: mysql-storage
209+
persistentVolumeClaim:
210+
claimName: mysql-pvc
211+
---
212+
apiVersion: v1
213+
kind: Service
214+
metadata:
215+
name: mysql-service
216+
spec:
217+
selector:
218+
app: mysql
219+
ports:
220+
- port: 3306
221+
targetPort: 3306
222+
---
223+
apiVersion: v1
224+
kind: PersistentVolumeClaim
225+
metadata:
226+
name: mysql-pvc
227+
spec:
228+
accessModes:
229+
- ReadWriteOnce
230+
resources:
231+
requests:
232+
storage: 10Gi
233+
```
234+
235+
!!! info "MariaDB & MySQL Kubernetes Support"
236+
MariaDB and MySQL are **fully supported** in Kubernetes deployments:
237+
238+
- **36+ database tables** work perfectly with MariaDB 12.0+ and MySQL 8.4+
239+
- All **VARCHAR length issues** resolved for MariaDB/MySQL compatibility
240+
- Use connection string: `mysql+pymysql://mysql:changeme@mariadb-service:3306/mcp`
241+
242+
---
243+
107244
## 💡 OpenShift Considerations
108245

109246
* Use `Route` instead of Ingress

docs/docs/deployment/local.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,69 @@ make dev # hot-reload (Uvicorn) on :8000
4040
4141
---
4242
43+
## 🗄 Database Configuration
44+
45+
By default, MCP Gateway uses SQLite for simplicity. You can configure alternative databases via the `DATABASE_URL` environment variable:
46+
47+
=== "SQLite (Default)"
48+
```bash
49+
# .env file
50+
DATABASE_URL=sqlite:///./mcp.db
51+
```
52+
53+
=== "MariaDB"
54+
```bash
55+
# .env file
56+
DATABASE_URL=mysql+pymysql://mysql:changeme@localhost:3306/mcp
57+
```
58+
59+
!!! info "MariaDB Setup"
60+
Install and configure MariaDB server:
61+
```bash
62+
# Ubuntu/Debian
63+
sudo apt update && sudo apt install mariadb-server
64+
65+
# Create database and user
66+
sudo mariadb -e "CREATE DATABASE mcp;"
67+
sudo mariadb -e "CREATE USER 'mysql'@'localhost' IDENTIFIED BY 'changeme';"
68+
sudo mariadb -e "GRANT ALL PRIVILEGES ON mcp.* TO 'mysql'@'localhost';"
69+
sudo mariadb -e "FLUSH PRIVILEGES;"
70+
```
71+
72+
=== "MySQL"
73+
```bash
74+
# .env file
75+
DATABASE_URL=mysql+pymysql://mysql:changeme@localhost:3306/mcp
76+
```
77+
78+
!!! info "MySQL Setup"
79+
Install and configure MySQL server:
80+
```bash
81+
# Ubuntu/Debian
82+
sudo apt update && sudo apt install mysql-server
83+
84+
# Create database and user
85+
sudo mysql -e "CREATE DATABASE mcp;"
86+
sudo mysql -e "CREATE USER 'mysql'@'localhost' IDENTIFIED BY 'changeme';"
87+
sudo mysql -e "GRANT ALL PRIVILEGES ON mcp.* TO 'mysql'@'localhost';"
88+
sudo mysql -e "FLUSH PRIVILEGES;"
89+
```
90+
91+
=== "PostgreSQL"
92+
```bash
93+
# .env file
94+
DATABASE_URL=postgresql://postgres:changeme@localhost:5432/mcp
95+
```
96+
97+
!!! tip "MariaDB & MySQL Full Compatibility"
98+
MariaDB and MySQL are **fully supported** with:
99+
100+
- **36+ database tables** working perfectly with MariaDB 12.0+ and MySQL 8.4+
101+
- All **VARCHAR length issues** resolved for MariaDB/MySQL compatibility
102+
- Complete feature parity with SQLite and PostgreSQL
103+
104+
---
105+
43106
## 🧪 Health Test
44107
45108
```bash

docs/docs/manage/.pages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
nav:
22
- index.md
3+
- configuration.md
34
- backup.md
45
- bulk-import.md
56
- metadata-tracking.md

0 commit comments

Comments
 (0)