Skip to content

Commit afa6bb1

Browse files
committed
feat: 添加启动脚本和更新文档
- 新增启动脚本 `start.sh`,自动化 Neo4j 初始化和 MCP 服务器启动流程 - 更新 `.dockerignore` 文件以包含必要的文件 - 修改 `Dockerfile` 以复制并设置启动脚本权限 - 更新 `MCP_USAGE.md` 和 `README.md`,详细说明启动脚本的使用和功能
1 parent 180dbe8 commit afa6bb1

File tree

5 files changed

+155
-61
lines changed

5 files changed

+155
-61
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
# Documentation
66
README.md
77
*.md
8+
!MCP_USAGE.md
9+
10+
# Include essential files
11+
!start.sh
12+
!mcp_server.py
13+
!main.py
14+
!requirements.txt
15+
!env.example
816

917
# Docker
1018
Dockerfile*

Dockerfile

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -36,68 +36,13 @@ RUN mkdir -p /var/lib/neo4j/data /var/lib/neo4j/logs /var/lib/neo4j/import /var/
3636
COPY requirements.txt .
3737
RUN pip install --no-cache-dir -r requirements.txt
3838

39+
# 复制启动脚本并设置权限
40+
COPY start.sh /app/start.sh
41+
RUN chmod +x /app/start.sh
42+
3943
# 复制应用代码
4044
COPY . .
4145

42-
# 创建启动脚本
43-
RUN echo '#!/bin/bash\n\
44-
set -e\n\
45-
\n\
46-
# 确保清理旧的数据(如果需要重新初始化)\n\
47-
if [ "$RESET_NEO4J" = "true" ]; then\n\
48-
echo "Resetting Neo4j data..."\n\
49-
rm -rf /var/lib/neo4j/data/databases/\n\
50-
rm -rf /var/lib/neo4j/data/transactions/\n\
51-
fi\n\
52-
\n\
53-
# 设置 Neo4j 初始密码\n\
54-
echo "Setting up Neo4j initial password..."\n\
55-
if [ ! -f /var/lib/neo4j/data/.neo4j_initialized ]; then\n\
56-
neo4j-admin dbms set-initial-password ${NEO4J_PASSWORD:-password}\n\
57-
touch /var/lib/neo4j/data/.neo4j_initialized\n\
58-
else\n\
59-
echo "Neo4j already initialized, skipping password setup"\n\
60-
fi\n\
61-
\n\
62-
# 启动 Neo4j\n\
63-
echo "Starting Neo4j..."\n\
64-
neo4j start\n\
65-
\n\
66-
# 等待 Neo4j 启动\n\
67-
echo "Waiting for Neo4j to start..."\n\
68-
for i in {1..30}; do\n\
69-
if neo4j status > /dev/null 2>&1; then\n\
70-
echo "Neo4j started successfully"\n\
71-
break\n\
72-
fi\n\
73-
echo "Neo4j is starting... ($i/30)"\n\
74-
sleep 2\n\
75-
done\n\
76-
\n\
77-
# 验证 Neo4j 是否真的启动了\n\
78-
if ! neo4j status > /dev/null 2>&1; then\n\
79-
echo "Failed to start Neo4j after 60 seconds"\n\
80-
exit 1\n\
81-
fi\n\
82-
\n\
83-
# 额外等待确保 Neo4j 完全就绪\n\
84-
echo "Waiting for Neo4j to be fully ready..."\n\
85-
sleep 5\n\
86-
\n\
87-
# 运行应用\n\
88-
echo "Starting Graphiti MCP Server..."\n\
89-
if [ -f "mcp_server.py" ]; then\n\
90-
python mcp_server.py\n\
91-
elif [ -f "main.py" ]; then\n\
92-
python main.py\n\
93-
elif [ -f "app.py" ]; then\n\
94-
python app.py\n\
95-
else\n\
96-
echo "No application file found. Starting Python shell..."\n\
97-
python\n\
98-
fi\n\
99-
' > /app/start.sh && chmod +x /app/start.sh
100-
10146
# 暴露端口
10247
EXPOSE 7474 7687 8000
10348

@@ -106,4 +51,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
10651
CMD neo4j status && curl -f http://localhost:7474/ || exit 1
10752

10853
# 启动命令
109-
CMD ["/app/start.sh"]
54+
CMD ["./start.sh"]

MCP_USAGE.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,39 @@
1818
# 使用 Docker Compose
1919
docker-compose up -d
2020

21-
# 或直接运行 MCP 服务器
21+
# 或直接运行启动脚本 (推荐)
22+
chmod +x start.sh
23+
./start.sh
24+
25+
# 或仅运行 MCP 服务器 (需要 Neo4j 已启动)
2226
python mcp_server.py
2327
```
2428

29+
### 启动脚本说明
30+
31+
`start.sh` 脚本会自动完成以下操作:
32+
33+
1. **Neo4j 初始化和启动**
34+
- 设置初始密码
35+
- 启动 Neo4j 服务
36+
- 等待服务就绪
37+
38+
2. **MCP 服务器启动**
39+
- 启动 Graphiti MCP 服务器
40+
- 等待客户端连接
41+
42+
**环境变量配置:**
43+
```bash
44+
# 重置 Neo4j 数据 (开发环境)
45+
export RESET_NEO4J=true
46+
47+
# 自定义 Neo4j 密码
48+
export NEO4J_PASSWORD=your_password
49+
50+
# 启动脚本
51+
./start.sh
52+
```
53+
2554
### 2. 验证服务状态
2655

2756
```bash

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,26 @@ This Docker deployment includes:
318318
- **Python 3.11**: Runtime environment
319319
- **Graphiti Core**: Knowledge graph framework
320320
- **MCP Server**: Model Context Protocol server implementation
321+
- **Start Script**: Automated startup script (`start.sh`) for Neo4j and MCP server
321322
- **Example Application**: Ready-to-run Graphiti demo with sample data
322323
- **Health Checks**: Container monitoring and status verification
323324
- **Data Persistence**: Volume mounting for data preservation
324325

326+
### File Structure
327+
328+
```
329+
graphiti-mcp/
330+
├── start.sh # 启动脚本 (Neo4j + MCP Server)
331+
├── mcp_server.py # MCP 协议服务器实现
332+
├── main.py # Graphiti 示例应用
333+
├── requirements.txt # Python 依赖
334+
├── Dockerfile # Docker 镜像构建
335+
├── docker-compose.yml # Docker Compose 配置
336+
├── env.example # 环境变量示例
337+
├── README.md # 项目文档
338+
└── MCP_USAGE.md # MCP 使用指南
339+
```
340+
325341
## 🛠️ MCP Tools Available
326342

327343
The Graphiti MCP server provides the following tools:
@@ -338,6 +354,46 @@ The Graphiti MCP server provides the following tools:
338354
- `graphiti://graph/schema` - 知识图谱架构信息
339355
- `graphiti://graph/stats` - 图谱统计信息
340356

357+
## 🔧 启动脚本说明
358+
359+
`start.sh` 脚本负责自动化启动流程,包含以下功能:
360+
361+
### 启动流程
362+
363+
1. **数据清理** (可选)
364+
- 当设置 `RESET_NEO4J=true` 时,清理旧的 Neo4j 数据
365+
366+
2. **Neo4j 初始化**
367+
- 设置初始密码 (使用 `NEO4J_PASSWORD` 环境变量)
368+
- 创建初始化标记文件
369+
370+
3. **Neo4j 启动**
371+
- 启动 Neo4j 服务
372+
- 等待服务就绪 (最多30秒)
373+
- 验证服务状态
374+
375+
4. **应用启动**
376+
- 优先启动 `mcp_server.py` (MCP 服务器)
377+
- 备选启动 `main.py``app.py`
378+
379+
### 环境变量
380+
381+
| 变量 | 说明 | 默认值 |
382+
|------|------|--------|
383+
| `RESET_NEO4J` | 是否重置 Neo4j 数据 | `false` |
384+
| `NEO4J_PASSWORD` | Neo4j 密码 | `password` |
385+
386+
### 手动运行
387+
388+
```bash
389+
# 本地运行启动脚本
390+
chmod +x start.sh
391+
./start.sh
392+
393+
# 或在容器中运行
394+
docker exec -it graphiti-mcp-server ./start.sh
395+
```
396+
341397
## 🚀 CI/CD Pipeline
342398

343399
This repository includes GitHub Actions workflow that automatically:

start.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# 确保清理旧的数据(如果需要重新初始化)
5+
if [ "$RESET_NEO4J" = "true" ]; then
6+
echo "Resetting Neo4j data..."
7+
rm -rf /var/lib/neo4j/data/databases/
8+
rm -rf /var/lib/neo4j/data/transactions/
9+
fi
10+
11+
# 设置 Neo4j 初始密码
12+
echo "Setting up Neo4j initial password..."
13+
if [ ! -f /var/lib/neo4j/data/.neo4j_initialized ]; then
14+
neo4j-admin dbms set-initial-password ${NEO4J_PASSWORD:-password}
15+
touch /var/lib/neo4j/data/.neo4j_initialized
16+
else
17+
echo "Neo4j already initialized, skipping password setup"
18+
fi
19+
20+
# 启动 Neo4j
21+
echo "Starting Neo4j..."
22+
neo4j start
23+
24+
# 等待 Neo4j 启动
25+
echo "Waiting for Neo4j to start..."
26+
for i in {1..30}; do
27+
if neo4j status > /dev/null 2>&1; then
28+
echo "Neo4j started successfully"
29+
break
30+
fi
31+
echo "Neo4j is starting... ($i/30)"
32+
sleep 2
33+
done
34+
35+
# 验证 Neo4j 是否真的启动了
36+
if ! neo4j status > /dev/null 2>&1; then
37+
echo "Failed to start Neo4j after 60 seconds"
38+
exit 1
39+
fi
40+
41+
# 额外等待确保 Neo4j 完全就绪
42+
echo "Waiting for Neo4j to be fully ready..."
43+
sleep 5
44+
45+
# 运行应用
46+
echo "Starting Graphiti MCP Server..."
47+
if [ -f "mcp_server.py" ]; then
48+
python mcp_server.py
49+
elif [ -f "main.py" ]; then
50+
python main.py
51+
elif [ -f "app.py" ]; then
52+
python app.py
53+
else
54+
echo "No application file found. Starting Python shell..."
55+
python
56+
fi

0 commit comments

Comments
 (0)