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