html-parser-mcp 1.0.1 → 1.0.3

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.
Files changed (2) hide show
  1. package/index.js +6 -11
  2. package/package.json +5 -2
package/index.js CHANGED
@@ -1,20 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
  const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
3
3
  const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
4
+ const { ListToolsRequestSchema, CallToolRequestSchema } = require('@modelcontextprotocol/sdk/types.js');
4
5
  const cheerio = require('cheerio');
5
6
  const fs = require('fs');
6
7
 
7
8
  const server = new Server({
8
9
  name: 'html-parser-mcp',
9
- version: '1.0.0'
10
+ version: '1.0.2'
10
11
  }, {
11
12
  capabilities: {
12
13
  tools: {}
13
14
  }
14
15
  });
15
16
 
16
- // 注册工具
17
- server.setRequestHandler('tools/list', async () => ({
17
+ // 修正:使用 ListToolsRequestSchema 而不是 { method: 'tools/list' }
18
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
18
19
  tools: [{
19
20
  name: 'parse_html',
20
21
  description: '解析 HTML 文件,提取表单字段',
@@ -28,15 +29,14 @@ server.setRequestHandler('tools/list', async () => ({
28
29
  }]
29
30
  }));
30
31
 
31
- // 处理工具调用
32
- server.setRequestHandler('tools/call', async (request) => {
32
+ // 修正:使用 CallToolRequestSchema 而不是 { method: 'tools/call' }
33
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
33
34
  const { name, arguments: args } = request.params;
34
35
 
35
36
  if (name === 'parse_html') {
36
37
  try {
37
38
  const { filePath } = args;
38
39
 
39
- // 检查文件是否存在
40
40
  if (!fs.existsSync(filePath)) {
41
41
  throw new Error(`文件不存在: ${filePath}`);
42
42
  }
@@ -62,7 +62,6 @@ server.setRequestHandler('tools/call', async (request) => {
62
62
  if (group.fields.length) groups.push(group);
63
63
  });
64
64
 
65
- // 如果没有找到任何分组,返回默认分组
66
65
  if (groups.length === 0) {
67
66
  groups.push({ name: '表单字段', fields: [] });
68
67
  }
@@ -72,7 +71,6 @@ server.setRequestHandler('tools/call', async (request) => {
72
71
  };
73
72
 
74
73
  } catch (error) {
75
- // 返回错误信息
76
74
  return {
77
75
  content: [{ type: 'text', text: JSON.stringify({ error: error.message }, null, 2) }],
78
76
  isError: true
@@ -80,11 +78,9 @@ server.setRequestHandler('tools/call', async (request) => {
80
78
  }
81
79
  }
82
80
 
83
- // 未知工具
84
81
  throw new Error(`未知工具: ${name}`);
85
82
  });
86
83
 
87
- // 错误处理:捕获未处理的异常
88
84
  process.on('uncaughtException', (error) => {
89
85
  console.error('Uncaught Exception:', error);
90
86
  process.exit(1);
@@ -95,7 +91,6 @@ process.on('unhandledRejection', (error) => {
95
91
  process.exit(1);
96
92
  });
97
93
 
98
- // 启动
99
94
  const transport = new StdioServerTransport();
100
95
  server.connect(transport).catch(error => {
101
96
  console.error('Failed to connect:', error);
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "html-parser-mcp",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
+ "bin": {
7
+ "html-parser-mcp": "index.js"
8
+ },
6
9
  "scripts": {
7
10
  "test": "echo \"Error: no test specified\" && exit 1"
8
11
  },
@@ -11,7 +14,7 @@
11
14
  "license": "ISC",
12
15
  "type": "commonjs",
13
16
  "dependencies": {
14
- "@modelcontextprotocol/sdk": "^1.27.1",
17
+ "@modelcontextprotocol/sdk": "^1.0.0",
15
18
  "cheerio": "^1.2.0"
16
19
  },
17
20
  "publishConfig": {