From 884870c9ded10201fc99291b58754e3421b5c3c9 Mon Sep 17 00:00:00 2001 From: samanhappy Date: Sun, 30 Nov 2025 17:20:01 +0800 Subject: [PATCH] refactor: Simplify database configuration instructions and update API endpoint references (#457) --- docs/configuration/database-configuration.mdx | 57 +++++-------------- .../configuration/database-configuration.mdx | 57 +++++-------------- docs/zh/development.mdx | 36 ------------ docs/zh/essentials/code.mdx | 22 +++---- docs/zh/essentials/markdown.mdx | 4 +- docs/zh/essentials/navigation.mdx | 21 +------ 6 files changed, 42 insertions(+), 155 deletions(-) diff --git a/docs/configuration/database-configuration.mdx b/docs/configuration/database-configuration.mdx index fcd9815..42d5b7c 100644 --- a/docs/configuration/database-configuration.mdx +++ b/docs/configuration/database-configuration.mdx @@ -23,34 +23,29 @@ DB_URL=postgresql://user:password@localhost:5432/mcphub # Or explicitly control with USE_DB (overrides auto-detection) # USE_DB=true - -# Alternative: Use separate components -# DB_HOST=localhost -# DB_PORT=5432 -# DB_NAME=mcphub -# DB_USER=user -# DB_PASSWORD=password ``` **Simplified Configuration**: You only need to set `DB_URL` to enable database mode. MCPHub will automatically detect and enable database mode when `DB_URL` is present. Use `USE_DB=false` to explicitly disable database mode even when `DB_URL` is set. -### Optional Settings - -```bash -# Automatic migration on startup (default: true) -AUTO_MIGRATE=true - -# Keep file-based config as fallback (default: false) -KEEP_FILE_CONFIG=false -``` - ## Setup Instructions ### 1. Using Docker -#### Option A: Using PostgreSQL as a separate service +#### Option A: Using External Database + +If you already have a PostgreSQL database: + +```bash +docker run -d \ + -p 3000:3000 \ + -v ./mcp_settings.json:/app/mcp_settings.json \ + -e DB_URL="postgresql://user:password@your-db-host:5432/mcphub" \ + samanhappy/mcphub +``` + +#### Option B: Using PostgreSQL as a separate service Create a `docker-compose.yml`: @@ -89,18 +84,6 @@ Run with: docker-compose up -d ``` -#### Option B: Using External Database - -If you already have a PostgreSQL database: - -```bash -docker run -d \ - -p 3000:3000 \ - -e USE_DB=true \ - -e DB_URL="postgresql://user:password@your-db-host:5432/mcphub" \ - samanhappy/mcphub:latest -``` - ### 2. Manual Setup #### Step 1: Setup PostgreSQL Database @@ -232,7 +215,7 @@ docker exec -i postgres psql -U mcphub mcphub < mcphub_backup.sql If you need to switch back to file-based configuration: -1. Set `USE_DB=false` or remove the environment variable +1. Set `USE_DB=false` or remove `DB_URL` and `USE_DB` environment variables 2. Restart MCPHub 3. MCPHub will use `mcp_settings.json` again @@ -288,12 +271,6 @@ Database tables are automatically created if they don't exist. If you get errors |----------|----------|---------|-------------| | `DB_URL` | Yes* | - | Full PostgreSQL connection URL. Setting this automatically enables database mode | | `USE_DB` | No | auto | Explicitly enable/disable database mode. If not set, auto-detected based on `DB_URL` presence | -| `DB_HOST` | No | `localhost` | Database host (if not using DB_URL) | -| `DB_PORT` | No | `5432` | Database port (if not using DB_URL) | -| `DB_NAME` | No | `mcphub` | Database name (if not using DB_URL) | -| `DB_USER` | No | `mcphub` | Database user (if not using DB_URL) | -| `DB_PASSWORD` | No | - | Database password (if not using DB_URL) | -| `AUTO_MIGRATE` | No | `true` | Auto-migrate from file on first start | | `MCPHUB_SETTING_PATH` | No | - | Path to mcp_settings.json (for migration) | *Required for database mode. Simply setting `DB_URL` enables database mode automatically @@ -320,9 +297,3 @@ File mode may be faster for: - Single user setups - Read-heavy workloads with infrequent changes - Development/testing environments - -## Support - -For issues or questions: -- GitHub Issues: https://github.com/samanhappy/mcphub/issues -- Documentation: https://mcphub.io/docs diff --git a/docs/zh/configuration/database-configuration.mdx b/docs/zh/configuration/database-configuration.mdx index b050b16..3226c1f 100644 --- a/docs/zh/configuration/database-configuration.mdx +++ b/docs/zh/configuration/database-configuration.mdx @@ -23,34 +23,29 @@ DB_URL=postgresql://user:password@localhost:5432/mcphub # 或显式控制 USE_DB(覆盖自动检测) # USE_DB=true - -# 替代方案:使用单独的配置项 -# DB_HOST=localhost -# DB_PORT=5432 -# DB_NAME=mcphub -# DB_USER=user -# DB_PASSWORD=password ``` **简化配置**:您只需设置 `DB_URL` 即可启用数据库模式。MCPHub 会自动检测 `DB_URL` 是否存在并启用数据库模式。如果需要在设置了 `DB_URL` 的情况下禁用数据库模式,可以显式设置 `USE_DB=false`。 -### 可选设置 - -```bash -# 启动时自动迁移(默认:true) -AUTO_MIGRATE=true - -# 保留基于文件的配置作为后备(默认:false) -KEEP_FILE_CONFIG=false -``` - ## 设置说明 ### 1. 使用 Docker -#### 方案 A:将 PostgreSQL 作为独立服务 +#### 方案 A:使用外部数据库 + +如果您已有 PostgreSQL 数据库: + +```bash +docker run -d \ + -p 3000:3000 \ + -v ./mcp_settings.json:/app/mcp_settings.json \ + -e DB_URL="postgresql://user:password@your-db-host:5432/mcphub" \ + samanhappy/mcphub +``` + +#### 方案 B:将 PostgreSQL 作为独立服务 创建 `docker-compose.yml` 文件: @@ -89,18 +84,6 @@ volumes: docker-compose up -d ``` -#### 方案 B:使用外部数据库 - -如果您已有 PostgreSQL 数据库: - -```bash -docker run -d \ - -p 3000:3000 \ - -e USE_DB=true \ - -e DB_URL="postgresql://user:password@your-db-host:5432/mcphub" \ - samanhappy/mcphub:latest -``` - ### 2. 手动设置 #### 步骤 1:设置 PostgreSQL 数据库 @@ -232,7 +215,7 @@ docker exec -i postgres psql -U mcphub mcphub < mcphub_backup.sql 如果您需要切换回基于文件的配置: -1. 设置 `USE_DB=false` 或删除该环境变量 +1. 设置 `USE_DB=false` 或删除 `DB_URL` 和 `USE_DB` 环境变量 2. 重启 MCPHub 3. MCPHub 将再次使用 `mcp_settings.json` @@ -288,12 +271,6 @@ Error: password authentication failed for user "mcphub" |------|------|--------|------| | `DB_URL` | 是* | - | 完整的 PostgreSQL 连接 URL。设置此变量会自动启用数据库模式 | | `USE_DB` | 否 | 自动 | 显式启用/禁用数据库模式。如果未设置,根据 `DB_URL` 是否存在自动检测 | -| `DB_HOST` | 否 | `localhost` | 数据库主机(如果不使用 DB_URL) | -| `DB_PORT` | 否 | `5432` | 数据库端口(如果不使用 DB_URL) | -| `DB_NAME` | 否 | `mcphub` | 数据库名称(如果不使用 DB_URL) | -| `DB_USER` | 否 | `mcphub` | 数据库用户(如果不使用 DB_URL) | -| `DB_PASSWORD` | 否 | - | 数据库密码(如果不使用 DB_URL) | -| `AUTO_MIGRATE` | 否 | `true` | 首次启动时自动从文件迁移 | | `MCPHUB_SETTING_PATH` | 否 | - | mcp_settings.json 的路径(用于迁移) | *数据库模式必需。只需设置 `DB_URL` 即可自动启用数据库模式 @@ -320,9 +297,3 @@ Error: password authentication failed for user "mcphub" - 单用户设置 - 读取密集型工作负载且更改不频繁 - 开发/测试环境 - -## 支持 - -如有问题或疑问: -- GitHub Issues: https://github.com/samanhappy/mcphub/issues -- 文档: https://mcphub.io/docs diff --git a/docs/zh/development.mdx b/docs/zh/development.mdx index e91d580..0ba34d5 100644 --- a/docs/zh/development.mdx +++ b/docs/zh/development.mdx @@ -123,42 +123,6 @@ nano .env NODE_ENV=development PORT=3000 HOST=localhost - -# 数据库配置 -DATABASE_URL=sqlite:./data/dev.db - -# JWT 配置 -JWT_SECRET=dev-jwt-secret-key -JWT_EXPIRES_IN=7d - -# 日志配置 -LOG_LEVEL=debug -LOG_FORMAT=dev - -# CORS 配置 -CORS_ORIGIN=http://localhost:3000,http://localhost:3001 - -# 管理员账户 -ADMIN_EMAIL=dev@mcphub.io -ADMIN_PASSWORD=dev123 - -# 开发功能开关 -ENABLE_DEBUG_ROUTES=true -ENABLE_SWAGGER=true -ENABLE_HOT_RELOAD=true -``` - -### 数据库初始化 - -```bash -# 生成 Prisma 客户端 -npx prisma generate - -# 运行数据库迁移 -npx prisma migrate dev --name init - -# 填充测试数据 -npm run db:seed ``` ## 启动开发服务器 diff --git a/docs/zh/essentials/code.mdx b/docs/zh/essentials/code.mdx index 64e274f..149438d 100644 --- a/docs/zh/essentials/code.mdx +++ b/docs/zh/essentials/code.mdx @@ -528,7 +528,7 @@ docker-compose up -d ````md ```bash # 创建新的 MCP 服务器 -curl -X POST https://api.mcphub.io/api/servers \ +curl -X POST http://localhost:3000/api/servers \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{ @@ -539,11 +539,11 @@ curl -X POST https://api.mcphub.io/api/servers \ }' # 获取服务器列表 -curl -X GET "https://api.mcphub.io/api/servers?limit=10&active=true" \ +curl -X GET "http://localhost:3000/api/servers?limit=10&active=true" \ -H "Authorization: Bearer YOUR_API_TOKEN" # 更新服务器配置 -curl -X PUT https://api.mcphub.io/api/servers/server-123 \ +curl -X PUT http://localhost:3000/api/servers/server-123 \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{ @@ -552,14 +552,14 @@ curl -X PUT https://api.mcphub.io/api/servers/server-123 \ }' # 删除服务器 -curl -X DELETE https://api.mcphub.io/api/servers/server-123 \ +curl -X DELETE http://localhost:3000/api/servers/server-123 \ -H "Authorization: Bearer YOUR_API_TOKEN" ``` ```` ```bash # 创建新的 MCP 服务器 -curl -X POST https://api.mcphub.io/api/servers \ +curl -X POST http://localhost:3000/api/servers \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{ @@ -570,11 +570,11 @@ curl -X POST https://api.mcphub.io/api/servers \ }' # 获取服务器列表 -curl -X GET "https://api.mcphub.io/api/servers?limit=10&active=true" \ +curl -X GET "http://localhost:3000/api/servers?limit=10&active=true" \ -H "Authorization: Bearer YOUR_API_TOKEN" # 更新服务器配置 -curl -X PUT https://api.mcphub.io/api/servers/server-123 \ +curl -X PUT http://localhost:3000/api/servers/server-123 \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{ @@ -583,7 +583,7 @@ curl -X PUT https://api.mcphub.io/api/servers/server-123 \ }' # 删除服务器 -curl -X DELETE https://api.mcphub.io/api/servers/server-123 \ +curl -X DELETE http://localhost:3000/api/servers/server-123 \ -H "Authorization: Bearer YOUR_API_TOKEN" ``` @@ -592,7 +592,7 @@ curl -X DELETE https://api.mcphub.io/api/servers/server-123 \ ````md ```http POST /api/servers HTTP/1.1 -Host: api.mcphub.io +Host: localhost:3000 Authorization: Bearer YOUR_API_TOKEN Content-Type: application/json @@ -607,7 +607,7 @@ Content-Type: application/json ```http POST /api/servers HTTP/1.1 -Host: api.mcphub.io +Host: localhost:3000 Authorization: Bearer YOUR_API_TOKEN Content-Type: application/json @@ -746,7 +746,7 @@ app.listen(port, () => { ```javascript // 初始化 MCPHub 客户端 const client = new MCPHubClient({ - endpoint: 'https://api.mcphub.io', + endpoint: 'http://localhost:3000', apiKey: process.env.API_KEY, timeout: 30000, // 30 秒超时 retries: 3, // 重试 3 次 diff --git a/docs/zh/essentials/markdown.mdx b/docs/zh/essentials/markdown.mdx index bc18296..45cb343 100644 --- a/docs/zh/essentials/markdown.mdx +++ b/docs/zh/essentials/markdown.mdx @@ -133,7 +133,7 @@ MCPHub 主要功能: ```javascript // MCPHub 客户端初始化 const mcpClient = new MCPClient({ - endpoint: 'https://api.mcphub.io', + endpoint: 'http://localhost:3000', apiKey: process.env.MCPHUB_API_KEY, }); ``` @@ -142,7 +142,7 @@ const mcpClient = new MCPClient({ ```javascript // MCPHub 客户端初始化 const mcpClient = new MCPClient({ - endpoint: 'https://api.mcphub.io', + endpoint: 'http://localhost:3000', apiKey: process.env.MCPHUB_API_KEY, }); ``` diff --git a/docs/zh/essentials/navigation.mdx b/docs/zh/essentials/navigation.mdx index e90f8bd..a09eaee 100644 --- a/docs/zh/essentials/navigation.mdx +++ b/docs/zh/essentials/navigation.mdx @@ -241,20 +241,6 @@ MCPHub 文档支持多级分层导航: ```json title="docs.json" { - "tabs": [ - { - "name": "文档", - "url": "https://docs.mcphub.io" - }, - { - "name": "API", - "url": "https://api.mcphub.io" - }, - { - "name": "SDK", - "url": "https://sdk.mcphub.io" - } - ], "navigation": { "文档": [ { @@ -336,13 +322,8 @@ MCPHub 文档支持以下图标库的图标: }, { "name": "Discord 社区", - "url": "https://discord.gg/mcphub", + "url": "https://discord.gg/qMKNsn5Q", "icon": "discord" - }, - { - "name": "状态页面", - "url": "https://status.mcphub.io", - "icon": "status" } ] }