- mcp-client-helper
mcp-client-helper
mcp client helper(管理,执行 mcp server)
Content
mcp-client-helper
MCP Server管理工具库 - 用于通过配置文件管理和控制多个MCP服务器实例
功能特性
- 通过配置管理多个MCP服务器
- 支持启动、停止和重启服务器
- 实时监控所有服务器状态
- 事件驱动的日志和错误处理
- 支持自定义环境变量配置
安装
npm install mcp-client-helper
配置格式
配置对象格式示例:
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "your-token-here"
}
},
"other-server": {
"command": "your-command",
"args": ["arg1", "arg2"],
"env": {
"KEY": "value"
}
}
}
}
使用示例
import { MCPServerManager } from 'mcp-client-helper';
import { readFileSync } from 'fs';
async function main() {
// 从配置文件加载配置
const config = JSON.parse(readFileSync('path/to/your/config.json', 'utf-8'));
// 创建服务器管理器实例
const manager = new MCPServerManager(config);
try {
// 获取所有配置的服务器名称
const serverNames = manager.getServerNames();
console.log('可用的服务器:', serverNames);
// 监听特定服务器的事件
manager.on('log', (serverName, log) => {
console.log(`[${serverName}] 日志:`, log);
});
manager.on('error', (serverName, error) => {
console.error(`[${serverName}] 错误:`, error);
});
manager.on('exit', (serverName, code) => {
console.log(`[${serverName}] 服务器退出,退出码:`, code);
});
// 启动指定的服务器
await manager.start('github');
// 获取服务器状态
const status = manager.getStatus('github');
console.log('服务器状态:', status);
// 重启服务器
await manager.restart('github');
// 停止服务器
await manager.stop('github');
// 动态更新配置
manager.updateConfig(newConfig);
} catch (error) {
console.error('错误:', error);
}
}
main().catch(console.error);
API文档
MCPServerManager
构造函数
constructor(config: MCPConfig)
配置参数:
config: MCP服务器配置对象,包含所有要管理的服务器配置
方法
start(serverName: string): Promise<void>: 启动指定的服务器stop(serverName: string): Promise<void>: 停止指定的服务器restart(serverName: string): Promise<void>: 重启指定的服务器getStatus(serverName: string): ServerStatus | undefined: 获取指定服务器的状态getAllStatuses(): Record<string, ServerStatus>: 获取所有服务器的状态getServerNames(): string[]: 获取所有配置的服务器名称updateConfig(config: MCPConfig): void: 动态更新服务器配置
事件
log:(serverName: string, log: string) => void- 服务器日志输出error:(serverName: string, error: string) => void- 服务器错误输出exit:(serverName: string, code: number | null) => void- 服务器退出事件
配置类型定义
interface MCPServerConfig {
command: string; // 服务器启动命令
args: string[]; // 命令行参数
env?: Record<string, string>; // 环境变量
}
interface MCPConfig {
mcpServers: Record<string, MCPServerConfig>; // 服务器配置映射
}
interface ServerStatus {
isRunning: boolean; // 是否正在运行
pid?: number; // 进程ID
startTime?: Date; // 启动时间
name: string; // 服务器名称
command: string; // 启动命令
}
开发要求
- Node.js >= 14.0.0
- TypeScript >= 4.0.0
许可证
ISC
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
DeepChatYour AI Partner on Desktop
WindsurfThe new purpose-built IDE to harness magic
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
ChatWiseThe second fastest AI chatbot™
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题;
Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Playwright McpPlaywright MCP server
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Tavily Mcp
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
CursorThe AI Code Editor
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Serper MCP ServerA Serper MCP Server
Amap Maps高德地图官方 MCP Server