NNNNzs
可用工具 (2 个)
该服务在 MCP 协议中暴露的工具,AI 可按需调用
get_server_status 1 个参数
获取服务器的CPU、内存和运行状态
该工具无需必填参数,直接调用即可
get_remote_server_status 1 个参数 需填 1 项
获取远程服务器的CPU、内存和运行状态
必填参数:host
服务介绍
Server Status Monitoring Tool
This is a server status monitoring tool based on FastMCP, capable of fetching CPU, memory, and uptime information from local or remote servers.
Features
- Supports fetching the status of local servers
- Supports fetching the status of remote servers via SSH
- Automatically reads SSH configuration files (~/.ssh/config)
- Supports custom SSH connection parameters
- Can be run as an independent server
- Can be integrated into other applications as an npm package
Installation
Install via npm
bash
Global installation
npm install -g server-status-mcp-server
Or install as a project dependency
npm install server-status-mcp-server
Install from Source Code
bash
Clone the repository
git clone https://github.com/nnnnzs/server-status-mcp-server.git
cd server-status-mcp-server
Install dependencies
npm install
Build the project
npm run build
Usage
Running as a Standalone Service
1. Start the Server
bash
If the package is installed globally
server-status-mcp-server
Or start from source code
npm start
2. Run the Test Client
bash
node client.js
3. Direct Command Line Invocation
Communicate with the server using stdio:
bash
echo {"jsonrpc":"2.0","method":"get_server_status","params":{},"id":1} | node dist/index.js
Fetch the status of a remote server:
bash
echo {"jsonrpc":"2.0","method":"getRemoteServerStatus","params":{"host":"172.18.1.103"},"id":1} | node dist/index.js
Integrating as an npm Package
1. Create and Configure MCP Service
javascript
import { createServerStatusMCP } from 'server-status-mcp-server';
// Create an instance of the MCP service
const server = createServerStatusMCP({
// Optional: Custom SSH configuration file path
sshConfigPath: '/path/to/ssh/config'
});
// Start the service
server.start({
transportType: "stdio" // or other transport types
});
2. Invoke Using MCP Client
javascript
import { MCPClient } from 'fastmcp';
import { createServerStatusMCP } from 'server-status-mcp-server';
import { spawn } from 'child_process';
async function main() {
// Method 1: Create a child process to run the service
const serverProcess = spawn('node', ['path/to/your/server.js']);
// Create an MCP client
const client = new MCPClient();
// Connect to the service process
await client.connect({
process: serverProcess,
transportType: "stdio"
});
// Method 2: Use in the same process (not recommended for production)
const server = createServerStatusMCP();
server.start({ transportType: "memory" });
const memoryClient = new MCPClient();
await memoryClient.connect({ transportType: "memory", server });
// Call the tool
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));
// Disconnect
await client.disconnect();
serverProcess.kill();
}
main().catch(console.error);
SSH Configuration Example
Add the following configuration to your ~/.ssh/config file:
Host my-server
HostName 192.168.1.100
User username
Port 22
IdentityFile ~/.ssh/id_rsa
Then you can use the configured hostname to fetch the status:
bash
echo {"jsonrpc":"2.0","method":"getRemoteServerStatus","params":{"host":"my-server"},"id":1} | node dist/index.js
Data Format Returned
Local Server Status
json
{
"cpuCount": 8,
"cpuRel": 0.12,
"memory": 8589934592,
"memoryUsage": "45.32",
"uptime": 123456,
"type": "local"
}
Remote Server Status
json
{
"cpu": "Processor information...",
"memory": "Memory usage...",
"uptime": "System uptime...",
"type": "remote"
}
API Documentation
Main Exports
typescript
// Create an MCP service instance
createServerStatusMCP(config?: { sshConfigPath?: string }): FastMCP
// Get local CPU usage
getLocalCpuUsage(): number
// Parse SSH configuration file
parseSSHConfig(configContent: string, targetHost: string): Promise<Record<string, string> | null>
// Server status interface
interface RemoteServerStatus {
cpuRel: string;
memoryRel: string;
alarmInfo: string;
itemStatus: string;
cpu: string;
memory: string;
memoryUsage: string;
uptime: string;
type: 'remote' | 'local';
}## Error Handling
If the connection fails or there is an error executing a command, the following will be returned:
json
{
"error": "Error message"
}
Publishing to NPM
If you wish to publish this package to NPM yourself, follow these steps:
- Update the version number in
package.json - Run
npm run buildto ensure the build is successful - Run
npm loginto log into your NPM account - Run
npm publishto publish the package - Optional: Use
npm publish --access publicto publish as a public package
License
ISC