campus-security-mcp 1.0.0 → 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/LICENSE +21 -0
- package/README.md +123 -0
- package/bin/index.js +57 -0
- package/package.json +12 -5
- package/test.js +81 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 campus-security-mcp
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# 校园安防助手 MCP 服务器
|
|
2
|
+
|
|
3
|
+
这是一个基于 Node.js 的 MCP (Model Context Protocol) 服务器,提供校园区域查询、街道查询和警告数量查询功能。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- **区域查询**: 返回所有学校区域名称(东、西、南、北)
|
|
8
|
+
- **街道查询**: 返回所有学校街道名称(共 9 条街道)
|
|
9
|
+
- **警告数量查询**: 根据时间、区域和街道参数查询警告数量
|
|
10
|
+
- **Mock 数据**: 使用模拟数据进行测试,预留真实 API 接口
|
|
11
|
+
|
|
12
|
+
## 安装
|
|
13
|
+
|
|
14
|
+
### 全局安装
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g campus-security-mcp
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### 直接使用 npx 运行
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx campus-security-mcp
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 使用
|
|
27
|
+
|
|
28
|
+
### 启动服务器
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# 全局安装后
|
|
32
|
+
campus-security-mcp
|
|
33
|
+
|
|
34
|
+
# 或使用 npx
|
|
35
|
+
npx campus-security-mcp
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 调用工具
|
|
39
|
+
|
|
40
|
+
服务器启动后,会监听标准输入,处理 JSON 格式的请求,并返回响应。
|
|
41
|
+
|
|
42
|
+
#### 示例请求
|
|
43
|
+
|
|
44
|
+
1. **区域查询**
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"id": "1",
|
|
49
|
+
"toolcall": {
|
|
50
|
+
"thought": "查询学校区域",
|
|
51
|
+
"name": "campus_security_get_areas",
|
|
52
|
+
"params": {}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
2. **街道查询**
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"id": "2",
|
|
62
|
+
"toolcall": {
|
|
63
|
+
"thought": "查询学校街道",
|
|
64
|
+
"name": "campus_security_get_streets",
|
|
65
|
+
"params": {}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
3. **警告数量查询**
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"id": "3",
|
|
75
|
+
"toolcall": {
|
|
76
|
+
"thought": "查询警告数量",
|
|
77
|
+
"name": "campus_security_get_warnings",
|
|
78
|
+
"params": {
|
|
79
|
+
"startDate": "2026-04-06",
|
|
80
|
+
"endDate": "2026-04-12",
|
|
81
|
+
"area": "东",
|
|
82
|
+
"street": "春晖路"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 项目结构
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
campus-security-mcp/
|
|
92
|
+
├── bin/
|
|
93
|
+
│ └── index.js # 可执行文件
|
|
94
|
+
├── dist/ # 构建输出目录
|
|
95
|
+
├── src/
|
|
96
|
+
│ ├── client/ # 远程 API 客户端
|
|
97
|
+
│ ├── data/ # 数据相关文件
|
|
98
|
+
│ ├── mcp/ # MCP 服务器模拟实现
|
|
99
|
+
│ ├── tools/ # MCP 工具实现
|
|
100
|
+
│ ├── utils/ # 工具函数
|
|
101
|
+
│ ├── index.ts # 服务器入口
|
|
102
|
+
│ └── server.ts # 服务器配置
|
|
103
|
+
├── package.json # 包配置信息
|
|
104
|
+
├── README.md # 使用说明
|
|
105
|
+
└── tsconfig.json # TypeScript 配置
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## 技术栈
|
|
109
|
+
|
|
110
|
+
- TypeScript 5.3.3
|
|
111
|
+
- Node.js 18+
|
|
112
|
+
- Zod 3.22.4
|
|
113
|
+
|
|
114
|
+
## 未来规划
|
|
115
|
+
|
|
116
|
+
- 接入真实 API 接口
|
|
117
|
+
- 添加更多校园安防相关工具
|
|
118
|
+
- 优化数据生成策略
|
|
119
|
+
- 提高服务性能和可靠性
|
|
120
|
+
|
|
121
|
+
## 许可证
|
|
122
|
+
|
|
123
|
+
MIT 许可证
|
package/bin/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// bin/index.js
|
|
3
|
+
const readline = require('readline');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
// 导入构建后的 MCP 服务器
|
|
7
|
+
const server = require('../dist/server').default;
|
|
8
|
+
// 导入所有工具
|
|
9
|
+
require('../dist/tools');
|
|
10
|
+
|
|
11
|
+
// 创建 readline 接口,监听标准输入
|
|
12
|
+
const rl = readline.createInterface({
|
|
13
|
+
input: process.stdin,
|
|
14
|
+
output: process.stdout,
|
|
15
|
+
terminal: false
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// 启动服务器
|
|
19
|
+
server.start().then(() => {
|
|
20
|
+
console.log('校园安防助手 MCP 服务器启动成功');
|
|
21
|
+
console.log('服务器已准备就绪,等待请求...');
|
|
22
|
+
}).catch((error) => {
|
|
23
|
+
console.error('启动 MCP 服务器失败:', error);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// 处理输入请求
|
|
28
|
+
rl.on('line', (line) => {
|
|
29
|
+
try {
|
|
30
|
+
const request = JSON.parse(line);
|
|
31
|
+
console.log('收到请求:', request);
|
|
32
|
+
|
|
33
|
+
// 简单响应示例 - 实际实现需要根据 MCP 协议处理
|
|
34
|
+
const response = {
|
|
35
|
+
result: 'Hello, MCP from npm!',
|
|
36
|
+
requestId: request.id
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
console.log(JSON.stringify(response));
|
|
40
|
+
} catch (error) {
|
|
41
|
+
const response = {
|
|
42
|
+
error: error.toString()
|
|
43
|
+
};
|
|
44
|
+
console.log(JSON.stringify(response));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// 处理错误
|
|
49
|
+
rl.on('error', (error) => {
|
|
50
|
+
console.error('读取输入时出错:', error);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// 处理关闭
|
|
54
|
+
rl.on('close', () => {
|
|
55
|
+
console.log('MCP 服务器已关闭');
|
|
56
|
+
process.exit(0);
|
|
57
|
+
});
|
package/package.json
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "campus-security-mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "校园安防助手 MCP 服务器",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "bin/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"campus-security-mcp": "bin/index.js"
|
|
8
|
+
},
|
|
6
9
|
"scripts": {
|
|
7
10
|
"build": "tsc",
|
|
8
|
-
"start": "node
|
|
9
|
-
"dev": "ts-node src/index.ts"
|
|
11
|
+
"start": "node bin/index.js",
|
|
12
|
+
"dev": "ts-node src/index.ts",
|
|
13
|
+
"test": "node test.js",
|
|
14
|
+
"lint": "eslint src",
|
|
15
|
+
"prepare": "npm run build",
|
|
16
|
+
"publish": "npm run build && npm publish"
|
|
10
17
|
},
|
|
11
18
|
"dependencies": {
|
|
12
19
|
"zod": "^3.22.4"
|
|
@@ -21,6 +28,6 @@
|
|
|
21
28
|
"security",
|
|
22
29
|
"typescript"
|
|
23
30
|
],
|
|
24
|
-
"author": "
|
|
31
|
+
"author": "Yasenagat",
|
|
25
32
|
"license": "MIT"
|
|
26
33
|
}
|
package/test.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// test.js - 测试 MCP 服务器工具
|
|
2
|
+
const { spawn } = require('child_process');
|
|
3
|
+
|
|
4
|
+
// 启动 MCP 服务器
|
|
5
|
+
const server = spawn('node', ['bin/index.js']);
|
|
6
|
+
|
|
7
|
+
// 存储服务器输出
|
|
8
|
+
let serverOutput = '';
|
|
9
|
+
|
|
10
|
+
// 监听服务器输出
|
|
11
|
+
server.stdout.on('data', (data) => {
|
|
12
|
+
const output = data.toString();
|
|
13
|
+
serverOutput += output;
|
|
14
|
+
console.log('服务器输出:', output);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// 监听服务器错误
|
|
18
|
+
server.stderr.on('data', (data) => {
|
|
19
|
+
console.error('服务器错误:', data.toString());
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// 监听服务器退出
|
|
23
|
+
server.on('close', (code) => {
|
|
24
|
+
console.log(`服务器退出,代码: ${code}`);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// 等待服务器启动
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
console.log('\n=== 开始测试 ===\n');
|
|
30
|
+
|
|
31
|
+
// 测试 1: 区域查询
|
|
32
|
+
console.log('测试 1: 区域查询');
|
|
33
|
+
const areaRequest = {
|
|
34
|
+
id: '1',
|
|
35
|
+
toolcall: {
|
|
36
|
+
thought: '查询学校区域',
|
|
37
|
+
name: 'campus_security_get_areas',
|
|
38
|
+
params: {}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
server.stdin.write(JSON.stringify(areaRequest) + '\n');
|
|
42
|
+
|
|
43
|
+
// 测试 2: 街道查询
|
|
44
|
+
setTimeout(() => {
|
|
45
|
+
console.log('\n测试 2: 街道查询');
|
|
46
|
+
const streetRequest = {
|
|
47
|
+
id: '2',
|
|
48
|
+
toolcall: {
|
|
49
|
+
thought: '查询学校街道',
|
|
50
|
+
name: 'campus_security_get_streets',
|
|
51
|
+
params: {}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
server.stdin.write(JSON.stringify(streetRequest) + '\n');
|
|
55
|
+
|
|
56
|
+
// 测试 3: 警告数量查询
|
|
57
|
+
setTimeout(() => {
|
|
58
|
+
console.log('\n测试 3: 警告数量查询');
|
|
59
|
+
const warningRequest = {
|
|
60
|
+
id: '3',
|
|
61
|
+
toolcall: {
|
|
62
|
+
thought: '查询警告数量',
|
|
63
|
+
name: 'campus_security_get_warnings',
|
|
64
|
+
params: {
|
|
65
|
+
startDate: '2026-04-06',
|
|
66
|
+
endDate: '2026-04-12',
|
|
67
|
+
area: '东',
|
|
68
|
+
street: '春晖路'
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
server.stdin.write(JSON.stringify(warningRequest) + '\n');
|
|
73
|
+
|
|
74
|
+
// 等待测试完成后关闭服务器
|
|
75
|
+
setTimeout(() => {
|
|
76
|
+
console.log('\n=== 测试完成 ===\n');
|
|
77
|
+
server.stdin.end();
|
|
78
|
+
}, 2000);
|
|
79
|
+
}, 2000);
|
|
80
|
+
}, 2000);
|
|
81
|
+
}, 3000);
|