html-parser-mcp 1.0.0

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 +64 -0
  2. package/package.json +21 -0
package/index.js ADDED
@@ -0,0 +1,64 @@
1
+ // index.js
2
+ const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
3
+ const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
4
+ const cheerio = require('cheerio');
5
+ const fs = require('fs');
6
+
7
+ const server = new Server({
8
+ name: 'html-parser',
9
+ version: '1.0.0'
10
+ }, {
11
+ capabilities: {
12
+ tools: {}
13
+ }
14
+ });
15
+
16
+ // 注册工具
17
+ server.setRequestHandler('tools/list', async () => ({
18
+ tools: [{
19
+ name: 'parse_html',
20
+ description: '解析 HTML 文件,提取表单字段',
21
+ inputSchema: {
22
+ type: 'object',
23
+ properties: {
24
+ filePath: { type: 'string', description: 'HTML 文件路径' }
25
+ },
26
+ required: ['filePath']
27
+ }
28
+ }]
29
+ }));
30
+
31
+ // 处理工具调用
32
+ server.setRequestHandler('tools/call', async (request) => {
33
+ if (request.params.name === 'parse_html') {
34
+ const { filePath } = request.params.arguments;
35
+ const html = fs.readFileSync(filePath, 'utf-8');
36
+ const $ = cheerio.load(html);
37
+
38
+ const groups = [];
39
+ $('.section-header, h2, h3, [class*="header"]').each((i, header) => {
40
+ const group = { name: $(header).text().trim(), fields: [] };
41
+ let next = $(header).next();
42
+ while (next.length && !next.is('.section-header, h2, h3, [class*="header"]')) {
43
+ if (next.is('.form-row, .form-group, [class*="form"]')) {
44
+ const label = next.find('label').first().text().replace('*', '').trim();
45
+ const input = next.find('input, select').first();
46
+ const name = input.attr('name');
47
+ if (name) {
48
+ group.fields.push({ name, label });
49
+ }
50
+ }
51
+ next = next.next();
52
+ }
53
+ if (group.fields.length) groups.push(group);
54
+ });
55
+
56
+ return {
57
+ content: [{ type: 'text', text: JSON.stringify(groups, null, 2) }]
58
+ };
59
+ }
60
+ });
61
+
62
+ // 启动
63
+ const transport = new StdioServerTransport();
64
+ server.connect(transport);
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "html-parser-mcp",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "type": "commonjs",
13
+ "dependencies": {
14
+ "@modelcontextprotocol/sdk": "^1.27.1",
15
+ "cheerio": "^1.2.0"
16
+ },
17
+ "publishConfig": {
18
+ "registry": "https://registry.npmjs.org",
19
+ "access": "public"
20
+ }
21
+ }