mcp-server-wom-call 0.0.1 → 0.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.
- package/dist/index.js +51 -40
- package/dist/types/index.d.ts +1 -1
- package/package.json +26 -9
package/dist/index.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* 用于自动化创建运维工单的 MCP 服务器
|
|
4
4
|
*
|
|
5
5
|
* @author Your Name
|
|
6
|
-
* @version 0.1.
|
|
6
|
+
* @version 0.1.2
|
|
7
7
|
*/
|
|
8
8
|
import 'dotenv/config';
|
|
9
9
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
10
10
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
11
11
|
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
12
|
-
import ESBProtocolBuilder from './utils/ESBProtocolBuilder';
|
|
12
|
+
import ESBProtocolBuilder from './utils/ESBProtocolBuilder.js';
|
|
13
13
|
// ============ 常量定义 ============
|
|
14
14
|
/**
|
|
15
15
|
* 工单创建工具定义
|
|
@@ -111,17 +111,17 @@ let ESB_URL = process.env.ESB_URL || '';
|
|
|
111
111
|
// ============ 服务器配置 ============
|
|
112
112
|
const SERVER_CONFIG = {
|
|
113
113
|
name: 'mcp-server-wom-call',
|
|
114
|
-
version: '0.1.
|
|
114
|
+
version: '0.1.2',
|
|
115
115
|
description: 'MCP Server for Work Order Management System Integration'
|
|
116
116
|
};
|
|
117
117
|
// ============ 工具函数 ============
|
|
118
118
|
/**
|
|
119
|
-
*
|
|
120
|
-
* @throws {Error}
|
|
119
|
+
* 验证配置是否完整
|
|
120
|
+
* @throws {Error} 如果必需的配置未设置
|
|
121
121
|
*/
|
|
122
|
-
function
|
|
123
|
-
if (!
|
|
124
|
-
throw new Error('ESB_URL is not
|
|
122
|
+
function validateConfiguration() {
|
|
123
|
+
if (!ESB_URL) {
|
|
124
|
+
throw new Error('ESB_URL is not configured. Please set it in .env file, system environment, or MCP client configuration.');
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
@@ -161,7 +161,6 @@ function buildESBPayload(input) {
|
|
|
161
161
|
* @throws {Error} 如果 API 调用失败
|
|
162
162
|
*/
|
|
163
163
|
async function createWorkOrder(input) {
|
|
164
|
-
// 使用配置的 ESB_URL
|
|
165
164
|
const url = ESB_URL;
|
|
166
165
|
if (!url) {
|
|
167
166
|
throw new Error('ESB_URL is not configured');
|
|
@@ -189,15 +188,6 @@ async function createWorkOrder(input) {
|
|
|
189
188
|
throw new Error(`Failed to create work order: ${String(error)}`);
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
|
-
/**
|
|
193
|
-
* 验证必需的环境变量或配置
|
|
194
|
-
* @throws {Error} 如果必需的配置未设置
|
|
195
|
-
*/
|
|
196
|
-
function validateConfiguration() {
|
|
197
|
-
if (!ESB_URL) {
|
|
198
|
-
throw new Error('ESB_URL is not configured. Please set it in .env file, system environment, or MCP client configuration.');
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
191
|
/**
|
|
202
192
|
* 验证输入参数
|
|
203
193
|
* @param args - 待验证的参数
|
|
@@ -244,10 +234,50 @@ function validateInput(args) {
|
|
|
244
234
|
if (input.email !== undefined && typeof input.email !== 'string') {
|
|
245
235
|
throw new Error('Invalid input: email must be a string');
|
|
246
236
|
}
|
|
237
|
+
// 验证邮箱格式(如果提供)
|
|
238
|
+
if (input.email && input.email.length > 0) {
|
|
239
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
240
|
+
if (!emailRegex.test(input.email)) {
|
|
241
|
+
throw new Error('Invalid input: email format is invalid');
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
// 验证附件格式(如果提供)
|
|
245
|
+
if (input.attachments !== undefined) {
|
|
246
|
+
if (!Array.isArray(input.attachments)) {
|
|
247
|
+
throw new Error('Invalid input: attachments must be an array');
|
|
248
|
+
}
|
|
249
|
+
for (const [index, attachment] of input.attachments.entries()) {
|
|
250
|
+
if (!attachment || typeof attachment !== 'object') {
|
|
251
|
+
throw new Error(`Invalid input: attachment at index ${index} must be an object`);
|
|
252
|
+
}
|
|
253
|
+
if (!attachment.filename ||
|
|
254
|
+
typeof attachment.filename !== 'string' ||
|
|
255
|
+
attachment.filename.trim().length === 0) {
|
|
256
|
+
throw new Error(`Invalid input: attachment at index ${index} must have a valid filename`);
|
|
257
|
+
}
|
|
258
|
+
if (!attachment.url ||
|
|
259
|
+
typeof attachment.url !== 'string' ||
|
|
260
|
+
attachment.url.trim().length === 0) {
|
|
261
|
+
throw new Error(`Invalid input: attachment at index ${index} must have a valid url`);
|
|
262
|
+
}
|
|
263
|
+
// 验证 URL 格式
|
|
264
|
+
try {
|
|
265
|
+
new URL(attachment.url);
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
throw new Error(`Invalid input: attachment at index ${index} has an invalid URL format`);
|
|
269
|
+
}
|
|
270
|
+
if (attachment.size !== undefined &&
|
|
271
|
+
(typeof attachment.size !== 'number' || attachment.size < 0)) {
|
|
272
|
+
throw new Error(`Invalid input: attachment at index ${index} size must be a positive number`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
247
276
|
}
|
|
248
277
|
// ============ MCP 服务器实现 ============
|
|
249
278
|
/**
|
|
250
279
|
* 创建 MCP 服务器实例
|
|
280
|
+
* 注意:Server 构造函数会自动处理 initialize 请求
|
|
251
281
|
*/
|
|
252
282
|
const server = new Server({
|
|
253
283
|
name: SERVER_CONFIG.name,
|
|
@@ -257,26 +287,6 @@ const server = new Server({
|
|
|
257
287
|
tools: {}
|
|
258
288
|
}
|
|
259
289
|
});
|
|
260
|
-
/**
|
|
261
|
-
* 处理初始化请求,接收配置参数
|
|
262
|
-
*/
|
|
263
|
-
server.setRequestHandler({ method: 'initialize' }, async (request) => {
|
|
264
|
-
// 从初始化参数中获取 esburl
|
|
265
|
-
if (request.params?.initializationOptions?.esburl) {
|
|
266
|
-
ESB_URL = request.params.initializationOptions.esburl;
|
|
267
|
-
console.error(`📝 ESB URL configured: ${ESB_URL}`);
|
|
268
|
-
}
|
|
269
|
-
return {
|
|
270
|
-
protocolVersion: '2024-11-05',
|
|
271
|
-
capabilities: {
|
|
272
|
-
tools: {}
|
|
273
|
-
},
|
|
274
|
-
serverInfo: {
|
|
275
|
-
name: SERVER_CONFIG.name,
|
|
276
|
-
version: SERVER_CONFIG.version
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
});
|
|
280
290
|
/**
|
|
281
291
|
* 注册工具列表处理器
|
|
282
292
|
*/
|
|
@@ -316,6 +326,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
316
326
|
}
|
|
317
327
|
catch (error) {
|
|
318
328
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
329
|
+
console.error('❌ Error handling tool call:', errorMessage);
|
|
319
330
|
return {
|
|
320
331
|
content: [
|
|
321
332
|
{
|
|
@@ -335,7 +346,7 @@ async function runServer() {
|
|
|
335
346
|
try {
|
|
336
347
|
// 创建传输层
|
|
337
348
|
const transport = new StdioServerTransport();
|
|
338
|
-
//
|
|
349
|
+
// 连接服务器(SDK 会自动处理 initialize 握手)
|
|
339
350
|
await server.connect(transport);
|
|
340
351
|
// 输出启动日志
|
|
341
352
|
console.error(`🚀 ${SERVER_CONFIG.name} v${SERVER_CONFIG.version} is running`);
|
|
@@ -344,7 +355,7 @@ async function runServer() {
|
|
|
344
355
|
console.error(`🔗 ESB URL: ${ESB_URL}`);
|
|
345
356
|
}
|
|
346
357
|
else {
|
|
347
|
-
console.error(`⚠️ ESB URL not configured
|
|
358
|
+
console.error(`⚠️ ESB URL not configured. Please set ESB_URL environment variable.`);
|
|
348
359
|
}
|
|
349
360
|
}
|
|
350
361
|
catch (error) {
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-server-wom-call",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "MCP
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "MCP Server for Work Order Management System Integration",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Myth",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"bin": {
|
|
9
|
-
"mcp-server-
|
|
9
|
+
"mcp-server-wom-call": "dist/index.js"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"dist"
|
|
@@ -14,19 +14,36 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "tsc && tsc-alias && shx chmod +x dist/*.js",
|
|
16
16
|
"prepare": "npm run build",
|
|
17
|
-
"watch": "tsc
|
|
18
|
-
"dev": "tsx
|
|
17
|
+
"watch": "tsc --watch",
|
|
18
|
+
"dev": "tsx src/index.ts",
|
|
19
|
+
"test:local": "node dist/index.js"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"@modelcontextprotocol/sdk": "1.0.1",
|
|
22
|
-
"dotenv": "^17.2.3"
|
|
23
|
-
"tsc-alias": "^1.8.16",
|
|
24
|
-
"tsconfig-paths": "^4.2.0",
|
|
25
|
-
"tsx": "^4.21.0"
|
|
23
|
+
"dotenv": "^17.2.3"
|
|
26
24
|
},
|
|
27
25
|
"devDependencies": {
|
|
28
26
|
"@types/node": "^22",
|
|
29
27
|
"shx": "^0.3.4",
|
|
28
|
+
"tsc-alias": "^1.8.16",
|
|
29
|
+
"tsconfig-paths": "^4.2.0",
|
|
30
|
+
"tsx": "^4.21.0",
|
|
30
31
|
"typescript": "^5.6.2"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"mcp",
|
|
35
|
+
"mcp-server",
|
|
36
|
+
"work-order",
|
|
37
|
+
"wom",
|
|
38
|
+
"ticket",
|
|
39
|
+
"esb",
|
|
40
|
+
"model-context-protocol"
|
|
41
|
+
],
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/yourusername/mcp-server-wom-call.git"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18.0.0"
|
|
31
48
|
}
|
|
32
49
|
}
|