vite-plugin-swagger-mcp 0.0.2 → 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/cjs/index.js +0 -11
- package/dist/esm/index.js +52 -77
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -161,17 +161,6 @@ function vitePluginSwaggerMcp({
|
|
|
161
161
|
name: "swagger-mcp-server",
|
|
162
162
|
version: "0.1.0"
|
|
163
163
|
});
|
|
164
|
-
mcpServer.tool("updateSwaggerDoc", "获取最新接口文档", async () => {
|
|
165
|
-
const res = await swaggerServer.getModules();
|
|
166
|
-
return {
|
|
167
|
-
content: [
|
|
168
|
-
{
|
|
169
|
-
type: "text",
|
|
170
|
-
text: JSON.stringify(res)
|
|
171
|
-
}
|
|
172
|
-
]
|
|
173
|
-
};
|
|
174
|
-
});
|
|
175
164
|
mcpServer.tool("getModules", "获取模块列表", async () => {
|
|
176
165
|
const res = await swaggerServer.getModules();
|
|
177
166
|
return {
|
package/dist/esm/index.js
CHANGED
|
@@ -236,12 +236,12 @@ export default function vitePluginSwaggerMcp(_ref) {
|
|
|
236
236
|
name: "vite-plugin-swagger-mcp",
|
|
237
237
|
enforce: "pre",
|
|
238
238
|
configureServer: function configureServer(server) {
|
|
239
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
239
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
240
240
|
var transport, swaggerServer, mcpServer;
|
|
241
|
-
return _regeneratorRuntime().wrap(function
|
|
242
|
-
while (1) switch (
|
|
241
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
242
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
243
243
|
case 0:
|
|
244
|
-
|
|
244
|
+
_context9.prev = 0;
|
|
245
245
|
transport = new StreamableHTTPServerTransport({
|
|
246
246
|
sessionIdGenerator: function sessionIdGenerator() {
|
|
247
247
|
return randomUUID();
|
|
@@ -262,9 +262,9 @@ export default function vitePluginSwaggerMcp(_ref) {
|
|
|
262
262
|
version: "0.1.0"
|
|
263
263
|
}); // 注册工具
|
|
264
264
|
/***
|
|
265
|
-
*
|
|
265
|
+
* 获取模块列表
|
|
266
266
|
*/
|
|
267
|
-
mcpServer.tool("
|
|
267
|
+
mcpServer.tool("getModules", "获取模块列表", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
268
268
|
var res;
|
|
269
269
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
270
270
|
while (1) switch (_context5.prev = _context5.next) {
|
|
@@ -286,48 +286,23 @@ export default function vitePluginSwaggerMcp(_ref) {
|
|
|
286
286
|
}, _callee5);
|
|
287
287
|
})));
|
|
288
288
|
|
|
289
|
-
/***
|
|
290
|
-
* 获取模块列表
|
|
291
|
-
*/
|
|
292
|
-
mcpServer.tool("getModules", "获取模块列表", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
293
|
-
var res;
|
|
294
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
295
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
296
|
-
case 0:
|
|
297
|
-
_context6.next = 2;
|
|
298
|
-
return swaggerServer.getModules();
|
|
299
|
-
case 2:
|
|
300
|
-
res = _context6.sent;
|
|
301
|
-
return _context6.abrupt("return", {
|
|
302
|
-
content: [{
|
|
303
|
-
type: "text",
|
|
304
|
-
text: JSON.stringify(res)
|
|
305
|
-
}]
|
|
306
|
-
});
|
|
307
|
-
case 4:
|
|
308
|
-
case "end":
|
|
309
|
-
return _context6.stop();
|
|
310
|
-
}
|
|
311
|
-
}, _callee6);
|
|
312
|
-
})));
|
|
313
|
-
|
|
314
289
|
/***
|
|
315
290
|
* 获取特定模块下的所有接口及返回值类型
|
|
316
291
|
*/
|
|
317
292
|
mcpServer.tool("getModuleApis", "获取特定模块下的所有接口及返回值类型", {
|
|
318
293
|
module: z.string().describe("模块名称")
|
|
319
294
|
}, /*#__PURE__*/function () {
|
|
320
|
-
var
|
|
295
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref3) {
|
|
321
296
|
var module, res;
|
|
322
|
-
return _regeneratorRuntime().wrap(function
|
|
323
|
-
while (1) switch (
|
|
297
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
298
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
324
299
|
case 0:
|
|
325
|
-
module =
|
|
300
|
+
module = _ref3.module;
|
|
326
301
|
if (module) {
|
|
327
|
-
|
|
302
|
+
_context6.next = 3;
|
|
328
303
|
break;
|
|
329
304
|
}
|
|
330
|
-
return
|
|
305
|
+
return _context6.abrupt("return", {
|
|
331
306
|
content: [{
|
|
332
307
|
type: "text",
|
|
333
308
|
text: JSON.stringify({
|
|
@@ -336,11 +311,11 @@ export default function vitePluginSwaggerMcp(_ref) {
|
|
|
336
311
|
}]
|
|
337
312
|
});
|
|
338
313
|
case 3:
|
|
339
|
-
|
|
314
|
+
_context6.next = 5;
|
|
340
315
|
return swaggerServer.getModuleApis(module);
|
|
341
316
|
case 5:
|
|
342
|
-
res =
|
|
343
|
-
return
|
|
317
|
+
res = _context6.sent;
|
|
318
|
+
return _context6.abrupt("return", {
|
|
344
319
|
content: [{
|
|
345
320
|
type: "text",
|
|
346
321
|
text: JSON.stringify(res)
|
|
@@ -348,12 +323,12 @@ export default function vitePluginSwaggerMcp(_ref) {
|
|
|
348
323
|
});
|
|
349
324
|
case 7:
|
|
350
325
|
case "end":
|
|
351
|
-
return
|
|
326
|
+
return _context6.stop();
|
|
352
327
|
}
|
|
353
|
-
},
|
|
328
|
+
}, _callee6);
|
|
354
329
|
}));
|
|
355
330
|
return function (_x4) {
|
|
356
|
-
return
|
|
331
|
+
return _ref4.apply(this, arguments);
|
|
357
332
|
};
|
|
358
333
|
}());
|
|
359
334
|
|
|
@@ -364,48 +339,48 @@ export default function vitePluginSwaggerMcp(_ref) {
|
|
|
364
339
|
path: z.string(),
|
|
365
340
|
method: z.string()
|
|
366
341
|
}, /*#__PURE__*/function () {
|
|
367
|
-
var
|
|
368
|
-
return _regeneratorRuntime().wrap(function
|
|
369
|
-
while (1) switch (
|
|
342
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(args) {
|
|
343
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
344
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
370
345
|
case 0:
|
|
371
|
-
|
|
372
|
-
|
|
346
|
+
_context7.t0 = JSON;
|
|
347
|
+
_context7.next = 3;
|
|
373
348
|
return swaggerServer.getApiTypes(args.path, args.method);
|
|
374
349
|
case 3:
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
350
|
+
_context7.t1 = _context7.sent;
|
|
351
|
+
_context7.t2 = _context7.t0.stringify.call(_context7.t0, _context7.t1);
|
|
352
|
+
_context7.t3 = {
|
|
378
353
|
type: "text",
|
|
379
|
-
text:
|
|
354
|
+
text: _context7.t2
|
|
380
355
|
};
|
|
381
|
-
|
|
382
|
-
return
|
|
383
|
-
content:
|
|
356
|
+
_context7.t4 = [_context7.t3];
|
|
357
|
+
return _context7.abrupt("return", {
|
|
358
|
+
content: _context7.t4
|
|
384
359
|
});
|
|
385
360
|
case 8:
|
|
386
361
|
case "end":
|
|
387
|
-
return
|
|
362
|
+
return _context7.stop();
|
|
388
363
|
}
|
|
389
|
-
},
|
|
364
|
+
}, _callee7);
|
|
390
365
|
}));
|
|
391
366
|
return function (_x5) {
|
|
392
|
-
return
|
|
367
|
+
return _ref5.apply(this, arguments);
|
|
393
368
|
};
|
|
394
369
|
}());
|
|
395
370
|
|
|
396
371
|
// Connect to the MCP mcpServer
|
|
397
|
-
|
|
372
|
+
_context9.next = 10;
|
|
398
373
|
return mcpServer.connect(transport);
|
|
399
|
-
case
|
|
374
|
+
case 10:
|
|
400
375
|
console.log("MCP server connected");
|
|
401
376
|
server.middlewares.use( /*#__PURE__*/function () {
|
|
402
|
-
var
|
|
377
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(req, res, next) {
|
|
403
378
|
var _req$url;
|
|
404
|
-
return _regeneratorRuntime().wrap(function
|
|
405
|
-
while (1) switch (
|
|
379
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
380
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
406
381
|
case 0:
|
|
407
382
|
if (!(req.method === "POST" && (_req$url = req.url) !== null && _req$url !== void 0 && _req$url.startsWith("/_mcp/sse/swagger"))) {
|
|
408
|
-
|
|
383
|
+
_context8.next = 6;
|
|
409
384
|
break;
|
|
410
385
|
}
|
|
411
386
|
if (!req.headers["mcp-session-id"] && transport.sessionId) {
|
|
@@ -413,34 +388,34 @@ export default function vitePluginSwaggerMcp(_ref) {
|
|
|
413
388
|
req.headers["mcp-session-id"] = transport.sessionId;
|
|
414
389
|
}
|
|
415
390
|
// Handle the request
|
|
416
|
-
|
|
391
|
+
_context8.next = 4;
|
|
417
392
|
return transport.handleRequest(req, res);
|
|
418
393
|
case 4:
|
|
419
|
-
|
|
394
|
+
_context8.next = 7;
|
|
420
395
|
break;
|
|
421
396
|
case 6:
|
|
422
397
|
next();
|
|
423
398
|
case 7:
|
|
424
399
|
case "end":
|
|
425
|
-
return
|
|
400
|
+
return _context8.stop();
|
|
426
401
|
}
|
|
427
|
-
},
|
|
402
|
+
}, _callee8);
|
|
428
403
|
}));
|
|
429
404
|
return function (_x6, _x7, _x8) {
|
|
430
|
-
return
|
|
405
|
+
return _ref6.apply(this, arguments);
|
|
431
406
|
};
|
|
432
407
|
}());
|
|
433
|
-
|
|
408
|
+
_context9.next = 17;
|
|
434
409
|
break;
|
|
435
|
-
case
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
console.log("MCP server error",
|
|
439
|
-
case
|
|
410
|
+
case 14:
|
|
411
|
+
_context9.prev = 14;
|
|
412
|
+
_context9.t0 = _context9["catch"](0);
|
|
413
|
+
console.log("MCP server error", _context9.t0);
|
|
414
|
+
case 17:
|
|
440
415
|
case "end":
|
|
441
|
-
return
|
|
416
|
+
return _context9.stop();
|
|
442
417
|
}
|
|
443
|
-
},
|
|
418
|
+
}, _callee9, null, [[0, 14]]);
|
|
444
419
|
}))();
|
|
445
420
|
}
|
|
446
421
|
};
|