Server Status MCP Server

by NNNNzs
Verified

Integrations

  • Allows installation directly from GitHub repository, providing source code access for customization and development.

  • Monitors local server status, providing real-time metrics on CPU usage, memory consumption, and system uptime for local machine monitoring.

  • Enables installation and distribution through npm, supporting both global installation and integration as a project dependency.

服务器状态监控工具

这是一个基于 FastMCP 的服务器状态监控工具,可以获取本地或远程服务器的 CPU、内存和运行时间信息。

功能特点

  • 支持获取本地服务器状态
  • 支持通过 SSH 获取远程服务器状态
  • 自动读取 SSH 配置文件(~/.ssh/config)
  • 支持自定义 SSH 连接参数
  • 可作为独立服务器运行
  • 可作为npm包集成到其他应用中

安装

通过npm安装

# 全局安装 npm install -g server-status-mcp-server # 或作为项目依赖安装 npm install server-status-mcp-server

从源码安装

# 克隆仓库 git clone https://github.com/nnnnzs/server-status-mcp-server.git cd server-status-mcp-server # 安装依赖 npm install # 构建项目 npm run build

使用方法

作为独立服务运行

1. 启动服务器

# 如果全局安装了包 server-status-mcp-server # 或者从源码启动 npm start

2. 运行测试客户端

node client.js

3. 命令行直接调用

使用 stdio 方式与服务器通信:

echo '{"jsonrpc":"2.0","method":"get_server_status","params":{},"id":1}' | node dist/index.js

获取远程服务器状态:

echo '{"jsonrpc":"2.0","method":"getRemoteServerStatus","params":{"host":"172.18.1.103"},"id":1}' | node dist/index.js

作为npm包集成

1. 创建和配置MCP服务

import { createServerStatusMCP } from 'server-status-mcp-server'; // 创建MCP服务实例 const server = createServerStatusMCP({ // 可选:自定义SSH配置文件路径 sshConfigPath: '/path/to/ssh/config' }); // 启动服务 server.start({ transportType: "stdio" // 或其他传输类型 });

2. 使用MCP客户端调用

import { MCPClient } from 'fastmcp'; import { createServerStatusMCP } from 'server-status-mcp-server'; import { spawn } from 'child_process'; async function main() { // 方法1:创建子进程运行服务 const serverProcess = spawn('node', ['path/to/your/server.js']); // 创建MCP客户端 const client = new MCPClient(); // 连接到服务进程 await client.connect({ process: serverProcess, transportType: "stdio" }); // 方法2:在同一进程中使用(不推荐用于生产环境) const server = createServerStatusMCP(); server.start({ transportType: "memory" }); const memoryClient = new MCPClient(); await memoryClient.connect({ transportType: "memory", server }); // 调用工具 const localStatus = await client.invoke('getLocalServerStatus', {}); console.log('本地服务器状态:', JSON.stringify(localStatus, null, 2)); const remoteStatus = await client.invoke('getRemoteServerStatus', { host: 'your-ssh-host' }); console.log('远程服务器状态:', JSON.stringify(remoteStatus, null, 2)); // 断开连接 await client.disconnect(); serverProcess.kill(); } main().catch(console.error);

SSH 配置示例

~/.ssh/config 文件中添加以下配置:

Host my-server HostName 192.168.1.100 User username Port 22 IdentityFile ~/.ssh/id_rsa

然后可以使用配置的主机名来获取状态:

echo '{"jsonrpc":"2.0","method":"getRemoteServerStatus","params":{"host":"my-server"},"id":1}' | node dist/index.js

返回数据格式

本地服务器状态

{ "cpuCount": 8, "cpuRel": 0.12, "memory": 8589934592, "memoryUsage": "45.32", "uptime": 123456, "type": "local" }

远程服务器状态

{ "cpu": "处理器信息...", "memory": "内存使用情况...", "uptime": "系统运行时间...", "type": "remote" }

API文档

主要导出

// 创建MCP服务实例 createServerStatusMCP(config?: { sshConfigPath?: string }): FastMCP // 获取本地CPU使用率 getLocalCpuUsage(): number // 解析SSH配置文件 parseSSHConfig(configContent: string, targetHost: string): Promise<Record<string, string> | null> // 服务器状态接口 interface RemoteServerStatus { cpuRel: string; memoryRel: string; alarmInfo: string; itemStatus: string; cpu: string; memory: string; memoryUsage: string; uptime: string; type: 'remote' | 'local'; }

错误处理

如果连接失败或执行命令出错,将返回:

{ "error": "错误信息" }

发布到NPM

如果你想自己发布这个包到NPM,可以按照以下步骤操作:

  1. 更新package.json中的版本号
  2. 运行npm run build确保构建成功
  3. 运行npm login登录NPM账号
  4. 运行npm publish发布包
  5. 可选:使用npm publish --access public发布公共包

许可证

ISC

You must be authenticated.

A
security – no known vulnerabilities
F
license - not found
A
quality - confirmed to work

A FastMCP-based tool for monitoring server statistics that retrieves CPU, memory, and uptime information from both local and remote servers via SSH.

  1. 功能特点
    1. 安装
      1. 通过npm安装
      2. 从源码安装
    2. 使用方法
      1. 作为独立服务运行
      2. 作为npm包集成
    3. SSH 配置示例
      1. 返回数据格式
        1. 本地服务器状态
        2. 远程服务器状态
      2. API文档
        1. 主要导出
      3. 错误处理
        1. 发布到NPM
          1. 许可证
            ID: xnf5brdivk