内容
# 🚀 MCP Server with Docker, Redis, and TimescaleDB
这个仓库使用 Docker 设置一个 **Model Context Protocol (MCP) Server**,集成 Redis 和 TimescaleDB 以实现高效的数据管理。
## 🛠️ Features
- **FastAPI**: 用作 MCP Server 的 Web 框架。
- **Redis**: 提供缓存机制。
- **TimescaleDB**: 构建在 PostgreSQL 上的时序数据库。
- **Docker Compose**: 编排多容器 Docker 应用程序。
- **Environment Variables**: 可通过 `.env` 文件配置。
- **Systemd Service**: 确保服务器在重新启动时自动启动。
## 📋 Prerequisites
- 您的系统上安装了 **Docker** 和 **Docker Compose**。
- 用于版本控制的 **Git**。
- 带有 **Oh-My-Zsh** 的 **Zsh**(可选,用于增强 shell 体验)。
## 📂 Repository Structure
```plaintext
mcp-server-docker/
├── app/
│ └── app.py
├── .env.example
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
├── scripts/
│ ├── bootstrap-mcp.sh
│ ├── full-bootstrap-mcp.sh
│ ├── init-repo.sh
│ ├── push-repo.sh
│ └── setup-mcpserver.sh
└── README.md
```
## 🚀 Setup Instructions
1. **Clone the Repository**:
```bash
git clone https://github.com/chuckwilliams37/mcp-server-docker.git
cd mcp-server-docker
```
2. **Configure Environment Variables**:
```bash
cp .env.example .env
```
根据需要修改 `.env`。
3. **Build and Start the Containers**:
```bash
docker compose build
docker compose up -d
```
4. **Access the MCP Server**:
```bash
http://localhost:8080
```
## 🔄 Auto-Restart on Reboot
创建一个 systemd 服务以保持您的应用程序运行:
```bash
sudo nano /etc/systemd/system/mcp-docker.service
```
粘贴:
```ini
[Unit]
Description=MCP Docker Compose App
Requires=docker.service
After=docker.service
[Service]
WorkingDirectory=/home/youruser/mcp-server-docker
ExecStart=/usr/bin/docker compose up -d
ExecStop=/usr/bin/docker compose down
Restart=always
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target
```
启用它:
```bash
sudo systemctl daemon-reload
sudo systemctl enable mcp-docker
sudo systemctl start mcp-docker
```
---
## 🧪 Scripts
`scripts/` 目录包含用于自动化基础设施任务的实用程序脚本。
---
### 🛠️ `scripts/full-bootstrap-mcp.sh`
💡 **在全新的 Ubuntu VM 上使用此脚本**,以充分准备它以进行 MCP 部署。它:
- 安装系统依赖项(Docker、Git、Zsh、UFW、Fail2Ban 等)
- 使用 `jonathan` 主题设置 `oh-my-zsh`
- 使用 XFCE + XRDP 配置远程桌面
- 克隆 MCP 仓库
- 使用 `docker compose` 构建并启动应用程序
- 添加一个 systemd 服务以在重新启动时重新启动容器
```bash
chmod +x scripts/full-bootstrap-mcp.sh
./scripts/full-bootstrap-mcp.sh
```
---
### 📜 `scripts/init-repo.sh`
初始化一个新的本地 Git 仓库并提交当前目录:
```bash
chmod +x scripts/init-repo.sh
./scripts/init-repo.sh
```
---
### 📤 `scripts/push-repo.sh`
将您的本地仓库推送到远程仓库(首先更新 URL):
```bash
chmod +x scripts/push-repo.sh
./scripts/push-repo.sh
```
---
### 🧠 `scripts/setup-mcpserver.sh`
配置您的本地 SSH 环境以访问远程 MCP Server:
- 推送您的公钥
- 添加 SSH 别名
- 打印示例 A 记录
```bash
chmod +x scripts/setup-mcpserver.sh
./scripts/setup-mcpserver.sh
```
---
> ⚠️ 在执行之前编辑占位符值(例如,IP、用户名、仓库 URL)。
---
## 🤝 Contributions
随时 fork 此仓库,提交问题或创建 pull request。
## 📄 License
本项目已获得 MIT License 的许可。