From d36c6ac5ad7f1f3f1012cb627d1f521a27a8a3ca Mon Sep 17 00:00:00 2001 From: samanhappy Date: Thu, 1 Jan 2026 21:58:11 +0800 Subject: [PATCH] fix: rename DATABASE_URL to DB_URL for consistency across configurations (#545) --- .github/workflows/ci.yml | 2 +- docs/configuration/docker-setup.mdx | 6 +++--- docs/development/getting-started.mdx | 2 +- docs/features/smart-routing.mdx | 16 ++++++++-------- docs/installation.mdx | 6 +++--- docs/zh/configuration/docker-setup.mdx | 6 +++--- docs/zh/configuration/mcp-settings.mdx | 2 +- docs/zh/development/getting-started.mdx | 2 +- docs/zh/essentials/code.mdx | 4 ++-- docs/zh/essentials/markdown.mdx | 4 ++-- docs/zh/features/smart-routing.mdx | 4 ++-- docs/zh/installation.mdx | 6 +++--- examples/mcp_settings_with_env_vars.json | 9 ++++++--- src/utils/smartRouting.ts | 2 +- tests/setup.ts | 4 ++-- 15 files changed, 39 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c0c49f..67e2248 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,7 +106,7 @@ jobs: # - name: Run integration tests # run: | - # export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mcphub_test" + # export DB_URL="postgresql://postgres:postgres@localhost:5432/mcphub_test" # node test-integration.ts # env: # NODE_ENV: test diff --git a/docs/configuration/docker-setup.mdx b/docs/configuration/docker-setup.mdx index 69748c7..ee98b23 100644 --- a/docs/configuration/docker-setup.mdx +++ b/docs/configuration/docker-setup.mdx @@ -106,7 +106,7 @@ services: - NODE_ENV=production - PORT=3000 - JWT_SECRET=${JWT_SECRET:-your-jwt-secret} - - DATABASE_URL=postgresql://mcphub:password@postgres:5432/mcphub + - DB_URL=postgresql://mcphub:password@postgres:5432/mcphub volumes: - ./mcp_settings.json:/app/mcp_settings.json:ro - ./servers.json:/app/servers.json:ro @@ -180,7 +180,7 @@ services: - PORT=3000 - JWT_SECRET=${JWT_SECRET} - JWT_EXPIRES_IN=${JWT_EXPIRES_IN:-24h} - - DATABASE_URL=postgresql://mcphub:${POSTGRES_PASSWORD}@postgres:5432/mcphub + - DB_URL=postgresql://mcphub:${POSTGRES_PASSWORD}@postgres:5432/mcphub - OPENAI_API_KEY=${OPENAI_API_KEY} - REDIS_URL=redis://redis:6379 volumes: @@ -293,7 +293,7 @@ services: environment: - NODE_ENV=development - PORT=3000 - - DATABASE_URL=postgresql://mcphub:password@postgres:5432/mcphub + - DB_URL=postgresql://mcphub:password@postgres:5432/mcphub volumes: - .:/app - /app/node_modules diff --git a/docs/development/getting-started.mdx b/docs/development/getting-started.mdx index 315629b..ec71e92 100644 --- a/docs/development/getting-started.mdx +++ b/docs/development/getting-started.mdx @@ -47,7 +47,7 @@ PORT=3000 NODE_ENV=development # Database Configuration -DATABASE_URL=postgresql://username:password@localhost:5432/mcphub +DB_URL=postgresql://username:password@localhost:5432/mcphub # JWT Configuration JWT_SECRET=your-secret-key diff --git a/docs/features/smart-routing.mdx b/docs/features/smart-routing.mdx index 3618367..f92de11 100644 --- a/docs/features/smart-routing.mdx +++ b/docs/features/smart-routing.mdx @@ -69,7 +69,7 @@ Smart Routing requires additional setup compared to basic MCPHub usage: ports: - "3000:3000" environment: - - DATABASE_URL=postgresql://mcphub:password@postgres:5432/mcphub + - DB_URL=postgresql://mcphub:password@postgres:5432/mcphub - OPENAI_API_KEY=your_openai_api_key - ENABLE_SMART_ROUTING=true depends_on: @@ -114,7 +114,7 @@ Smart Routing requires additional setup compared to basic MCPHub usage: 2. **Set Environment Variables**: ```bash - export DATABASE_URL="postgresql://mcphub:your_password@localhost:5432/mcphub" + export DB_URL="postgresql://mcphub:your_password@localhost:5432/mcphub" export OPENAI_API_KEY="your_openai_api_key" export ENABLE_SMART_ROUTING="true" ``` @@ -178,7 +178,7 @@ Smart Routing requires additional setup compared to basic MCPHub usage: - name: mcphub image: samanhappy/mcphub:latest env: - - name: DATABASE_URL + - name: DB_URL value: "postgresql://mcphub:password@postgres:5432/mcphub" - name: OPENAI_API_KEY valueFrom: @@ -202,7 +202,7 @@ Configure Smart Routing with these environment variables: ```bash # Required -DATABASE_URL=postgresql://user:password@host:5432/database +DB_URL=postgresql://user:password@host:5432/database OPENAI_API_KEY=your_openai_api_key # Optional @@ -219,10 +219,10 @@ EMBEDDING_BATCH_SIZE=100 ```bash # Full PostgreSQL connection string - DATABASE_URL=postgresql://username:password@host:port/database?schema=public + DB_URL=postgresql://username:password@host:port/database?schema=public # SSL configuration for cloud databases - DATABASE_URL=postgresql://user:pass@host:5432/db?sslmode=require + DB_URL=postgresql://user:pass@host:5432/db?sslmode=require # Connection pool settings DATABASE_POOL_SIZE=20 @@ -673,11 +673,11 @@ curl -X POST http://localhost:3000/api/smart-routing/feedback \ **Solutions:** 1. Verify PostgreSQL is running - 2. Check DATABASE_URL format + 2. Check DB_URL format 3. Ensure pgvector extension is installed 4. Test connection manually: ```bash - psql $DATABASE_URL -c "SELECT 1;" + psql $DB_URL -c "SELECT 1;" ``` diff --git a/docs/installation.mdx b/docs/installation.mdx index 8eb97d3..6c3ea0b 100644 --- a/docs/installation.mdx +++ b/docs/installation.mdx @@ -445,7 +445,7 @@ Set the following environment variables: ```bash # Database connection -DATABASE_URL=postgresql://mcphub:your_password@localhost:5432/mcphub +DB_URL=postgresql://mcphub:your_password@localhost:5432/mcphub # OpenAI API for embeddings OPENAI_API_KEY=your_openai_api_key @@ -563,10 +563,10 @@ curl -X POST http://localhost:3000/mcp \ **Database connection failed:** ```bash # Test database connection - psql $DATABASE_URL -c "SELECT 1;" + psql $DB_URL -c "SELECT 1;" # Check if pgvector is installed - psql $DATABASE_URL -c "CREATE EXTENSION IF NOT EXISTS vector;" + psql $DB_URL -c "CREATE EXTENSION IF NOT EXISTS vector;" ``` **Embedding service errors:** diff --git a/docs/zh/configuration/docker-setup.mdx b/docs/zh/configuration/docker-setup.mdx index 8d7f65e..5e82a9d 100644 --- a/docs/zh/configuration/docker-setup.mdx +++ b/docs/zh/configuration/docker-setup.mdx @@ -106,7 +106,7 @@ services: - NODE_ENV=production - PORT=3000 - JWT_SECRET=${JWT_SECRET:-your-jwt-secret} - - DATABASE_URL=postgresql://mcphub:password@postgres:5432/mcphub + - DB_URL=postgresql://mcphub:password@postgres:5432/mcphub volumes: - ./mcp_settings.json:/app/mcp_settings.json:ro - ./servers.json:/app/servers.json:ro @@ -180,7 +180,7 @@ services: - PORT=3000 - JWT_SECRET=${JWT_SECRET} - JWT_EXPIRES_IN=${JWT_EXPIRES_IN:-24h} - - DATABASE_URL=postgresql://mcphub:${POSTGRES_PASSWORD}@postgres:5432/mcphub + - DB_URL=postgresql://mcphub:${POSTGRES_PASSWORD}@postgres:5432/mcphub - OPENAI_API_KEY=${OPENAI_API_KEY} - REDIS_URL=redis://redis:6379 volumes: @@ -293,7 +293,7 @@ services: environment: - NODE_ENV=development - PORT=3000 - - DATABASE_URL=postgresql://mcphub:password@postgres:5432/mcphub + - DB_URL=postgresql://mcphub:password@postgres:5432/mcphub volumes: - .:/app - /app/node_modules diff --git a/docs/zh/configuration/mcp-settings.mdx b/docs/zh/configuration/mcp-settings.mdx index fdfdd89..676c188 100644 --- a/docs/zh/configuration/mcp-settings.mdx +++ b/docs/zh/configuration/mcp-settings.mdx @@ -290,7 +290,7 @@ MCPHub 支持使用 `${VAR_NAME}` 语法进行环境变量替换: "command": "python", "args": ["-m", "db_server"], "env": { - "DB_URL": "${NODE_ENV:development == 'production' ? DATABASE_URL : DEV_DATABASE_URL}" + "DB_URL": "${NODE_ENV:development == 'production' ? DB_URL : DEV_DB_URL}" } } } diff --git a/docs/zh/development/getting-started.mdx b/docs/zh/development/getting-started.mdx index c319b0d..b5ca5ee 100644 --- a/docs/zh/development/getting-started.mdx +++ b/docs/zh/development/getting-started.mdx @@ -47,7 +47,7 @@ PORT=3000 NODE_ENV=development # 数据库配置 -DATABASE_URL=postgresql://username:password@localhost:5432/mcphub +DB_URL=postgresql://username:password@localhost:5432/mcphub # JWT 配置 JWT_SECRET=your-secret-key diff --git a/docs/zh/essentials/code.mdx b/docs/zh/essentials/code.mdx index 149438d..ae78378 100644 --- a/docs/zh/essentials/code.mdx +++ b/docs/zh/essentials/code.mdx @@ -480,7 +480,7 @@ docker run -d \ --name mcphub \ -p 3000:3000 \ -e NODE_ENV=production \ - -e DATABASE_URL=postgresql://user:pass@host:5432/mcphub \ + -e DB_URL=postgresql://user:pass@host:5432/mcphub \ -e JWT_SECRET=your-secret-key \ mcphub/server:latest @@ -504,7 +504,7 @@ docker run -d \ --name mcphub \ -p 3000:3000 \ -e NODE_ENV=production \ - -e DATABASE_URL=postgresql://user:pass@host:5432/mcphub \ + -e DB_URL=postgresql://user:pass@host:5432/mcphub \ -e JWT_SECRET=your-secret-key \ mcphub/server:latest diff --git a/docs/zh/essentials/markdown.mdx b/docs/zh/essentials/markdown.mdx index 45cb343..b9d9fb0 100644 --- a/docs/zh/essentials/markdown.mdx +++ b/docs/zh/essentials/markdown.mdx @@ -159,7 +159,7 @@ services: - '3000:3000' environment: - NODE_ENV=production - - DATABASE_URL=postgresql://user:pass@db:5432/mcphub + - DB_URL=postgresql://user:pass@db:5432/mcphub ``` ```` @@ -172,7 +172,7 @@ services: - '3000:3000' environment: - NODE_ENV=production - - DATABASE_URL=postgresql://user:pass@db:5432/mcphub + - DB_URL=postgresql://user:pass@db:5432/mcphub ``` ### 终端命令 diff --git a/docs/zh/features/smart-routing.mdx b/docs/zh/features/smart-routing.mdx index 1758fd1..40e9b64 100644 --- a/docs/zh/features/smart-routing.mdx +++ b/docs/zh/features/smart-routing.mdx @@ -245,11 +245,11 @@ curl -X POST http://localhost:3000/api/smart-routing/feedback \ **解决方案:** 1. 验证 PostgreSQL 是否正在运行 - 2. 检查 DATABASE_URL 格式 + 2. 检查 DB_URL 格式 3. 确保安装了 pgvector 扩展 4. 手动测试连接: ```bash - psql $DATABASE_URL -c "SELECT 1;" + psql $DB_URL -c "SELECT 1;" ``` diff --git a/docs/zh/installation.mdx b/docs/zh/installation.mdx index aa5876e..ffebbe8 100644 --- a/docs/zh/installation.mdx +++ b/docs/zh/installation.mdx @@ -420,7 +420,7 @@ description: '各种平台的详细安装说明' ```bash # 数据库连接 -DATABASE_URL=postgresql://mcphub:your_password@localhost:5432/mcphub +DB_URL=postgresql://mcphub:your_password@localhost:5432/mcphub # 用于嵌入的 OpenAI API OPENAI_API_KEY=your_openai_api_key @@ -538,10 +538,10 @@ curl -X POST http://localhost:3000/mcp \ **数据库连接失败:** ```bash # 测试数据库连接 - psql $DATABASE_URL -c "SELECT 1;" + psql $DB_URL -c "SELECT 1;" # 检查是否安装了 pgvector - psql $DATABASE_URL -c "CREATE EXTENSION IF NOT EXISTS vector;" + psql $DB_URL -c "CREATE EXTENSION IF NOT EXISTS vector;" ``` **嵌入服务错误:** diff --git a/examples/mcp_settings_with_env_vars.json b/examples/mcp_settings_with_env_vars.json index c36d4c6..1fba9b6 100644 --- a/examples/mcp_settings_with_env_vars.json +++ b/examples/mcp_settings_with_env_vars.json @@ -28,7 +28,7 @@ "env": { "API_KEY": "${MY_API_KEY}", "DEBUG": "${DEBUG_MODE}", - "DATABASE_URL": "${DATABASE_URL}" + "DB_URL": "${DB_URL}" } }, "example-stdio-with-proxy": { @@ -96,7 +96,10 @@ "clientId": "${OAUTH_CLIENT_ID}", "clientSecret": "${OAUTH_CLIENT_SECRET}", "accessToken": "${OAUTH_ACCESS_TOKEN}", - "scopes": ["read", "write"] + "scopes": [ + "read", + "write" + ] } } }, @@ -118,4 +121,4 @@ "baseUrl": "${MCPROUTER_BASE_URL}" } } -} +} \ No newline at end of file diff --git a/src/utils/smartRouting.ts b/src/utils/smartRouting.ts index 5f61c7c..e0340fb 100644 --- a/src/utils/smartRouting.ts +++ b/src/utils/smartRouting.ts @@ -17,7 +17,7 @@ export interface SmartRoutingConfig { * * Priority order for each setting: * 1. Specific environment variables (ENABLE_SMART_ROUTING, SMART_ROUTING_ENABLED, etc.) - * 2. Generic environment variables (OPENAI_API_KEY, DATABASE_URL, etc.) + * 2. Generic environment variables (OPENAI_API_KEY, DB_URL, etc.) * 3. Settings configuration (systemConfig.smartRouting) * 4. Default values * diff --git a/tests/setup.ts b/tests/setup.ts index 83ae455..47652d0 100644 --- a/tests/setup.ts +++ b/tests/setup.ts @@ -5,7 +5,7 @@ import 'reflect-metadata'; Object.assign(process.env, { NODE_ENV: 'test', JWT_SECRET: 'test-jwt-secret-key', - DATABASE_URL: 'sqlite::memory:', + DB_URL: 'sqlite::memory:', }); // Mock moduleDir to avoid import.meta parsing issues in Jest @@ -40,7 +40,7 @@ expect.extend({ }; } }, - + toBeValidUUID(received: any) { const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; const pass = typeof received === 'string' && uuidRegex.test(received);