vite-plugin-swagger-mcp 0.0.12 → 0.0.13

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
@@ -216,47 +216,15 @@ function vitePluginSwaggerMcp({
216
216
  `http://localhost:${(_b = (_a = server.config) == null ? void 0 : _a.server) == null ? void 0 : _b.port}/_mcp/sse/swagger`
217
217
  );
218
218
  server.middlewares.use("/_mcp/sse/swagger", async (req, res) => {
219
- var _a2;
220
- if (req.method === "POST") {
221
- let body = "";
222
- for await (const chunk of req)
223
- body += chunk;
224
- const json = JSON.parse(body);
225
- try {
226
- const result = await transport.handleRequest(req, res, json);
227
- res.writeHead(200, {
228
- "Content-Type": "application/json"
229
- });
230
- res.end(JSON.stringify(result));
231
- return;
232
- } catch (err) {
233
- res.writeHead(500);
234
- res.end(
235
- JSON.stringify({
236
- jsonrpc: "2.0",
237
- id: (json == null ? void 0 : json.id) ?? null,
238
- error: { message: err == null ? void 0 : err.message }
239
- })
240
- );
219
+ try {
220
+ await transport.handleRequest(req, res);
221
+ } catch (err) {
222
+ console.error("[MCP]", err);
223
+ if (!res.headersSent) {
224
+ res.statusCode = 500;
225
+ res.end();
241
226
  }
242
227
  }
243
- if (req.method === "GET") {
244
- if (!((_a2 = req.headers.accept) == null ? void 0 : _a2.includes("text/event-stream"))) {
245
- res.writeHead(405);
246
- return res.end();
247
- }
248
- res.writeHead(200, {
249
- "Content-Type": "text/event-stream",
250
- "Cache-Control": "no-cache",
251
- Connection: "keep-alive"
252
- });
253
- transport.onmessage = (message) => {
254
- res.write(message);
255
- };
256
- return;
257
- }
258
- res.statusCode = 405;
259
- res.end();
260
228
  });
261
229
  } catch (error) {
262
230
  console.log("MCP server error", error);
package/dist/esm/index.js CHANGED
@@ -10,8 +10,6 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
10
10
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
12
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
- function _asyncIterator(r) { var n, t, o, e = 2; for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) { if (t && null != (n = r[t])) return n.call(r); if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r)); t = "@@asyncIterator", o = "@@iterator"; } throw new TypeError("Object is not async iterable"); }
14
- function AsyncFromSyncIterator(r) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var n = r.done; return Promise.resolve(r.value).then(function (r) { return { value: r, done: n }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(r) { this.s = r, this.n = r.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, return: function _return(r) { var n = this.s.return; return void 0 === n ? Promise.resolve({ value: r, done: !0 }) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments)); }, throw: function _throw(r) { var n = this.s.return; return void 0 === n ? Promise.reject(r) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(r); }
15
13
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
16
14
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
17
15
  import { randomUUID } from "node:crypto";
@@ -376,114 +374,28 @@ export default function vitePluginSwaggerMcp(_ref) {
376
374
  console.log("MCP server connected:", "http://localhost:".concat((_server$config = server.config) === null || _server$config === void 0 || (_server$config = _server$config.server) === null || _server$config === void 0 ? void 0 : _server$config.port, "/_mcp/sse/swagger"));
377
375
  server.middlewares.use('/_mcp/sse/swagger', /*#__PURE__*/function () {
378
376
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(req, res) {
379
- var body, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, chunk, json, result, _json$id, _req$headers$accept;
380
377
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
381
378
  while (1) switch (_context8.prev = _context8.next) {
382
379
  case 0:
383
- if (!(req.method === 'POST')) {
384
- _context8.next = 44;
385
- break;
386
- }
387
- body = '';
388
- _iteratorAbruptCompletion = false;
389
- _didIteratorError = false;
390
- _context8.prev = 4;
391
- _iterator = _asyncIterator(req);
392
- case 6:
393
- _context8.next = 8;
394
- return _iterator.next();
395
- case 8:
396
- if (!(_iteratorAbruptCompletion = !(_step = _context8.sent).done)) {
397
- _context8.next = 14;
398
- break;
399
- }
400
- chunk = _step.value;
401
- body += chunk;
402
- case 11:
403
- _iteratorAbruptCompletion = false;
404
- _context8.next = 6;
405
- break;
406
- case 14:
407
- _context8.next = 20;
380
+ _context8.prev = 0;
381
+ _context8.next = 3;
382
+ return transport.handleRequest(req, res);
383
+ case 3:
384
+ _context8.next = 9;
408
385
  break;
409
- case 16:
410
- _context8.prev = 16;
411
- _context8.t0 = _context8["catch"](4);
412
- _didIteratorError = true;
413
- _iteratorError = _context8.t0;
414
- case 20:
415
- _context8.prev = 20;
416
- _context8.prev = 21;
417
- if (!(_iteratorAbruptCompletion && _iterator.return != null)) {
418
- _context8.next = 25;
419
- break;
420
- }
421
- _context8.next = 25;
422
- return _iterator.return();
423
- case 25:
424
- _context8.prev = 25;
425
- if (!_didIteratorError) {
426
- _context8.next = 28;
427
- break;
428
- }
429
- throw _iteratorError;
430
- case 28:
431
- return _context8.finish(25);
432
- case 29:
433
- return _context8.finish(20);
434
- case 30:
435
- json = JSON.parse(body);
436
- _context8.prev = 31;
437
- _context8.next = 34;
438
- return transport.handleRequest(req, res, json);
439
- case 34:
440
- result = _context8.sent;
441
- // 规范:POST 一定返回 response
442
- res.writeHead(200, {
443
- 'Content-Type': 'application/json'
444
- });
445
- res.end(JSON.stringify(result));
446
- return _context8.abrupt("return");
447
- case 40:
448
- _context8.prev = 40;
449
- _context8.t1 = _context8["catch"](31);
450
- res.writeHead(500);
451
- res.end(JSON.stringify({
452
- jsonrpc: '2.0',
453
- id: (_json$id = json === null || json === void 0 ? void 0 : json.id) !== null && _json$id !== void 0 ? _json$id : null,
454
- error: {
455
- message: _context8.t1 === null || _context8.t1 === void 0 ? void 0 : _context8.t1.message
456
- }
457
- }));
458
- case 44:
459
- if (!(req.method === 'GET')) {
460
- _context8.next = 51;
461
- break;
462
- }
463
- if ((_req$headers$accept = req.headers.accept) !== null && _req$headers$accept !== void 0 && _req$headers$accept.includes('text/event-stream')) {
464
- _context8.next = 48;
465
- break;
386
+ case 5:
387
+ _context8.prev = 5;
388
+ _context8.t0 = _context8["catch"](0);
389
+ console.error('[MCP]', _context8.t0);
390
+ if (!res.headersSent) {
391
+ res.statusCode = 500;
392
+ res.end();
466
393
  }
467
- res.writeHead(405);
468
- return _context8.abrupt("return", res.end());
469
- case 48:
470
- res.writeHead(200, {
471
- 'Content-Type': 'text/event-stream',
472
- 'Cache-Control': 'no-cache',
473
- Connection: 'keep-alive'
474
- });
475
- transport.onmessage = function (message) {
476
- res.write(message);
477
- };
478
- return _context8.abrupt("return");
479
- case 51:
480
- res.statusCode = 405;
481
- res.end();
482
- case 53:
394
+ case 9:
483
395
  case "end":
484
396
  return _context8.stop();
485
397
  }
486
- }, _callee8, null, [[4, 16, 20, 30], [21,, 25, 29], [31, 40]]);
398
+ }, _callee8, null, [[0, 5]]);
487
399
  }));
488
400
  return function (_x6, _x7) {
489
401
  return _ref6.apply(this, arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-swagger-mcp",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "vite plugin for swagger mcp",
5
5
  "homepage": "https://github.com/mmdctjj/vite-plugin-swagger-mcp",
6
6
  "repository": {