语音流MCP客户端
一个用于模型上下文协议(MCP)的Node.js客户端,与远程MCP服务器集成,为您的语音流代理提供工具。
特性
- 支持多个远程MCP服务器
- 用于服务器通信的HTTP传输
- 工具发现和与Claude AI的集成
- 通过JSON可配置的服务器集成
- 自动错误处理和重试
设置
先决条件
- Node.js 20.x或更高版本
- npm
安装
- 使用子模块克隆存储库:
git clone --recursive https://github.com/voiceflow-gallagan/voiceflow-mcp-server-client.git或者,如果您已经克隆了存储库,请初始化子模块:
git submodule update --init --recursive- 安装依赖项:
npm install- 构建MCP服务器:
npm run build这将:
- 设置Playwright依赖项(包括Chrome和Chromium)
- 初始化并更新Git子模块(天气mcp服务器和谷歌日历mcp)
- 构建气象MCP服务器
- 构建谷歌日历MCP服务器
注意:构建过程需要root权限才能安装Chrome。系统可能会提示您输入密码。
- 设置环境变量:
- 复制 .env.template 创建新 .env 文件:
cp .env.template .env- 更新 .env 文件中包含您的实际值:
ANTHROPIC_API_KEY=your-anthropic-api-key
CLAUDE_MODEL=claude-3-7-sonnet-20250219
PORT=3000
BRAVE_API_KEY=your-brave-api-key
LAST_RESPONSE_ONLY=false
SERVER_DISCOVERY_TIMEOUT=20000
ZAPIER_MCP_URL=https://actions.zapier.com/mcp/your-api-key/sse
MAX_CONVERSATION_HISTORY=10
TRUNCATE_TOOL_RESPONSES=false
GCP_SAVED_TOKENS={"access_token":"your-access-token","scope":"https://www.googleapis.com/auth/calendar","token_type":"Bearer","expiry_date":1234567890,"refresh_token":"your-refresh-token"}
GCP_OAUTH_KEYS={"installed":{"client_id":"your-client-id","project_id":"your-project-id","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"your-client-secret","redirect_uris":["http://localhost"]}}所需的环境变量:
- ANTHROPIC_API_KEY:Claude AI的Anthropic API密钥 - CLAUDE_MODEL:要使用的Claude模型(默认值:Claude-3-7-connect-20250219) - PORT:服务器的端口号(默认值:3000) - BRAVE_API_KEY:用于搜索功能的勇敢搜索API密钥 - LAST_RESPONSE_ONLY:当设置为“true”时,API响应中将只返回最后一个工具响应(默认值:false) - SERVER_DISCOVERY_TIMEOUT:等待服务器发现的最长时间(毫秒)(默认值:20000ms) - ZAPIER_MCP_URL:Zapier MCP服务器的可选URL(例如。,https://actions.zapier.com/mcp/your-api-key/sse) - MAX_CONVERSATION_HISTORY:对话历史记录中保留的最大消息数(默认值:10) - TRUNCATE_TOOL_RESPONSES:是否截断toolResponses数组中的工具响应(默认值:false) - 如果为true,工具响应将被截断为1000个字符 - 如果为false,完整的响应将保存在toolResponses中 - 注意:对话上下文中的工具响应总是被截断,以防止令牌限制问题 - MAX_FOLLOWUP_STEPS:允许的最大递归工具调用次数(默认值:5) - 更高的值允许更复杂的任务,但可能会增加处理时间 - 较低的值可以防止无限循环,但可能会限制任务完成 - PLAYWRIGHT_EXTENDED_STEPS:剧作家工具允许的最大递归工具调用数(默认值:8) - 网页浏览工具的单独限制,通常需要更多步骤 - 在复杂的网页浏览场景中增加此值
可选环境变量:
- GCP_SAVED_TOKENS:谷歌日历OAuth令牌(可选) - GCP_OAUTH_KEYS:谷歌日历OAuth凭据(可选)
动态服务器配置
客户端通过环境变量支持动态服务器配置。目前,此功能仅适用于Zapier MCP服务器。这使您能够:
- 在不修改代码的情况下启用/禁用Zapier服务器
- 使用API密钥安全地配置Zapier服务器
- 添加Zapier服务器而不更改代码
动态服务器配置示例:
- 将Zapier服务器URL添加到您的
.env文件:
ZAPIER_MCP_URL=https://actions.zapier.com/mcp/your-api-key/sse- Zapier服务器将在应用程序启动时自动配置。
- 要禁用Zapier服务器,只需删除或注释掉
ZAPIER_MCP_URL环境变量。
注意:虽然动态服务器配置功能目前仅限于Zapier服务器,但该架构支持在未来添加更多动态服务器。
谷歌日历设置
要使用Google Calendar MCP服务器,您需要设置OAuth 2.0凭据并将其添加到您的环境变量中:
- 转到 谷歌云控制台
- 创建新项目或选择现有项目
- 启用Google日历API
- 创建OAuth 2.0凭据:
- 转到“API和服务”>“凭据” - 点击“创建凭据”>“OAuth客户端ID” - 选择“桌面应用程序”作为应用程序类型 - 下载客户端配置文件
- 将这些环境变量添加到您的
.env文件:
GCP_SAVED_TOKENS={"access_token":"your-access-token","scope":"https://www.googleapis.com/auth/calendar","token_type":"Bearer","expiry_date":1234567890,"refresh_token":"your-refresh-token"}
GCP_OAUTH_KEYS={"installed":{"client_id":"your-client-id","project_id":"your-project-id","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"your-client-secret","redirect_uris":["http://localhost"]}}注意:这些值应该是整行JSON内容。您可以从以下位置获取这些值:
- GCP_SAVED_TOKENS:在第一个OAuth流之后,令牌将保存在 .gcp-saved-tokens.json - GCP_OAUTH_KEYS:从下载的客户端配置文件
- 创建一个
servers-config.json根目录中的文件,用于配置远程MCP服务器:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest", "--headless"]
},
"brave-search": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
"env": {
"BRAVE_API_KEY": "${BRAVE_API_KEY}"
}
},
"time-mcp": {
"command": "npx",
"args": ["-y", "time-mcp"]
},
"weather-server": {
"command": "node",
"args": ["mcp-servers/weather-mcp-server/build/index.js"],
"env": {
"OPENWEATHER_API_KEY": "${OPENWEATHER_API_KEY}"
},
"disabled": false,
"autoApprove": []
},
"google-calendar": {
"command": "node",
"args": ["./mcp-servers/google-calendar-mcp/build/index.js"]
}
}
}服务器配置支持:
- 基于命令的服务器(使用
command和args) - 环境变量替换(使用
${VARIABLE_NAME}) - 禁用服务器(使用
disabled: true) - 特定工具的自动批准(使用
autoApprove)
对于每个服务器,工具将以服务器名称作为前缀以避免冲突(例如。, weather_getWeather).
目前,只有Zapier服务器支持通过环境变量进行动态服务器配置。这允许您通过 ZAPIER_MCP_URL 环境变量。该架构支持在未来添加更多动态服务器。
Docker设置
先决条件
- Docker已安装在您的系统上
- Docker Compose(可选,便于管理)
使用Docker构建和运行
- 构建Docker镜像:
docker build -t mcp-client .- 运行容器:
docker run -p 3000:3000 \
--env-file .env \
--name mcp-client \
mcp-client或者使用Docker Compose(创建一个 docker-compose.yml 文件):
services:
mcp-client:
build: .
ports:
- "3135:3135"
env_file:
- .env
volumes:
- ./logs:/app/logs
restart: unless-stopped然后运行:
docker-compose up -dDocker环境变量
Docker容器使用与本地设置相同的环境变量。确保你的 .env 在构建映像之前,文件已正确配置。
Docker卷
以下目录可用于卷装载:
/app/logs:应用程序日志/app/public:静态文件
Docker健康检查
容器包含一个健康检查端点,位于 /health。您可以使用以下方式监视容器的运行状况:
docker inspect --format='{{.State.Health.Status}}' mcp-clientDocker命令
管理容器的常见Docker命令:
# Stop the container
docker stop mcp-client
# Start the container
docker start mcp-client
# View logs
docker logs mcp-client
# Remove the container
docker rm mcp-client
# Rebuild and restart with new changes
docker-compose up -d --build用法
运行客户端
启动API服务器:
npm start这将:
- 在端口3000(或.env文件中指定的端口)上启动API服务器
- 需要时自动连接到配置的远程MCP服务器
配置远程MCP服务器
此项目支持与远程MCP服务器集成。您可以使用 servers-config.json 项目根目录中的文件:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest", "--headless"]
},
"brave-search": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
"env": {
"BRAVE_API_KEY": "${BRAVE_API_KEY}"
}
},
"time-mcp": {
"command": "npx",
"args": ["-y", "time-mcp"]
},
"weather-server": {
"command": "node",
"args": ["mcp-servers/weather-mcp-server/build/index.js"],
"env": {
"OPENWEATHER_API_KEY": "${OPENWEATHER_API_KEY}"
},
"disabled": false,
"autoApprove": []
},
"google-calendar": {
"command": "node",
"args": ["./mcp-servers/google-calendar-mcp/build/index.js"]
}
}
}服务器配置支持:
- 基于命令的服务器(使用
command和args) - 环境变量替换(使用
${VARIABLE_NAME}) - 禁用服务器(使用
disabled: true) - 特定工具的自动批准(使用
autoApprove)
对于每个服务器,工具将以服务器名称作为前缀以避免冲突(例如。, weather_getWeather).
目前,只有Zapier服务器支持通过环境变量进行动态服务器配置。这允许您通过 ZAPIER_MCP_URL 环境变量。该架构支持在未来添加更多动态服务器。
API终点
健康检查
GET /返回API和可用MCP服务器的当前状态。
答复:
{
"status": "ok",
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest", "--headless"],
"disabled": false
},
"brave-search": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
"env": {
"BRAVE_API_KEY": "${BRAVE_API_KEY}"
},
"disabled": false
},
"time-mcp": {
"command": "npx",
"args": ["-y", "time-mcp"],
"disabled": false
},
"weather-server": {
"command": "node",
"args": ["mcp-servers/weather-mcp-server/build/index.js"],
"env": {
"OPENWEATHER_API_KEY": "${OPENWEATHER_API_KEY}"
},
"disabled": false,
"autoApprove": []
},
"google-calendar": {
"command": "node",
"args": ["./mcp-servers/google-calendar-mcp/build/index.js"],
"disabled": false
}
}
}流程查询
POST /api/query使用可用的MCP工具和Claude AI处理用户查询。
请求正文:
{
"query": "What is the weather in New York?",
"conversationId": "optional-conversation-id",
"userId": "optional-user-id",
"userEmail": "optional-user-email",
"queryTimeoutMs": 30000,
"llm_answer": false
}答复:
{
"query": "What is the weather in New York?",
"answer": "The AI's response here",
"conversationId": "conv-123456789",
"userId": "user-123",
"needsClarification": false,
"noAnswer": false,
"error": false,
"toolResponses": [
{
"tool": "weather_getWeather",
"input": { "location": "New York" },
"response": "The current temperature is 72°F with sunny conditions.",
"server": "weather"
}
]
}当 LAST_RESPONSE_ONLY=true 如果在环境中设置了,则只会返回最后一个工具响应。例如,如果调用多个工具:
{
"toolResponses": [
{
"tool": "time_getTime",
"input": { "location": "New York" },
"response": "The current time is 2:30 PM EDT",
"server": "time"
}
]
}可用参数:
query(必填):用户的问题或请求conversationId(可选):用于维护对话上下文的ID。如果没有提供,将创建一个新的对话userId(可选):发出请求的用户的IDuserEmail(可选):用户的电子邮件,用于日历相关工具queryTimeoutMs(可选):等待响应的最长时间(毫秒)。默认值为30000毫秒(30秒)llm_answer(可选):是否使用Claude生成最终答案。如果为false,则只返回工具响应。默认为false。
API将返回一个JSON响应,其中包含:
query:原始查询answer:AI的响应(如果llm_answer为false,则为null)conversationId:对话的ID(新的或现有的)userId:用户的ID(如果提供)needsClarification:布尔值,指示AI是否需要更多信息noAnswer:布尔值,指示AI是否无法使用可用工具回答查询error:布尔值,指示是否发生错误toolResponses:工具响应数组,每个响应包含:
- tool:被调用的工具的名称 - input:传递给工具的输入参数 - response:工具的响应 - server:提供该工具的MCP服务器的名称 - error:布尔值,指示工具调用是否失败(仅在true时存在)
获取用户对话
GET /api/conversations/:userId检索特定用户的所有对话。
参数:
userId(path参数):用户的ID
答复:
{
"userId": "user-123",
"conversations": [
{
"conversationId": "conv-123456789",
"firstMessage": "What is the weather in New York?",
"lastMessage": "The current temperature is 72°F with sunny conditions.",
"messageCount": 4
}
]
}清晰的对话
DELETE /api/conversation/:conversationId清除特定对话。
参数:
conversationId(path参数):要清除的对话的ID
答复:
{
"success": true,
"message": "Conversation conv-123456789 cleared successfully"
}清除用户对话
DELETE /api/conversations/:userId清除特定用户的所有对话。
参数:
userId(path参数):用户的ID
答复:
{
"success": true,
"message": "All conversations for user user-123 cleared successfully"
}获取可用服务器
GET /api/servers检索有关所有已配置的MCP服务器及其可用操作的信息。
答复:
{
"success": true,
"servers": {
"weather-server": {
"name": "weather-server",
"actions": [
{
"name": "getWeather",
"description": "Get current weather for a location",
"inputSchema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name or location"
}
},
"required": ["location"]
}
}
],
"enabled": true
},
"google-calendar": {
"name": "google-calendar",
"actions": [
{
"name": "listEvents",
"description": "List calendar events",
"inputSchema": {
"type": "object",
"properties": {
"maxResults": {
"type": "number",
"description": "Maximum number of events to return"
}
}
}
}
],
"enabled": true
}
}
}答复包括:
success:布尔值,指示请求是否成功servers:包含有关每个已配置服务器的信息的对象:
- name:服务器名称 - actions:服务器的可用操作数组,每个操作包含: - name:动作名称 - description:描述动作的作用 - inputSchema:描述预期输入参数的JSON模式 - enabled:布尔值,指示服务器是否已启用 - error:错误消息(仅在服务器无法提供操作时显示)
测试API
您可以使用curl测试API:
curl -X POST http://localhost:3000/api/query \
-H "Content-Type: application/json" \
-d '{
"query": "What is the weather in New York?",
"llm_answer": false
}'或者使用附带的演示:
node demo.js使用演示代理进行测试
要测试集成,您可以使用演示代理文件 MCP Agent Apr 1 2025.vf此代理被配置为与MCP客户端一起工作,并包括MCP工具功能。
注:演示代理旨在展示集成功能,可能需要使用特定的API密钥和配置进行更新。
发展
- 在开发模式下运行:
npm run dev
错误处理
客户端包括几种错误处理机制:
- 连接失败的重试机制
- 适当清理资源
- 调试详细日志记录
许可证
国际协调委员会

