Skip to content

Commit f1ff81e

Browse files
authored
Merge branch 'main' into feature/explain
2 parents f799a0b + 2da80ae commit f1ff81e

File tree

4 files changed

+83
-22
lines changed

4 files changed

+83
-22
lines changed

README.md

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The MCP MariaDB Server exposes a set of tools for interacting with MariaDB datab
2727
- Query performance analysis with EXPLAIN and EXPLAIN EXTENDED
2828
- Comprehensive tool usage guide for LLM self-discovery
2929
- Creating and managing vector stores for embedding-based search
30-
- Integrating with embedding providers (currently OpenAI, Gemini, and HuggingFace)
30+
- Integrating with embedding providers (currently OpenAI, Gemini, and HuggingFace) (optional)
3131

3232
---
3333

@@ -65,6 +65,8 @@ The MCP MariaDB Server exposes a set of tools for interacting with MariaDB datab
6565
- Creates a new database if it doesn't exist.
6666
- Parameters: `database_name` (string, required)
6767

68+
### Query Performance Analysis Tools
69+
6870
- **explain_query**
6971
- Executes EXPLAIN on a SQL query to show the execution plan for performance analysis.
7072
- Parameters: `sql_query` (string, required), `database_name` (string, required), `parameters` (list, optional)
@@ -75,7 +77,9 @@ The MCP MariaDB Server exposes a set of tools for interacting with MariaDB datab
7577
- Parameters: `sql_query` (string, required), `database_name` (string, required), `parameters` (list, optional)
7678
- _Note: Provides comprehensive analysis including filtered rows percentage and extra optimization details._
7779

78-
### Vector Store & Embedding Tools
80+
### Vector Store & Embedding Tools (optional)
81+
82+
**Note**: These tools are only available when `EMBEDDING_PROVIDER` is configured. If no embedding provider is set, these tools will be disabled.
7983

8084
- **create_vector_store**
8185
- Creates a new vector store (table) for embeddings.
@@ -101,6 +105,10 @@ The MCP MariaDB Server exposes a set of tools for interacting with MariaDB datab
101105

102106
## Embeddings & Vector Store
103107

108+
### Overview
109+
110+
The MCP MariaDB Server provides **optional** embedding and vector store capabilities. These features can be enabled by configuring an embedding provider, or completely disabled if you only need standard database operations.
111+
104112
### Supported Providers
105113

106114
- **OpenAI**
@@ -109,11 +117,10 @@ The MCP MariaDB Server exposes a set of tools for interacting with MariaDB datab
109117

110118
### Configuration
111119

112-
- `EMBEDDING_PROVIDER`: Set to `openai` (default option), can change it to required providers
120+
- `EMBEDDING_PROVIDER`: Set to `openai`, `gemini`, `huggingface`, or leave unset to disable
113121
- `OPENAI_API_KEY`: Required if using OpenAI embeddings
114-
- GEMINI_API_KEY`: Required if using Gemini embeddings
115-
- Open models from HUGGINGFACE: Required open model currently provided option for "intfloat/multilingual-e5-large-instruct" & "BAAI/bge-m3"
116-
122+
- `GEMINI_API_KEY`: Required if using Gemini embeddings
123+
- `HF_MODEL`: Required if using HuggingFace embeddings (e.g., "intfloat/multilingual-e5-large-instruct" or "BAAI/bge-m3")
117124
### Model Selection
118125

119126
- Default and allowed models are configurable in code (`DEFAULT_OPENAI_MODEL`, `ALLOWED_OPENAI_MODELS`)
@@ -142,13 +149,14 @@ All configuration is via environment variables (typically set in a `.env` file):
142149
| `DB_NAME` | Default database (optional; can be set per query) | No | |
143150
| `MCP_READ_ONLY` | Enforce read-only SQL mode (`true`/`false`) | No | `true` |
144151
| `MCP_MAX_POOL_SIZE` | Max DB connection pool size | No | `10` |
145-
| `EMBEDDING_PROVIDER` | Embedding provider (`openai`/`gemini`/`huggingface`) | No | `openai` |
146-
| `OPENAI_API_KEY` | API key for OpenAI embeddings | Yes (if using embeddings) | |
147-
| `GEMINII_API_KEY` | API key for Gemini embeddings | Yes (if using embeddings) | |
148-
| `HF_MODEL` | Open models from Huggingface | Yes (if using embeddings) | |
152+
| `EMBEDDING_PROVIDER` | Embedding provider (`openai`/`gemini`/`huggingface`) | No |`None`(Disabled)|
153+
| `OPENAI_API_KEY` | API key for OpenAI embeddings | Yes (if EMBEDDING_PROVIDER=openai) | |
154+
| `GEMINI_API_KEY` | API key for Gemini embeddings | Yes (if EMBEDDING_PROVIDER=gemini) | |
155+
| `HF_MODEL` | Open models from Huggingface | Yes (if EMBEDDING_PROVIDER=huggingface) | |
149156

150157
#### Example `.env` file
151158

159+
**With Embedding Support (OpenAI):**
152160
```dotenv
153161
DB_HOST=localhost
154162
DB_USER=your_db_user
@@ -165,6 +173,17 @@ GEMINI_API_KEY=AI...
165173
HF_MODEL="BAAI/bge-m3"
166174
```
167175

176+
**Without Embedding Support:**
177+
```dotenv
178+
DB_HOST=localhost
179+
DB_USER=your_db_user
180+
DB_PASSWORD=your_db_password
181+
DB_PORT=3306
182+
DB_NAME=your_default_database
183+
MCP_READ_ONLY=true
184+
MCP_MAX_POOL_SIZE=10
185+
```
186+
168187
---
169188

170189
## Installation & Setup
@@ -256,9 +275,9 @@ HF_MODEL="BAAI/bge-m3"
256275
```
257276
---
258277

259-
## Integration - Claude desktop/Cursor/Windsurf
278+
## Integration - Claude desktop/Cursor/Windsurf/VSCode
260279

261-
```python
280+
```json
262281
{
263282
"mcpServers": {
264283
"MariaDB_Server": {
@@ -274,6 +293,18 @@ HF_MODEL="BAAI/bge-m3"
274293
}
275294
}
276295
```
296+
or
297+
**If already running MCP server**
298+
```json
299+
{
300+
"servers": {
301+
"mariadb-mcp-server": {
302+
"url": "http://{host}:9001/sse",
303+
"type": "sse"
304+
}
305+
}
306+
}
307+
```
277308
---
278309

279310
## Logging

docker-compose.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
services:
2+
mariadb-server:
3+
image: mariadb:11
4+
container_name: mariadb
5+
environment:
6+
MARIADB_ROOT_PASSWORD: rootpassword123
7+
MARIADB_DATABASE: demo
8+
MARIADB_USER: user
9+
MARIADB_PASSWORD: password123
10+
ports:
11+
- "3306:3306"
12+
healthcheck:
13+
test: ["CMD", "mariadb-admin", "ping", "-h", "127.0.0.1", "-p'rootpassword123'"]
14+
interval: 5s
15+
timeout: 3s
16+
retries: 10
17+
mariadb-mcp:
18+
build: .
19+
container_name: mariadb-mcp
20+
env_file: .env
21+
ports:
22+
- "9001:9001"
23+
depends_on:
24+
mariadb-server:
25+
condition: service_healthy

src/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959

6060
# --- Embedding Configuration ---
6161
# Provider selection ('openai' or 'gemini' or 'huggingface')
62-
EMBEDDING_PROVIDER = os.getenv("EMBEDDING_PROVIDER", "openai").lower()
62+
EMBEDDING_PROVIDER = os.getenv("EMBEDDING_PROVIDER")
63+
EMBEDDING_PROVIDER = EMBEDDING_PROVIDER.lower() if EMBEDDING_PROVIDER else None
6364
# API Keys
6465
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
6566
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
@@ -86,8 +87,8 @@
8687
logger.error("EMBEDDING_PROVIDER is 'huggingface' but HF_MODEL is missing.")
8788
raise ValueError("HuggingFace model is required when EMBEDDING_PROVIDER is 'huggingface'.")
8889
else:
89-
logger.error(f"Invalid EMBEDDING_PROVIDER specified: '{EMBEDDING_PROVIDER}'. Use 'openai' or 'gemini' or 'huggingface'.")
90-
raise ValueError(f"Invalid EMBEDDING_PROVIDER: '{EMBEDDING_PROVIDER}'.")
90+
EMBEDDING_PROVIDER = None
91+
logger.info(f"No EMBEDDING_PROVIDER selected or it is set to None. Disabling embedding features.")
9192

9293
logger.info(f"Read-only mode: {MCP_READ_ONLY}")
9394
logger.info(f"Logging to console and to file: {LOG_FILE_PATH} (Level: {LOG_LEVEL}, MaxSize: {LOG_MAX_BYTES}B, Backups: {LOG_BACKUP_COUNT})")

src/server.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
# Import configuration settings
1313
from config import (
1414
DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME,
15-
MCP_READ_ONLY, MCP_MAX_POOL_SIZE, logger
15+
MCP_READ_ONLY, MCP_MAX_POOL_SIZE, EMBEDDING_PROVIDER,
16+
logger
1617
)
1718

1819
# Import EmbeddingService for vector store creation
1920
from embeddings import EmbeddingService
2021

2122
# Singleton instance for embedding service
22-
embedding_service = EmbeddingService()
23+
embedding_service = None
24+
if EMBEDDING_PROVIDER is not None:
25+
embedding_service = EmbeddingService()
2326

2427
from asyncmy.errors import Error as AsyncMyError
2528

@@ -746,11 +749,12 @@ def register_tools(self):
746749
self.mcp.add_tool(self.create_database)
747750
self.mcp.add_tool(self.explain_query)
748751
self.mcp.add_tool(self.explain_query_extended)
749-
self.mcp.add_tool(self.create_vector_store)
750-
self.mcp.add_tool(self.list_vector_stores)
751-
self.mcp.add_tool(self.delete_vector_store)
752-
self.mcp.add_tool(self.insert_docs_vector_store)
753-
self.mcp.add_tool(self.search_vector_store)
752+
if EMBEDDING_PROVIDER is not None:
753+
self.mcp.add_tool(self.create_vector_store)
754+
self.mcp.add_tool(self.list_vector_stores)
755+
self.mcp.add_tool(self.delete_vector_store)
756+
self.mcp.add_tool(self.insert_docs_vector_store)
757+
self.mcp.add_tool(self.search_vector_store)
754758
logger.info("Registered MCP tools explicitly.")
755759

756760
# --- Async Main Server Logic ---

0 commit comments

Comments
 (0)