Content
# MySQL MCP Project
This project is an intelligent MySQL MCP Server that combines the strengths of traditional relational databases (MySQL) and vector databases (Milvus) to achieve intelligent database querying and document management through AI technology. The project provides the following core features:
1. **Intelligent Table Structure Query**: Automatically find relevant database table structures through natural language descriptions
2. **SQL Query Execution**: Supports executing SQL statements and returning query results
3. **Intelligent Document Processing**: Supports uploading, parsing, and vectorizing storage of documents in various formats
4. **Vector Similarity Search**: Intelligent content retrieval based on semantic understanding
5. **Automated Data Synchronization**: Regularly update database table structures to the vector database
## Flowchart
System flowchart
<img src="sys.png">
Technical architecture diagram
<img src="tec.png">
Data flow diagram
<img src="data.png">
## Environment Configuration
The project requires the following environment variable configurations (set in the `.env` file):
### MySQL Database Configuration
- `DB_USER`: Database username
- `DB_PASSWORD`: Database password
- `DB_HOST`: Database host address
- `DB_PORT`: Database port (default 3306)
- `DB_NAME`: Database name
- `DB_PARAMS`: Database connection parameters (e.g., character set, time zone)
### SiliconFlow API Configuration (for vector embedding)
- `SILICONFLOW_TOKEN`: SiliconFlow API access token
- `SILICONFLOW_URL`: SiliconFlow API endpoint URL
### Milvus Vector Database Configuration
- `MILVUS_HOST`: Milvus server address
- `MILVUS_PORT`: Milvus service port (default 19530)
- `MILVUS_COLLECTION`: Milvus collection name
## Features
### 🔍 Intelligent Table Structure Query
- **Tool Name**: `get_can_use_table`
- **Function Description**: Intelligently find relevant table structure information based on natural language descriptions
- **Technical Implementation**: Use vector embedding technology to convert queries into vectors and perform similarity searches in Milvus
- **Application Scenarios**: Quickly understand relevant table structures before writing SQL
### 💾 SQL Query Execution
- **Tool Name**: `execute_sql`
- **Function Description**: Directly execute MySQL database queries and return results
- **Security Features**: Supports query timeout control to prevent long-running queries
- **Return Format**: Structured query result data
### 📄 Intelligent Document Processing
- **Tool Name**: `doc`
- **Function Description**: Upload documents and automatically vectorize and store them in Milvus
- **Supported Formats**:
- Text files (.txt, .md, etc.)
- PDF documents (.pdf)
- HTML files (.html)
- Other common document formats
- **Processing Flow**: Document parsing → Content segmentation → Vector embedding → Storage in vector database
### 🤖 Automated Data Synchronization
- **Scheduled Updates**: Automatically retrieve database table structure changes every 5 minutes
- **Incremental Synchronization**: Intelligently identify new table structures to avoid redundant processing
- **Vectorized Storage**: Automatically convert table structure information into vectors and store them
### 🔎 Vector Similarity Search
- **Efficient Retrieval**: Use Milvus for millisecond-level vector similarity searches
- **Semantic Understanding**: Understand query semantics based on AI embedding models
- **Precise Matching**: Supports cosine similarity algorithms to provide precise relevance ranking
## Main Process Description
### 1. System Initialization Process
Load environment configuration → Initialize logging system → Connect to MySQL database → Connect to Milvus vector database → Initialize SQLite cache
### 2. Vector Database Preparation Process
Check Milvus collection → Create collection (if it does not exist) → Get all table structures → Vectorize processing → Store in vector database
### 3. Intelligent Query Process
Natural language input → Vector embedding → Milvus similarity search → Return relevant table structures → User writes SQL → Execute query → Return results
### 4. Document Processing Process
Document upload → Format identification → Content parsing → Text segmentation → Vector embedding → Store in Milvus → Return processing status
## Usage
### Environment Preparation
1. Ensure that the MySQL database is accessible
2. Ensure that the Milvus vector database is running normally
3. Obtain a SiliconFlow API access token
### Deployment Steps
1. **Compile the application**:
```bash
go build -o yourPath/mcp-mysql
2. Configure environment variables: Create a .env file in yourPath and configure the relevant environment variables
3. MCP client configuration:
```json
"mcpName": {
"timeout": 60,
"command": "yourPath/mcp-mysql",
"args": [
"-m",
"query",
""
],
"transportType": "stdio"
}
```
## Technical Architecture
### Core Components
- MySQL: Main data storage
- Milvus: Vector database, storing embedded vectors
- SiliconFlow: AI embedding service, providing text vectorization
- SQLite: Local storage
- Go: Main development language
- MCP protocol: Communication protocol
### Key Technologies
- Vector Embedding: Use advanced AI models to convert text into high-dimensional vectors
- Similarity Search: Fast retrieval algorithm based on cosine similarity
- Document Parsing: Supports intelligent document processing in various formats
## Dependencies
- Go 1.23+
- MySQL Database
- Milvus Vector Database v2.5+
- SiliconFlow API (for generating text embedding vectors)
- zap Logging Library (for structured logging)
## Other Information
* MCP Official Documentation: https://modelcontextprotocol.io/introduction
* vscode install cline extension(MCP host): https://docs.cline.bot/getting-started/installing-cline
* milvus local installation tutorial: https://milvus.io/docs/install_standalone-docker-compose.md
* SiliconFlow registration, APIKEY acquisition: https://docs.siliconflow.cn/cn/userguide/quickstart
Connection Info
You Might Also Like
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
markitdown
Python tool for converting files and office documents to Markdown.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.
Sequential Thinking
A structured MCP server for dynamic problem-solving and reflective thinking.
Fetch
Retrieve and process content from web pages by converting HTML into markdown format.
TrendRadar
TrendRadar: Your hotspot assistant for real news in just 30 seconds.