getNodeInfo
Retrieve Node.js version information from the current operating environment to diagnose compatibility or perform version-specific tasks.
Instructions
获取当前设备安装的 Node.js 版本信息
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"required": [],
"type": "object"
}
Implementation Reference
- src/index.ts:741-780 (handler)Handler function for the 'getNodeInfo' tool. Collects Node.js runtime information including version, npm version, global packages, platform details, and falls back to basic info on error.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) }] }; }
- src/index.ts:271-279 (registration)Registration of the 'getNodeInfo' tool in the list returned by handleRequest, including name, description, and input schema (empty object).{ name: "getNodeInfo", description: "获取当前设备安装的 Node.js 版本信息", inputSchema: { type: "object", properties: {}, required: [] } }
- src/index.ts:274-278 (schema)Input schema for getNodeInfo tool: an empty object with no properties or requirements.inputSchema: { type: "object", properties: {}, required: [] }