vite-plugin-swagger-mcp 0.0.2 → 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/cjs/index.js CHANGED
@@ -125,7 +125,7 @@ var SwaggerMcpServer = class {
125
125
  const op = (_a = doc.paths[path]) == null ? void 0 : _a[method.toLowerCase()];
126
126
  if (!op)
127
127
  throw new Error("接口不存在");
128
- const originalRef = (_d = (_c = (_b = doc.paths[path][method].responses) == null ? void 0 : _b["200"]) == null ? void 0 : _c.schema) == null ? void 0 : _d.originalRef;
128
+ const originalRef = (_d = (_c = (_b = doc.paths[path][method.toLowerCase()].responses) == null ? void 0 : _b["200"]) == null ? void 0 : _c.schema) == null ? void 0 : _d.originalRef;
129
129
  const resolvedDefinition = this.resolveRef(doc, originalRef);
130
130
  return {
131
131
  path,
@@ -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
@@ -204,7 +204,7 @@ export var SwaggerMcpServer = /*#__PURE__*/function () {
204
204
  }
205
205
  throw new Error("接口不存在");
206
206
  case 6:
207
- originalRef = (_doc$paths$path$metho3 = doc.paths[path][method].responses) === null || _doc$paths$path$metho3 === void 0 || (_doc$paths$path$metho3 = _doc$paths$path$metho3["200"]) === null || _doc$paths$path$metho3 === void 0 || (_doc$paths$path$metho3 = _doc$paths$path$metho3.schema) === null || _doc$paths$path$metho3 === void 0 ? void 0 : _doc$paths$path$metho3.originalRef;
207
+ originalRef = (_doc$paths$path$metho3 = doc.paths[path][method.toLowerCase()].responses) === null || _doc$paths$path$metho3 === void 0 || (_doc$paths$path$metho3 = _doc$paths$path$metho3["200"]) === null || _doc$paths$path$metho3 === void 0 || (_doc$paths$path$metho3 = _doc$paths$path$metho3.schema) === null || _doc$paths$path$metho3 === void 0 ? void 0 : _doc$paths$path$metho3.originalRef;
208
208
  resolvedDefinition = this.resolveRef(doc, originalRef);
209
209
  return _context4.abrupt("return", _objectSpread(_objectSpread({
210
210
  path: path,
@@ -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 _callee10() {
239
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
240
240
  var transport, swaggerServer, mcpServer;
241
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
242
- while (1) switch (_context10.prev = _context10.next) {
241
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
242
+ while (1) switch (_context9.prev = _context9.next) {
243
243
  case 0:
244
- _context10.prev = 0;
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("updateSwaggerDoc", "获取最新接口文档", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
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 _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref4) {
295
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref3) {
321
296
  var module, res;
322
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
323
- while (1) switch (_context7.prev = _context7.next) {
297
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
298
+ while (1) switch (_context6.prev = _context6.next) {
324
299
  case 0:
325
- module = _ref4.module;
300
+ module = _ref3.module;
326
301
  if (module) {
327
- _context7.next = 3;
302
+ _context6.next = 3;
328
303
  break;
329
304
  }
330
- return _context7.abrupt("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
- _context7.next = 5;
314
+ _context6.next = 5;
340
315
  return swaggerServer.getModuleApis(module);
341
316
  case 5:
342
- res = _context7.sent;
343
- return _context7.abrupt("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 _context7.stop();
326
+ return _context6.stop();
352
327
  }
353
- }, _callee7);
328
+ }, _callee6);
354
329
  }));
355
330
  return function (_x4) {
356
- return _ref5.apply(this, arguments);
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 _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(args) {
368
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
369
- while (1) switch (_context8.prev = _context8.next) {
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
- _context8.t0 = JSON;
372
- _context8.next = 3;
346
+ _context7.t0 = JSON;
347
+ _context7.next = 3;
373
348
  return swaggerServer.getApiTypes(args.path, args.method);
374
349
  case 3:
375
- _context8.t1 = _context8.sent;
376
- _context8.t2 = _context8.t0.stringify.call(_context8.t0, _context8.t1);
377
- _context8.t3 = {
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: _context8.t2
354
+ text: _context7.t2
380
355
  };
381
- _context8.t4 = [_context8.t3];
382
- return _context8.abrupt("return", {
383
- content: _context8.t4
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 _context8.stop();
362
+ return _context7.stop();
388
363
  }
389
- }, _callee8);
364
+ }, _callee7);
390
365
  }));
391
366
  return function (_x5) {
392
- return _ref6.apply(this, arguments);
367
+ return _ref5.apply(this, arguments);
393
368
  };
394
369
  }());
395
370
 
396
371
  // Connect to the MCP mcpServer
397
- _context10.next = 11;
372
+ _context9.next = 10;
398
373
  return mcpServer.connect(transport);
399
- case 11:
374
+ case 10:
400
375
  console.log("MCP server connected");
401
376
  server.middlewares.use( /*#__PURE__*/function () {
402
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(req, res, next) {
377
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(req, res, next) {
403
378
  var _req$url;
404
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
405
- while (1) switch (_context9.prev = _context9.next) {
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
- _context9.next = 6;
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
- _context9.next = 4;
391
+ _context8.next = 4;
417
392
  return transport.handleRequest(req, res);
418
393
  case 4:
419
- _context9.next = 7;
394
+ _context8.next = 7;
420
395
  break;
421
396
  case 6:
422
397
  next();
423
398
  case 7:
424
399
  case "end":
425
- return _context9.stop();
400
+ return _context8.stop();
426
401
  }
427
- }, _callee9);
402
+ }, _callee8);
428
403
  }));
429
404
  return function (_x6, _x7, _x8) {
430
- return _ref7.apply(this, arguments);
405
+ return _ref6.apply(this, arguments);
431
406
  };
432
407
  }());
433
- _context10.next = 18;
408
+ _context9.next = 17;
434
409
  break;
435
- case 15:
436
- _context10.prev = 15;
437
- _context10.t0 = _context10["catch"](0);
438
- console.log("MCP server error", _context10.t0);
439
- case 18:
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 _context10.stop();
416
+ return _context9.stop();
442
417
  }
443
- }, _callee10, null, [[0, 15]]);
418
+ }, _callee9, null, [[0, 14]]);
444
419
  }))();
445
420
  }
446
421
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-swagger-mcp",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "vite plugin for swagger mcp",
5
5
  "homepage": "https://github.com/mmctjj/vite-plugin-swagger-mcp",
6
6
  "repository": {