getNodeInfo
Retrieve Node.js version details from the current operating environment to verify installations and check compatibility.
Instructions
获取当前设备安装的 Node.js 版本信息
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "getNodeInfo"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:271-279 (registration)Tool registration in the listTools handler: defines name, description, and empty input schema for getNodeInfo.
{ name: "getNodeInfo", description: "获取当前设备安装的 Node.js 版本信息", inputSchema: { type: "object", properties: {}, required: [] } } - src/index.ts:741-780 (handler)Handler implementation for getNodeInfo tool: fetches Node.js version, npm version, global packages, and other runtime info using process object and execSync, returns JSON stringified response.
case "getNodeInfo": { let nodeInfo = {}; try { // 获取 Node.js 版本信息 const nodeVersion = process.version; const nodeFullVersion = execSync('node --version').toString().trim(); const npmVersion = execSync('npm --version').toString().trim(); // 获取已安装的全局 npm 包 const globalPackages = execSync('npm list -g --depth=0 --json').toString(); const parsedGlobalPackages = JSON.parse(globalPackages); // 获取 Node.js 环境信息 nodeInfo = { version: nodeVersion, fullVersion: nodeFullVersion, npmVersion: npmVersion, platform: process.platform, arch: process.arch, globalPackages: parsedGlobalPackages.dependencies || {}, execPath: process.execPath, features: process.features, modules: process.versions }; } catch (error) { // 出错时返回基本信息 nodeInfo = { version: process.version, platform: process.platform, arch: process.arch }; } return { content: [{ type: "text", text: JSON.stringify(nodeInfo, null, 2) }] }; }