@mcpcn/mcp-computer-env 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
File without changes
package/dist/index.js CHANGED
@@ -29,7 +29,9 @@ function getSystemInfo() {
29
29
  if (match)
30
30
  distro = match[1];
31
31
  }
32
- catch { }
32
+ catch (error) {
33
+ // 忽略文件读取错误,distro 保持为空字符串
34
+ }
33
35
  }
34
36
  return {
35
37
  platform,
@@ -89,18 +91,23 @@ function getCommonDirs() {
89
91
  dirs.pictures = path.join(home, '图片');
90
92
  dirs.videos = path.join(home, '视频');
91
93
  // 兼容英文目录
92
- if (!fs.existsSync(dirs.desktop))
93
- dirs.desktop = path.join(home, 'Desktop');
94
- if (!fs.existsSync(dirs.documents))
95
- dirs.documents = path.join(home, 'Documents');
96
- if (!fs.existsSync(dirs.downloads))
97
- dirs.downloads = path.join(home, 'Downloads');
98
- if (!fs.existsSync(dirs.music))
99
- dirs.music = path.join(home, 'Music');
100
- if (!fs.existsSync(dirs.pictures))
101
- dirs.pictures = path.join(home, 'Pictures');
102
- if (!fs.existsSync(dirs.videos))
103
- dirs.videos = path.join(home, 'Videos');
94
+ try {
95
+ if (!fs.existsSync(dirs.desktop))
96
+ dirs.desktop = path.join(home, 'Desktop');
97
+ if (!fs.existsSync(dirs.documents))
98
+ dirs.documents = path.join(home, 'Documents');
99
+ if (!fs.existsSync(dirs.downloads))
100
+ dirs.downloads = path.join(home, 'Downloads');
101
+ if (!fs.existsSync(dirs.music))
102
+ dirs.music = path.join(home, 'Music');
103
+ if (!fs.existsSync(dirs.pictures))
104
+ dirs.pictures = path.join(home, 'Pictures');
105
+ if (!fs.existsSync(dirs.videos))
106
+ dirs.videos = path.join(home, 'Videos');
107
+ }
108
+ catch (error) {
109
+ // 忽略文件系统检查错误,使用默认值
110
+ }
104
111
  dirs.appData = process.env.XDG_CONFIG_HOME || path.join(home, '.config');
105
112
  }
106
113
  return dirs;
@@ -117,46 +124,52 @@ function getNetworkInfo() {
117
124
  }
118
125
  // 获取磁盘分区信息(跨平台)
119
126
  async function getDiskInfo() {
120
- const platform = os.platform();
121
- if (platform === 'win32') {
122
- // Windows: 使用wmic
123
- const { stdout } = await execAsync('wmic logicaldisk get Caption,FileSystem,Size,FreeSpace');
124
- const lines = stdout.trim().split(/\r?\n/).filter(Boolean);
125
- const header = lines.shift();
126
- return lines.map(line => {
127
- const parts = line.trim().split(/\s+/);
128
- const [Caption, FileSystem, Size, FreeSpace] = parts;
129
- const total = parseInt(Size, 10) || 0;
130
- const free = parseInt(FreeSpace, 10) || 0;
131
- return {
132
- filesystem: Caption,
133
- mount: Caption + '\\',
134
- type: FileSystem,
135
- total,
136
- used: total - free,
137
- available: free
138
- };
139
- });
127
+ try {
128
+ const platform = os.platform();
129
+ if (platform === 'win32') {
130
+ // Windows: 使用wmic
131
+ const { stdout } = await execAsync('wmic logicaldisk get Caption,FileSystem,Size,FreeSpace');
132
+ const lines = stdout.trim().split(/\r?\n/).filter(Boolean);
133
+ const header = lines.shift();
134
+ return lines.map(line => {
135
+ const parts = line.trim().split(/\s+/);
136
+ const [Caption, FileSystem, Size, FreeSpace] = parts;
137
+ const total = parseInt(Size, 10) || 0;
138
+ const free = parseInt(FreeSpace, 10) || 0;
139
+ return {
140
+ filesystem: Caption,
141
+ mount: Caption + '\\',
142
+ type: FileSystem,
143
+ total,
144
+ used: total - free,
145
+ available: free
146
+ };
147
+ });
148
+ }
149
+ else {
150
+ // macOS/Linux: 使用df -kP
151
+ const { stdout } = await execAsync('df -kP');
152
+ const lines = stdout.trim().split(/\n/).filter(Boolean);
153
+ lines.shift(); // 去掉表头
154
+ return lines.map(line => {
155
+ const parts = line.replace(/\s+/g, ' ').split(' ');
156
+ // Filesystem 1024-blocks Used Available Capacity Mounted on
157
+ const [filesystem, blocks, used, available, capacity, ...mountArr] = parts;
158
+ const mount = mountArr.join(' ');
159
+ return {
160
+ filesystem,
161
+ mount,
162
+ type: '', // 跨平台简化,详细类型可用mount命令补充
163
+ total: parseInt(blocks, 10) * 1024,
164
+ used: parseInt(used, 10) * 1024,
165
+ available: parseInt(available, 10) * 1024
166
+ };
167
+ });
168
+ }
140
169
  }
141
- else {
142
- // macOS/Linux: 使用df -kP
143
- const { stdout } = await execAsync('df -kP');
144
- const lines = stdout.trim().split(/\n/).filter(Boolean);
145
- lines.shift(); // 去掉表头
146
- return lines.map(line => {
147
- const parts = line.replace(/\s+/g, ' ').split(' ');
148
- // Filesystem 1024-blocks Used Available Capacity Mounted on
149
- const [filesystem, blocks, used, available, capacity, ...mountArr] = parts;
150
- const mount = mountArr.join(' ');
151
- return {
152
- filesystem,
153
- mount,
154
- type: '', // 跨平台简化,详细类型可用mount命令补充
155
- total: parseInt(blocks, 10) * 1024,
156
- used: parseInt(used, 10) * 1024,
157
- available: parseInt(available, 10) * 1024
158
- };
159
- });
170
+ catch (error) {
171
+ const errorMessage = error instanceof Error ? error.message : String(error);
172
+ throw new McpError(ErrorCode.InternalError, `Failed to get disk info: ${errorMessage}`);
160
173
  }
161
174
  }
162
175
  class ComputerEnvServer {
@@ -207,31 +220,57 @@ class ComputerEnvServer {
207
220
  ],
208
221
  }));
209
222
  this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
223
+ const { name, arguments: args } = request.params;
210
224
  try {
211
- switch (request.params.name) {
225
+ switch (name) {
212
226
  case 'get_system_info':
213
- return { content: [{ type: 'text', text: JSON.stringify(getSystemInfo()) }] };
227
+ return {
228
+ content: [{ type: 'text', text: JSON.stringify(getSystemInfo()) }],
229
+ isError: false
230
+ };
214
231
  case 'get_common_dirs':
215
- return { content: [{ type: 'text', text: JSON.stringify(getCommonDirs()) }] };
232
+ return {
233
+ content: [{ type: 'text', text: JSON.stringify(getCommonDirs()) }],
234
+ isError: false
235
+ };
216
236
  case 'get_memory_info':
217
- return { content: [{ type: 'text', text: JSON.stringify(getMemoryInfo()) }] };
237
+ return {
238
+ content: [{ type: 'text', text: JSON.stringify(getMemoryInfo()) }],
239
+ isError: false
240
+ };
218
241
  case 'get_network_info':
219
- return { content: [{ type: 'text', text: JSON.stringify(getNetworkInfo()) }] };
242
+ return {
243
+ content: [{ type: 'text', text: JSON.stringify(getNetworkInfo()) }],
244
+ isError: false
245
+ };
220
246
  case 'get_disk_info':
221
- return { content: [{ type: 'text', text: JSON.stringify(await getDiskInfo()) }] };
247
+ return {
248
+ content: [{ type: 'text', text: JSON.stringify(await getDiskInfo()) }],
249
+ isError: false
250
+ };
222
251
  default:
223
- throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}`);
252
+ throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
224
253
  }
225
254
  }
226
255
  catch (error) {
227
- throw error;
256
+ if (error instanceof McpError) {
257
+ throw error;
258
+ }
259
+ const errorMessage = error instanceof Error ? error.message : String(error);
260
+ throw new McpError(ErrorCode.InternalError, `Error executing tool ${name}: ${errorMessage}`);
228
261
  }
229
262
  });
230
263
  }
231
264
  async run() {
232
- const transport = new StdioServerTransport();
233
- await this.server.connect(transport);
234
- console.error('Computer Env MCP server running on stdio');
265
+ try {
266
+ const transport = new StdioServerTransport();
267
+ await this.server.connect(transport);
268
+ console.error('Computer Env MCP server running on stdio');
269
+ }
270
+ catch (error) {
271
+ console.error('Failed to start server:', error);
272
+ process.exit(1);
273
+ }
235
274
  }
236
275
  }
237
276
  const server = new ComputerEnvServer();
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@mcpcn/mcp-computer-env",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "获取用户电脑环境信息的MCP服务器",
5
- "packageManager": "pnpm@8.12.1",
5
+ "packageManager": "npm@10.9.0",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "bin": {
@@ -26,7 +26,7 @@
26
26
  "start": "node dist/index.js",
27
27
  "dev": "tsc -w",
28
28
  "clean": "rm -rf build",
29
- "prepare": "pnpm clean && pnpm build"
29
+ "prepare": "npm run clean && npm run build"
30
30
  },
31
31
  "type": "module",
32
32
  "license": "MIT",