mcp-client-helper

mcp-client-helper

mcp client helper(管理,执行 mcp server)

Yangbin-v

Developer Tools
Visit Server

README

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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
MCP Package Docs Server

MCP Package Docs Server

Facilitates LLMs to efficiently access and fetch structured documentation for packages in Go, Python, and NPM, enhancing software development with multi-language support and performance optimization.

Featured
Local
TypeScript
Claude Code MCP

Claude Code MCP

An implementation of Claude Code as a Model Context Protocol server that enables using Claude's software engineering capabilities (code generation, editing, reviewing, and file operations) through the standardized MCP interface.

Featured
Local
JavaScript
@kazuph/mcp-taskmanager

@kazuph/mcp-taskmanager

Model Context Protocol server for Task Management. This allows Claude Desktop (or any MCP client) to manage and execute tasks in a queue-based system.

Featured
Local
JavaScript
Linear MCP Server

Linear MCP Server

Enables interaction with Linear's API for managing issues, teams, and projects programmatically through the Model Context Protocol.

Featured
JavaScript
mermaid-mcp-server

mermaid-mcp-server

A Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images.

Featured
JavaScript
Jira-Context-MCP

Jira-Context-MCP

MCP server to provide Jira Tickets information to AI coding agents like Cursor

Featured
TypeScript
Linear MCP Server

Linear MCP Server

A Model Context Protocol server that integrates with Linear's issue tracking system, allowing LLMs to create, update, search, and comment on Linear issues through natural language interactions.

Featured
JavaScript
Sequential Thinking MCP Server

Sequential Thinking MCP Server

This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.

Featured
Python