使用说明
带MCP服务器的Nx monorepo
此工作区使用Nx初始化,并包含基于节点的MCP服务器应用程序 mcp-server.
先决条件
- Node.js 18+
npm install
环境配置
该项目使用 dotenv 从加载环境变量 .env 本地开发文件。
-
创建
.env示例中的文件:cp env.example .env -
编辑
.env文件 根据您的配置:# Icons CDN Configuration ICONS_CDN_BASE_URL=https://gpt-mcp-server-2.vercel.app # or for local development with ngrok: # ICONS_CDN_BASE_URL=https://your-ngrok-domain.ngrok-free.dev # Widget Domain WIDGET_DOMAIN=https://italki.com # Server Configuration PORT=3030 -
环境变量会自动加载 当您在本地运行服务器时。
注: 对于Vercel部署,请在Vercel项目设置中设置环境变量,而不是使用
.env文件。
环境配置
创建 .env 项目根目录中的文件基于 env.example:
cp env.example .env
然后编辑 .env 配置您的设置。关键环境变量:
ICONS_CDN_BASE_URL:用于提供静态图标的CDN基础URL(例如。,https://gpt-mcp-server-2.vercel.app或您的ngrok域名)WIDGET_DOMAIN:用于OpenAI小部件子域生成的域(默认值:https://italki.com)PORT:服务器端口(默认值:3030)- 看
env.example对于所有可用的配置选项。
有用的命令
- 构建:
npx nx build mcp-server
- 运行(HTTP/SSE传输):
node dist/mcp-server/main.js
测试服务器
-
启动服务器(仅限HTTP):
node dist/mcp-server/main.js -
使用HTTPS启动服务器:
# 生成 SSL 证书(仅开发环境) ./scripts/generate-ssl-cert.sh # 启动 HTTPS 服务器 USE_HTTPS=true node dist/mcp-server/main.js -
健康检查:
# HTTP curl http://localhost:3030/health # HTTPS curl -k https://localhost:3443/health -
访问日志配置:
# Common Log Format (default) with request/response content and MCP headers LOG_FORMAT=common LOG_REQUEST_RESPONSE=true node dist/mcp-server/main.js # JSON format with request/response content and MCP headers LOG_FORMAT=json LOG_REQUEST_RESPONSE=true node dist/mcp-server/main.js # Disable request/response content and MCP headers logging LOG_REQUEST_RESPONSE=false node dist/mcp-server/main.js # Disable access logs completely ENABLE_ACCESS_LOG=false node dist/mcp-server/main.js会话功能:
- 每个会话在
Mcp-Session-Id头球 - 会话在30分钟不活动后自动过期
- 多个客户端可以同时连接不同的会话
- 如果找不到会话ID,服务器将返回400错误
- 每个会话在
