mirror of
https://github.com/mangooer/mysql-mcp-server-sse.git
synced 2025-12-08 09:42:27 +08:00
<feat> 添加 Docker 支持,包含 Dockerfile 和 .dockerignore 文件,更新 README 以说明 Docker 部署方法,更新依赖版本以支持 Python 3.12.3 及以上版本
This commit is contained in:
32
.dockerignore
Normal file
32
.dockerignore
Normal file
@ -0,0 +1,32 @@
|
||||
# 操作系统和编辑器临时文件
|
||||
__MACOSX
|
||||
.DS_Store
|
||||
*.code-workspace
|
||||
.vscode
|
||||
.idea
|
||||
.history
|
||||
.cursorrules
|
||||
.cursor
|
||||
|
||||
# Python 缓存和测试
|
||||
**/__pycache__/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
*.swp
|
||||
.pytest_cache/
|
||||
.coverage
|
||||
|
||||
# Node/Vendor/依赖
|
||||
node_modules/
|
||||
vendor/
|
||||
requirements-dev.txt
|
||||
|
||||
# 版本控制和文档
|
||||
.git
|
||||
docs/
|
||||
tests/
|
||||
|
||||
# 环境变量
|
||||
.env
|
||||
50
.github/workflows/docker-publish.yml
vendored
Normal file
50
.github/workflows/docker-publish.yml
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
name: Docker Build and Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
tags: [ 'v*.*.*' ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
env:
|
||||
REGISTRY: docker.io
|
||||
IMAGE_NAME: mangooer/mysql-mcp-server-sse
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=ref,event=tag
|
||||
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
||||
type=sha,format=short
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
24
Dockerfile
Normal file
24
Dockerfile
Normal file
@ -0,0 +1,24 @@
|
||||
FROM python:3.12-slim
|
||||
|
||||
RUN apt-get update && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 复制本地代码到镜像
|
||||
COPY . .
|
||||
|
||||
# 自动生成 .env(如不存在则复制 example.env)
|
||||
RUN [ -f .env ] || cp example.env .env
|
||||
|
||||
# 安装依赖
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# 暴露端口(如需)
|
||||
EXPOSE 3000
|
||||
|
||||
# 支持环境变量覆盖
|
||||
ENV HOST=0.0.0.0 \
|
||||
PORT=3000
|
||||
|
||||
CMD ["python", "-m", "src.server"]
|
||||
45
README.md
45
README.md
@ -21,6 +21,7 @@ This project is a MySQL query server based on the MCP framework, supporting real
|
||||
- 敏感信息自动隐藏与自定义
|
||||
- 灵活的环境变量配置
|
||||
- 完善的日志与错误处理
|
||||
- Docker支持,快速部署
|
||||
|
||||
- Built on FastMCP framework, high-performance async
|
||||
- Connection pool for high concurrency, with flexible parameter tuning
|
||||
@ -31,21 +32,59 @@ This project is a MySQL query server based on the MCP framework, supporting real
|
||||
- Automatic and customizable sensitive info masking
|
||||
- Flexible environment variable configuration
|
||||
- Robust logging & error handling
|
||||
- Docker support for quick deployment
|
||||
|
||||
---
|
||||
|
||||
## 3. 快速开始 / Quick Start
|
||||
|
||||
### 安装依赖 / Install Dependencies
|
||||
### Docker 方式 / Docker Method
|
||||
|
||||
```bash
|
||||
# 拉取镜像
|
||||
docker pull mangooer/mysql-mcp-server-sse:latest
|
||||
|
||||
# 运行容器
|
||||
docker run -d \
|
||||
--name mysql-mcp-server-sse \
|
||||
-e HOST=0.0.0.0 \
|
||||
-e PORT=3000 \
|
||||
-e MYSQL_HOST=your_mysql_host \
|
||||
-e MYSQL_PORT=3306 \
|
||||
-e MYSQL_USER=your_mysql_user \
|
||||
-e MYSQL_PASSWORD=your_mysql_password \
|
||||
-e MYSQL_DATABASE=your_database \
|
||||
-p 3000:3000 \
|
||||
mangooer/mysql-mcp-server-sse:latest
|
||||
```
|
||||
|
||||
Windows PowerShell 格式:
|
||||
```powershell
|
||||
docker run -d `
|
||||
--name mysql-mcp-server-sse `
|
||||
-e HOST=0.0.0.0 `
|
||||
-e PORT=3000 `
|
||||
-e MYSQL_HOST=your_mysql_host `
|
||||
-e MYSQL_PORT=3306 `
|
||||
-e MYSQL_USER=your_mysql_user `
|
||||
-e MYSQL_PASSWORD=your_mysql_password `
|
||||
-e MYSQL_DATABASE=your_database `
|
||||
-p 3000:3000 `
|
||||
mangooer/mysql-mcp-server-sse:latest
|
||||
```
|
||||
|
||||
### 源码方式 / Source Code Method
|
||||
|
||||
#### 安装依赖 / Install Dependencies
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### 配置环境变量 / Configure Environment Variables
|
||||
#### 配置环境变量 / Configure Environment Variables
|
||||
复制`.env.example`为`.env`,并根据实际情况修改。
|
||||
Copy `.env.example` to `.env` and modify as needed.
|
||||
|
||||
### 启动服务 / Start the Server
|
||||
#### 启动服务 / Start the Server
|
||||
```bash
|
||||
python -m src.server
|
||||
```
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
mcp>=0.1.0
|
||||
aiomysql==0.2.0
|
||||
python-dotenv>=0.19.0
|
||||
sqlparse>=0.4.2
|
||||
# 需要 Python 3.12.3 及以上版本 / Requires Python >=3.12.3
|
||||
mcp>=1.4.1
|
||||
aiomysql>=0.2.0
|
||||
python-dotenv>=1.0.1
|
||||
sqlparse>=0.5.3
|
||||
Reference in New Issue
Block a user