@alcyone-labs/arg-parser 1.1.0 → 2.0.0

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.
Files changed (105) hide show
  1. package/README.md +460 -1179
  2. package/dist/assets/.dxtignore.template +38 -0
  3. package/dist/assets/logo_1_small.jpg +0 -0
  4. package/dist/assets/tsdown.dxt.config.ts +37 -0
  5. package/dist/index.cjs +23702 -2315
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.min.mjs +16360 -1725
  8. package/dist/index.min.mjs.map +1 -1
  9. package/dist/index.mjs +23694 -2315
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/src/config/ConfigurationManager.d.ts +74 -0
  12. package/dist/src/config/ConfigurationManager.d.ts.map +1 -0
  13. package/dist/src/config/plugins/ConfigPlugin.d.ts +60 -0
  14. package/dist/src/config/plugins/ConfigPlugin.d.ts.map +1 -0
  15. package/dist/src/config/plugins/ConfigPluginRegistry.d.ts +72 -0
  16. package/dist/src/config/plugins/ConfigPluginRegistry.d.ts.map +1 -0
  17. package/dist/src/config/plugins/TomlConfigPlugin.d.ts +30 -0
  18. package/dist/src/config/plugins/TomlConfigPlugin.d.ts.map +1 -0
  19. package/dist/src/config/plugins/YamlConfigPlugin.d.ts +29 -0
  20. package/dist/src/config/plugins/YamlConfigPlugin.d.ts.map +1 -0
  21. package/dist/src/config/plugins/index.d.ts +5 -0
  22. package/dist/src/config/plugins/index.d.ts.map +1 -0
  23. package/dist/src/core/ArgParser.d.ts +332 -0
  24. package/dist/src/core/ArgParser.d.ts.map +1 -0
  25. package/dist/src/{ArgParserBase.d.ts → core/ArgParserBase.d.ts} +84 -3
  26. package/dist/src/core/ArgParserBase.d.ts.map +1 -0
  27. package/dist/src/core/FlagManager.d.ts.map +1 -0
  28. package/dist/src/{types.d.ts → core/types.d.ts} +40 -0
  29. package/dist/src/core/types.d.ts.map +1 -0
  30. package/dist/src/dxt/DxtGenerator.d.ts +115 -0
  31. package/dist/src/dxt/DxtGenerator.d.ts.map +1 -0
  32. package/dist/src/index.d.ts +10 -6
  33. package/dist/src/index.d.ts.map +1 -1
  34. package/dist/src/mcp/ArgParserMcp.d.ts +21 -0
  35. package/dist/src/mcp/ArgParserMcp.d.ts.map +1 -0
  36. package/dist/src/mcp/mcp-integration.d.ts +83 -0
  37. package/dist/src/mcp/mcp-integration.d.ts.map +1 -0
  38. package/dist/src/mcp/mcp-notifications.d.ts +138 -0
  39. package/dist/src/mcp/mcp-notifications.d.ts.map +1 -0
  40. package/dist/src/mcp/mcp-prompts.d.ts +132 -0
  41. package/dist/src/mcp/mcp-prompts.d.ts.map +1 -0
  42. package/dist/src/mcp/mcp-resources.d.ts +133 -0
  43. package/dist/src/mcp/mcp-resources.d.ts.map +1 -0
  44. package/dist/src/testing/fuzzy-test-cli.d.ts +5 -0
  45. package/dist/src/testing/fuzzy-test-cli.d.ts.map +1 -0
  46. package/dist/src/{fuzzy-tester.d.ts → testing/fuzzy-tester.d.ts} +1 -1
  47. package/dist/src/testing/fuzzy-tester.d.ts.map +1 -0
  48. package/package.json +51 -17
  49. package/dist/examples/fuzzy-demo.d.ts +0 -8
  50. package/dist/examples/fuzzy-demo.d.ts.map +0 -1
  51. package/dist/examples/fuzzy-test-example.d.ts +0 -8
  52. package/dist/examples/fuzzy-test-example.d.ts.map +0 -1
  53. package/dist/examples/fzf-search-cli.d.ts +0 -8
  54. package/dist/examples/fzf-search-cli.d.ts.map +0 -1
  55. package/dist/examples/getting-started.d.ts +0 -27
  56. package/dist/examples/getting-started.d.ts.map +0 -1
  57. package/dist/examples/mcp-preset-transports.d.ts +0 -19
  58. package/dist/examples/mcp-preset-transports.d.ts.map +0 -1
  59. package/dist/examples/simple-cli.d.ts +0 -26
  60. package/dist/examples/simple-cli.d.ts.map +0 -1
  61. package/dist/examples/v1.1.0-showcase.d.ts +0 -16
  62. package/dist/examples/v1.1.0-showcase.d.ts.map +0 -1
  63. package/dist/examples/with-env-example.d.ts +0 -3
  64. package/dist/examples/with-env-example.d.ts.map +0 -1
  65. package/dist/index-6G9StDO_.js +0 -6445
  66. package/dist/index-6G9StDO_.js.map +0 -1
  67. package/dist/index-CqU7Fj3C.cjs +0 -6444
  68. package/dist/index-CqU7Fj3C.cjs.map +0 -1
  69. package/dist/index-Dx_q1msW.js +0 -4682
  70. package/dist/index-Dx_q1msW.js.map +0 -1
  71. package/dist/src/ArgParser.d.ts +0 -156
  72. package/dist/src/ArgParser.d.ts.map +0 -1
  73. package/dist/src/ArgParserBase.d.ts.map +0 -1
  74. package/dist/src/FlagManager.d.ts.map +0 -1
  75. package/dist/src/fuzzy-test-cli.d.ts +0 -5
  76. package/dist/src/fuzzy-test-cli.d.ts.map +0 -1
  77. package/dist/src/fuzzy-tester.d.ts.map +0 -1
  78. package/dist/src/mcp-integration.d.ts +0 -31
  79. package/dist/src/mcp-integration.d.ts.map +0 -1
  80. package/dist/src/types.d.ts.map +0 -1
  81. package/dist/sse-B5Jf_YpG.cjs +0 -121
  82. package/dist/sse-B5Jf_YpG.cjs.map +0 -1
  83. package/dist/sse-BDL3h2Ll.js +0 -121
  84. package/dist/sse-BDL3h2Ll.js.map +0 -1
  85. package/dist/sse-DSjLfGFo.js +0 -107
  86. package/dist/sse-DSjLfGFo.js.map +0 -1
  87. package/dist/stdio-Cf19UQO7.js +0 -70
  88. package/dist/stdio-Cf19UQO7.js.map +0 -1
  89. package/dist/stdio-DESvSONI.cjs +0 -94
  90. package/dist/stdio-DESvSONI.cjs.map +0 -1
  91. package/dist/stdio-DLOResWr.js +0 -94
  92. package/dist/stdio-DLOResWr.js.map +0 -1
  93. package/dist/streamableHttp-DXIdDSbF.js +0 -342
  94. package/dist/streamableHttp-DXIdDSbF.js.map +0 -1
  95. package/dist/streamableHttp-DsXlAnqJ.cjs +0 -456
  96. package/dist/streamableHttp-DsXlAnqJ.cjs.map +0 -1
  97. package/dist/streamableHttp-Vd4Qsgko.js +0 -456
  98. package/dist/streamableHttp-Vd4Qsgko.js.map +0 -1
  99. package/dist/types-DSxPEImy.cjs +0 -943
  100. package/dist/types-DSxPEImy.cjs.map +0 -1
  101. package/dist/types-DdsPVLQ5.js +0 -846
  102. package/dist/types-DdsPVLQ5.js.map +0 -1
  103. package/dist/types-DpK81FWv.js +0 -944
  104. package/dist/types-DpK81FWv.js.map +0 -1
  105. /package/dist/src/{FlagManager.d.ts → core/FlagManager.d.ts} +0 -0
@@ -1,70 +0,0 @@
1
- import a from "node:process";
2
- import { J as n } from "./types-DdsPVLQ5.js";
3
- class o {
4
- append(t) {
5
- this._buffer = this._buffer ? Buffer.concat([this._buffer, t]) : t;
6
- }
7
- readMessage() {
8
- if (!this._buffer)
9
- return null;
10
- const t = this._buffer.indexOf(`
11
- `);
12
- if (t === -1)
13
- return null;
14
- const r = this._buffer.toString("utf8", 0, t).replace(/\r$/, "");
15
- return this._buffer = this._buffer.subarray(t + 1), f(r);
16
- }
17
- clear() {
18
- this._buffer = void 0;
19
- }
20
- }
21
- function f(e) {
22
- return n.parse(JSON.parse(e));
23
- }
24
- function d(e) {
25
- return JSON.stringify(e) + `
26
- `;
27
- }
28
- class l {
29
- constructor(t = a.stdin, r = a.stdout) {
30
- this._stdin = t, this._stdout = r, this._readBuffer = new o(), this._started = !1, this._ondata = (s) => {
31
- this._readBuffer.append(s), this.processReadBuffer();
32
- }, this._onerror = (s) => {
33
- var i;
34
- (i = this.onerror) === null || i === void 0 || i.call(this, s);
35
- };
36
- }
37
- /**
38
- * Starts listening for messages on stdin.
39
- */
40
- async start() {
41
- if (this._started)
42
- throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");
43
- this._started = !0, this._stdin.on("data", this._ondata), this._stdin.on("error", this._onerror);
44
- }
45
- processReadBuffer() {
46
- for (var t, r; ; )
47
- try {
48
- const s = this._readBuffer.readMessage();
49
- if (s === null)
50
- break;
51
- (t = this.onmessage) === null || t === void 0 || t.call(this, s);
52
- } catch (s) {
53
- (r = this.onerror) === null || r === void 0 || r.call(this, s);
54
- }
55
- }
56
- async close() {
57
- var t;
58
- this._stdin.off("data", this._ondata), this._stdin.off("error", this._onerror), this._stdin.listenerCount("data") === 0 && this._stdin.pause(), this._readBuffer.clear(), (t = this.onclose) === null || t === void 0 || t.call(this);
59
- }
60
- send(t) {
61
- return new Promise((r) => {
62
- const s = d(t);
63
- this._stdout.write(s) ? r() : this._stdout.once("drain", r);
64
- });
65
- }
66
- }
67
- export {
68
- l as StdioServerTransport
69
- };
70
- //# sourceMappingURL=stdio-Cf19UQO7.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stdio-Cf19UQO7.js","sources":["../node_modules/.pnpm/@modelcontextprotocol+sdk@1.13.1/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js","../node_modules/.pnpm/@modelcontextprotocol+sdk@1.13.1/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js"],"sourcesContent":["import { JSONRPCMessageSchema } from \"../types.js\";\n/**\n * Buffers a continuous stdio stream into discrete JSON-RPC messages.\n */\nexport class ReadBuffer {\n append(chunk) {\n this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;\n }\n readMessage() {\n if (!this._buffer) {\n return null;\n }\n const index = this._buffer.indexOf(\"\\n\");\n if (index === -1) {\n return null;\n }\n const line = this._buffer.toString(\"utf8\", 0, index).replace(/\\r$/, '');\n this._buffer = this._buffer.subarray(index + 1);\n return deserializeMessage(line);\n }\n clear() {\n this._buffer = undefined;\n }\n}\nexport function deserializeMessage(line) {\n return JSONRPCMessageSchema.parse(JSON.parse(line));\n}\nexport function serializeMessage(message) {\n return JSON.stringify(message) + \"\\n\";\n}\n//# sourceMappingURL=stdio.js.map","import process from \"node:process\";\nimport { ReadBuffer, serializeMessage } from \"../shared/stdio.js\";\n/**\n * Server transport for stdio: this communicates with a MCP client by reading from the current process' stdin and writing to stdout.\n *\n * This transport is only available in Node.js environments.\n */\nexport class StdioServerTransport {\n constructor(_stdin = process.stdin, _stdout = process.stdout) {\n this._stdin = _stdin;\n this._stdout = _stdout;\n this._readBuffer = new ReadBuffer();\n this._started = false;\n // Arrow functions to bind `this` properly, while maintaining function identity.\n this._ondata = (chunk) => {\n this._readBuffer.append(chunk);\n this.processReadBuffer();\n };\n this._onerror = (error) => {\n var _a;\n (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);\n };\n }\n /**\n * Starts listening for messages on stdin.\n */\n async start() {\n if (this._started) {\n throw new Error(\"StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.\");\n }\n this._started = true;\n this._stdin.on(\"data\", this._ondata);\n this._stdin.on(\"error\", this._onerror);\n }\n processReadBuffer() {\n var _a, _b;\n while (true) {\n try {\n const message = this._readBuffer.readMessage();\n if (message === null) {\n break;\n }\n (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message);\n }\n catch (error) {\n (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);\n }\n }\n }\n async close() {\n var _a;\n // Remove our event listeners first\n this._stdin.off(\"data\", this._ondata);\n this._stdin.off(\"error\", this._onerror);\n // Check if we were the only data listener\n const remainingDataListeners = this._stdin.listenerCount('data');\n if (remainingDataListeners === 0) {\n // Only pause stdin if we were the only listener\n // This prevents interfering with other parts of the application that might be using stdin\n this._stdin.pause();\n }\n // Clear the buffer and notify closure\n this._readBuffer.clear();\n (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);\n }\n send(message) {\n return new Promise((resolve) => {\n const json = serializeMessage(message);\n if (this._stdout.write(json)) {\n resolve();\n }\n else {\n this._stdout.once(\"drain\", resolve);\n }\n });\n }\n}\n//# sourceMappingURL=stdio.js.map"],"names":["ReadBuffer","chunk","index","line","deserializeMessage","JSONRPCMessageSchema","serializeMessage","message","StdioServerTransport","_stdin","process","_stdout","error","_a","_b","resolve","json"],"mappings":";;AAIO,MAAMA,EAAW;AAAA,EACpB,OAAOC,GAAO;AACV,SAAK,UAAU,KAAK,UAAU,OAAO,OAAO,CAAC,KAAK,SAASA,CAAK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AAK,YAAY,YAAW;AAC5C,YAAIA,MAAY;AACZ;AAEJ,SAACM,IAAK,KAAK,eAAe,QAAQA,MAAO,UAAkBA,EAAG,KAAK,MAAMN,CAAO;AAAA,MAChG,SACmBK,GAAO;AACV,SAACE,IAAK,KAAK,aAAa,QAAQA,MAAO,UAAkBA,EAAG,KAAK,MAAMF,CAAK;AAAA,MAC5F;AAAA,EAEA;AAAA,EACI,MAAM,QAAQ;AACV,QAAIC;AAEJ,SAAK,OAAO,IAAI,QAAQ,KAAK,OAAO,GACpC,KAAK,OAAO,IAAI,SAAS,KAAK,QAAQ,GAEP,KAAK,OAAO,cAAc,MAAM,MAChC,KAG3B,KAAK,OAAO,MAAK,GAGrB,KAAK,YAAY,MAAK,IACrBA,IAAK,KAAK,aAAa,QAAQA,MAAO,UAAkBA,EAAG,KAAK,IAAI;AAAA,EAC7E;AAAA,EACI,KAAKN,GAAS;AACV,WAAO,IAAI,QAAQ,CAACQ,MAAY;AAC5B,YAAMC,IAAOV,EAAiBC,CAAO;AACrC,MAAI,KAAK,QAAQ,MAAMS,CAAI,IACvBD,EAAO,IAGP,KAAK,QAAQ,KAAK,SAASA,CAAO;AAAA,IAElD,CAAS;AAAA,EACT;AACA;","x_google_ignoreList":[0,1]}
@@ -1,94 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const process = require("node:process");
4
- const types = require("./types-DSxPEImy.cjs");
5
- class ReadBuffer {
6
- append(chunk) {
7
- this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
8
- }
9
- readMessage() {
10
- if (!this._buffer) {
11
- return null;
12
- }
13
- const index = this._buffer.indexOf("\n");
14
- if (index === -1) {
15
- return null;
16
- }
17
- const line = this._buffer.toString("utf8", 0, index).replace(/\r$/, "");
18
- this._buffer = this._buffer.subarray(index + 1);
19
- return deserializeMessage(line);
20
- }
21
- clear() {
22
- this._buffer = void 0;
23
- }
24
- }
25
- function deserializeMessage(line) {
26
- return types.JSONRPCMessageSchema.parse(JSON.parse(line));
27
- }
28
- function serializeMessage(message) {
29
- return JSON.stringify(message) + "\n";
30
- }
31
- class StdioServerTransport {
32
- constructor(_stdin = process.stdin, _stdout = process.stdout) {
33
- this._stdin = _stdin;
34
- this._stdout = _stdout;
35
- this._readBuffer = new ReadBuffer();
36
- this._started = false;
37
- this._ondata = (chunk) => {
38
- this._readBuffer.append(chunk);
39
- this.processReadBuffer();
40
- };
41
- this._onerror = (error) => {
42
- var _a;
43
- (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
44
- };
45
- }
46
- /**
47
- * Starts listening for messages on stdin.
48
- */
49
- async start() {
50
- if (this._started) {
51
- throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");
52
- }
53
- this._started = true;
54
- this._stdin.on("data", this._ondata);
55
- this._stdin.on("error", this._onerror);
56
- }
57
- processReadBuffer() {
58
- var _a, _b;
59
- while (true) {
60
- try {
61
- const message = this._readBuffer.readMessage();
62
- if (message === null) {
63
- break;
64
- }
65
- (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message);
66
- } catch (error) {
67
- (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);
68
- }
69
- }
70
- }
71
- async close() {
72
- var _a;
73
- this._stdin.off("data", this._ondata);
74
- this._stdin.off("error", this._onerror);
75
- const remainingDataListeners = this._stdin.listenerCount("data");
76
- if (remainingDataListeners === 0) {
77
- this._stdin.pause();
78
- }
79
- this._readBuffer.clear();
80
- (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
81
- }
82
- send(message) {
83
- return new Promise((resolve) => {
84
- const json = serializeMessage(message);
85
- if (this._stdout.write(json)) {
86
- resolve();
87
- } else {
88
- this._stdout.once("drain", resolve);
89
- }
90
- });
91
- }
92
- }
93
- exports.StdioServerTransport = StdioServerTransport;
94
- //# sourceMappingURL=stdio-DESvSONI.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stdio-DESvSONI.cjs","sources":["../node_modules/.pnpm/@modelcontextprotocol+sdk@1.13.1/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js","../node_modules/.pnpm/@modelcontextprotocol+sdk@1.13.1/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js"],"sourcesContent":["import { JSONRPCMessageSchema } from \"../types.js\";\n/**\n * Buffers a continuous stdio stream into discrete JSON-RPC messages.\n */\nexport class ReadBuffer {\n append(chunk) {\n this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;\n }\n readMessage() {\n if (!this._buffer) {\n return null;\n }\n const index = this._buffer.indexOf(\"\\n\");\n if (index === -1) {\n return null;\n }\n const line = this._buffer.toString(\"utf8\", 0, index).replace(/\\r$/, '');\n this._buffer = this._buffer.subarray(index + 1);\n return deserializeMessage(line);\n }\n clear() {\n this._buffer = undefined;\n }\n}\nexport function deserializeMessage(line) {\n return JSONRPCMessageSchema.parse(JSON.parse(line));\n}\nexport function serializeMessage(message) {\n return JSON.stringify(message) + \"\\n\";\n}\n//# sourceMappingURL=stdio.js.map","import process from \"node:process\";\nimport { ReadBuffer, serializeMessage } from \"../shared/stdio.js\";\n/**\n * Server transport for stdio: this communicates with a MCP client by reading from the current process' stdin and writing to stdout.\n *\n * This transport is only available in Node.js environments.\n */\nexport class StdioServerTransport {\n constructor(_stdin = process.stdin, _stdout = process.stdout) {\n this._stdin = _stdin;\n this._stdout = _stdout;\n this._readBuffer = new ReadBuffer();\n this._started = false;\n // Arrow functions to bind `this` properly, while maintaining function identity.\n this._ondata = (chunk) => {\n this._readBuffer.append(chunk);\n this.processReadBuffer();\n };\n this._onerror = (error) => {\n var _a;\n (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);\n };\n }\n /**\n * Starts listening for messages on stdin.\n */\n async start() {\n if (this._started) {\n throw new Error(\"StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.\");\n }\n this._started = true;\n this._stdin.on(\"data\", this._ondata);\n this._stdin.on(\"error\", this._onerror);\n }\n processReadBuffer() {\n var _a, _b;\n while (true) {\n try {\n const message = this._readBuffer.readMessage();\n if (message === null) {\n break;\n }\n (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message);\n }\n catch (error) {\n (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);\n }\n }\n }\n async close() {\n var _a;\n // Remove our event listeners first\n this._stdin.off(\"data\", this._ondata);\n this._stdin.off(\"error\", this._onerror);\n // Check if we were the only data listener\n const remainingDataListeners = this._stdin.listenerCount('data');\n if (remainingDataListeners === 0) {\n // Only pause stdin if we were the only listener\n // This prevents interfering with other parts of the application that might be using stdin\n this._stdin.pause();\n }\n // Clear the buffer and notify closure\n this._readBuffer.clear();\n (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);\n }\n send(message) {\n return new Promise((resolve) => {\n const json = serializeMessage(message);\n if (this._stdout.write(json)) {\n resolve();\n }\n else {\n this._stdout.once(\"drain\", resolve);\n }\n });\n }\n}\n//# sourceMappingURL=stdio.js.map"],"names":["JSONRPCMessageSchema"],"mappings":";;;;AAIO,MAAM,WAAW;AAAA,EACpB,OAAO,OAAO;AACV,SAAK,UAAU,KAAK,UAAU,OAAO,OAAO,CAAC,KAAK,SAAS,KAAK,CAAC,IAAI;AAAA,EAC7E;AAAA,EACI,cAAc;AACV,QAAI,CAAC,KAAK,SAAS;AACf,aAAO;AAAA,IACnB;AACQ,UAAM,QAAQ,KAAK,QAAQ,QAAQ,IAAI;AACvC,QAAI,UAAU,IAAI;AACd,aAAO;AAAA,IACnB;AACQ,UAAM,OAAO,KAAK,QAAQ,SAAS,QAAQ,GAAG,KAAK,EAAE,QAAQ,OAAO,EAAE;AACtE,SAAK,UAAU,KAAK,QAAQ,SAAS,QAAQ,CAAC;AAC9C,WAAO,mBAAmB,IAAI;AAAA,EACtC;AAAA,EACI,QAAQ;AACJ,SAAK,UAAU;AAAA,EACvB;AACA;AACO,SAAS,mBAAmB,MAAM;A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AAK,QAAQ;AAEtC,UAAM,yBAAyB,KAAK,OAAO,cAAc,MAAM;AAC/D,QAAI,2BAA2B,GAAG;AAG9B,WAAK,OAAO,MAAK;AAAA,IAC7B;AAEQ,SAAK,YAAY,MAAK;AACtB,KAAC,KAAK,KAAK,aAAa,QAAQ,OAAO,SAAS,SAAS,GAAG,KAAK,IAAI;AAAA,EAC7E;AAAA,EACI,KAAK,SAAS;AACV,WAAO,IAAI,QAAQ,CAAC,YAAY;AAC5B,YAAM,OAAO,iBAAiB,OAAO;AACrC,UAAI,KAAK,QAAQ,MAAM,IAAI,GAAG;AAC1B,gBAAO;AAAA,MACvB,OACiB;AACD,aAAK,QAAQ,KAAK,SAAS,OAAO;AAAA,MAClD;AAAA,IACA,CAAS;AAAA,EACT;AACA;;","x_google_ignoreList":[0,1]}
@@ -1,94 +0,0 @@
1
- import process from "node:process";
2
- import { J as JSONRPCMessageSchema } from "./types-DpK81FWv.js";
3
- class ReadBuffer {
4
- append(chunk) {
5
- this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
6
- }
7
- readMessage() {
8
- if (!this._buffer) {
9
- return null;
10
- }
11
- const index = this._buffer.indexOf("\n");
12
- if (index === -1) {
13
- return null;
14
- }
15
- const line = this._buffer.toString("utf8", 0, index).replace(/\r$/, "");
16
- this._buffer = this._buffer.subarray(index + 1);
17
- return deserializeMessage(line);
18
- }
19
- clear() {
20
- this._buffer = void 0;
21
- }
22
- }
23
- function deserializeMessage(line) {
24
- return JSONRPCMessageSchema.parse(JSON.parse(line));
25
- }
26
- function serializeMessage(message) {
27
- return JSON.stringify(message) + "\n";
28
- }
29
- class StdioServerTransport {
30
- constructor(_stdin = process.stdin, _stdout = process.stdout) {
31
- this._stdin = _stdin;
32
- this._stdout = _stdout;
33
- this._readBuffer = new ReadBuffer();
34
- this._started = false;
35
- this._ondata = (chunk) => {
36
- this._readBuffer.append(chunk);
37
- this.processReadBuffer();
38
- };
39
- this._onerror = (error) => {
40
- var _a;
41
- (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
42
- };
43
- }
44
- /**
45
- * Starts listening for messages on stdin.
46
- */
47
- async start() {
48
- if (this._started) {
49
- throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");
50
- }
51
- this._started = true;
52
- this._stdin.on("data", this._ondata);
53
- this._stdin.on("error", this._onerror);
54
- }
55
- processReadBuffer() {
56
- var _a, _b;
57
- while (true) {
58
- try {
59
- const message = this._readBuffer.readMessage();
60
- if (message === null) {
61
- break;
62
- }
63
- (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message);
64
- } catch (error) {
65
- (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);
66
- }
67
- }
68
- }
69
- async close() {
70
- var _a;
71
- this._stdin.off("data", this._ondata);
72
- this._stdin.off("error", this._onerror);
73
- const remainingDataListeners = this._stdin.listenerCount("data");
74
- if (remainingDataListeners === 0) {
75
- this._stdin.pause();
76
- }
77
- this._readBuffer.clear();
78
- (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
79
- }
80
- send(message) {
81
- return new Promise((resolve) => {
82
- const json = serializeMessage(message);
83
- if (this._stdout.write(json)) {
84
- resolve();
85
- } else {
86
- this._stdout.once("drain", resolve);
87
- }
88
- });
89
- }
90
- }
91
- export {
92
- StdioServerTransport
93
- };
94
- //# sourceMappingURL=stdio-DLOResWr.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stdio-DLOResWr.js","sources":["../node_modules/.pnpm/@modelcontextprotocol+sdk@1.13.1/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js","../node_modules/.pnpm/@modelcontextprotocol+sdk@1.13.1/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js"],"sourcesContent":["import { JSONRPCMessageSchema } from \"../types.js\";\n/**\n * Buffers a continuous stdio stream into discrete JSON-RPC messages.\n */\nexport class ReadBuffer {\n append(chunk) {\n this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;\n }\n readMessage() {\n if (!this._buffer) {\n return null;\n }\n const index = this._buffer.indexOf(\"\\n\");\n if (index === -1) {\n return null;\n }\n const line = this._buffer.toString(\"utf8\", 0, index).replace(/\\r$/, '');\n this._buffer = this._buffer.subarray(index + 1);\n return deserializeMessage(line);\n }\n clear() {\n this._buffer = undefined;\n }\n}\nexport function deserializeMessage(line) {\n return JSONRPCMessageSchema.parse(JSON.parse(line));\n}\nexport function serializeMessage(message) {\n return JSON.stringify(message) + \"\\n\";\n}\n//# sourceMappingURL=stdio.js.map","import process from \"node:process\";\nimport { ReadBuffer, serializeMessage } from \"../shared/stdio.js\";\n/**\n * Server transport for stdio: this communicates with a MCP client by reading from the current process' stdin and writing to stdout.\n *\n * This transport is only available in Node.js environments.\n */\nexport class StdioServerTransport {\n constructor(_stdin = process.stdin, _stdout = process.stdout) {\n this._stdin = _stdin;\n this._stdout = _stdout;\n this._readBuffer = new ReadBuffer();\n this._started = false;\n // Arrow functions to bind `this` properly, while maintaining function identity.\n this._ondata = (chunk) => {\n this._readBuffer.append(chunk);\n this.processReadBuffer();\n };\n this._onerror = (error) => {\n var _a;\n (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);\n };\n }\n /**\n * Starts listening for messages on stdin.\n */\n async start() {\n if (this._started) {\n throw new Error(\"StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.\");\n }\n this._started = true;\n this._stdin.on(\"data\", this._ondata);\n this._stdin.on(\"error\", this._onerror);\n }\n processReadBuffer() {\n var _a, _b;\n while (true) {\n try {\n const message = this._readBuffer.readMessage();\n if (message === null) {\n break;\n }\n (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message);\n }\n catch (error) {\n (_b = this.onerror) === null || _b === void 0 ? void 0 : _b.call(this, error);\n }\n }\n }\n async close() {\n var _a;\n // Remove our event listeners first\n this._stdin.off(\"data\", this._ondata);\n this._stdin.off(\"error\", this._onerror);\n // Check if we were the only data listener\n const remainingDataListeners = this._stdin.listenerCount('data');\n if (remainingDataListeners === 0) {\n // Only pause stdin if we were the only listener\n // This prevents interfering with other parts of the application that might be using stdin\n this._stdin.pause();\n }\n // Clear the buffer and notify closure\n this._readBuffer.clear();\n (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);\n }\n send(message) {\n return new Promise((resolve) => {\n const json = serializeMessage(message);\n if (this._stdout.write(json)) {\n resolve();\n }\n else {\n this._stdout.once(\"drain\", resolve);\n }\n });\n }\n}\n//# sourceMappingURL=stdio.js.map"],"names":[],"mappings":";;AAIO,MAAM,WAAW;AAAA,EACpB,OAAO,OAAO;AACV,SAAK,UAAU,KAAK,UAAU,OAAO,OAAO,CAAC,KAAK,SAAS,KAAK,CAAC,IAAI;AAAA,EAC7E;AAAA,EACI,cAAc;AACV,QAAI,CAAC,KAAK,SAAS;AACf,aAAO;AAAA,IACnB;AACQ,UAAM,QAAQ,KAAK,QAAQ,QAAQ,IAAI;AACvC,QAAI,UAAU,IAAI;AACd,aAAO;AAAA,IACnB;AACQ,UAAM,OAAO,KAAK,QAAQ,SAAS,QAAQ,GAAG,KAAK,EAAE,QAAQ,OAAO,EAAE;AACtE,SAAK,UAAU,KAAK,QAAQ,SAAS,QAAQ,CAAC;AAC9C,WAAO,mBAAmB,IAAI;AAAA,EACtC;AAAA,EACI,QAAQ;AACJ,SAAK,UAAU;AAAA,EACvB;AACA;AACO,SAAS,mBAAmB,MAAM;AACrC,SAAO,qBAAqB,MAAM,KAAK,MAAM,IAAI,CAAC;AACtD;AACO,SAAS,iBAAiB,SAAS;AACtC,SAAO,KAAK,UAAU,OAAO,IAAI;AACrC;ACtBO,MAAM,qBAAqB;AAAA,EAC9B,YAAY,SAAS,QAAQ,OAAO,UAAU,QAAQ,QAAQ;AAC1D,SAAK,SAAS;AACd,SAAK,UAAU;AACf,SAAK,cAAc,IAAI,WAAU;AACjC,SAAK,WAAW;AAEhB,SAAK,UAAU,CAAC,UAAU;AACtB,WAAK,YAAY,OA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QAAQ,MAAM,IAAI,GAAG;AAC1B,gBAAO;AAAA,MACvB,OACiB;AACD,aAAK,QAAQ,KAAK,SAAS,OAAO;AAAA,MAClD;AAAA,IACA,CAAS;AAAA,EACT;AACA;","x_google_ignoreList":[0,1]}
@@ -1,342 +0,0 @@
1
- import { J as g, i as I, a as y, D as R, S as w, b as f, c as S } from "./types-DdsPVLQ5.js";
2
- import { c as E, g as M } from "./index-Dx_q1msW.js";
3
- import { randomUUID as O } from "node:crypto";
4
- const T = "4mb";
5
- class q {
6
- constructor(e) {
7
- var t;
8
- this._started = !1, this._streamMapping = /* @__PURE__ */ new Map(), this._requestToStreamMapping = /* @__PURE__ */ new Map(), this._requestResponseMap = /* @__PURE__ */ new Map(), this._initialized = !1, this._enableJsonResponse = !1, this._standaloneSseStreamId = "_GET_stream", this.sessionIdGenerator = e.sessionIdGenerator, this._enableJsonResponse = (t = e.enableJsonResponse) !== null && t !== void 0 ? t : !1, this._eventStore = e.eventStore, this._onsessioninitialized = e.onsessioninitialized;
9
- }
10
- /**
11
- * Starts the transport. This is required by the Transport interface but is a no-op
12
- * for the Streamable HTTP transport as connections are managed per-request.
13
- */
14
- async start() {
15
- if (this._started)
16
- throw new Error("Transport already started");
17
- this._started = !0;
18
- }
19
- /**
20
- * Handles an incoming HTTP request, whether GET or POST
21
- */
22
- async handleRequest(e, t, s) {
23
- e.method === "POST" ? await this.handlePostRequest(e, t, s) : e.method === "GET" ? await this.handleGetRequest(e, t) : e.method === "DELETE" ? await this.handleDeleteRequest(e, t) : await this.handleUnsupportedRequest(t);
24
- }
25
- /**
26
- * Handles GET requests for SSE stream
27
- */
28
- async handleGetRequest(e, t) {
29
- const s = e.headers.accept;
30
- if (!(s != null && s.includes("text/event-stream"))) {
31
- t.writeHead(406).end(JSON.stringify({
32
- jsonrpc: "2.0",
33
- error: {
34
- code: -32e3,
35
- message: "Not Acceptable: Client must accept text/event-stream"
36
- },
37
- id: null
38
- }));
39
- return;
40
- }
41
- if (!this.validateSession(e, t) || !this.validateProtocolVersion(e, t))
42
- return;
43
- if (this._eventStore) {
44
- const n = e.headers["last-event-id"];
45
- if (n) {
46
- await this.replayEvents(n, t);
47
- return;
48
- }
49
- }
50
- const i = {
51
- "Content-Type": "text/event-stream",
52
- "Cache-Control": "no-cache, no-transform",
53
- Connection: "keep-alive"
54
- };
55
- if (this.sessionId !== void 0 && (i["mcp-session-id"] = this.sessionId), this._streamMapping.get(this._standaloneSseStreamId) !== void 0) {
56
- t.writeHead(409).end(JSON.stringify({
57
- jsonrpc: "2.0",
58
- error: {
59
- code: -32e3,
60
- message: "Conflict: Only one SSE stream is allowed per session"
61
- },
62
- id: null
63
- }));
64
- return;
65
- }
66
- t.writeHead(200, i).flushHeaders(), this._streamMapping.set(this._standaloneSseStreamId, t), t.on("close", () => {
67
- this._streamMapping.delete(this._standaloneSseStreamId);
68
- });
69
- }
70
- /**
71
- * Replays events that would have been sent after the specified event ID
72
- * Only used when resumability is enabled
73
- */
74
- async replayEvents(e, t) {
75
- var s, i;
76
- if (this._eventStore)
77
- try {
78
- const n = {
79
- "Content-Type": "text/event-stream",
80
- "Cache-Control": "no-cache, no-transform",
81
- Connection: "keep-alive"
82
- };
83
- this.sessionId !== void 0 && (n["mcp-session-id"] = this.sessionId), t.writeHead(200, n).flushHeaders();
84
- const o = await ((s = this._eventStore) === null || s === void 0 ? void 0 : s.replayEventsAfter(e, {
85
- send: async (d, r) => {
86
- var a;
87
- this.writeSSEEvent(t, r, d) || ((a = this.onerror) === null || a === void 0 || a.call(this, new Error("Failed replay events")), t.end());
88
- }
89
- }));
90
- this._streamMapping.set(o, t);
91
- } catch (n) {
92
- (i = this.onerror) === null || i === void 0 || i.call(this, n);
93
- }
94
- }
95
- /**
96
- * Writes an event to the SSE stream with proper formatting
97
- */
98
- writeSSEEvent(e, t, s) {
99
- let i = `event: message
100
- `;
101
- return s && (i += `id: ${s}
102
- `), i += `data: ${JSON.stringify(t)}
103
-
104
- `, e.write(i);
105
- }
106
- /**
107
- * Handles unsupported requests (PUT, PATCH, etc.)
108
- */
109
- async handleUnsupportedRequest(e) {
110
- e.writeHead(405, {
111
- Allow: "GET, POST, DELETE"
112
- }).end(JSON.stringify({
113
- jsonrpc: "2.0",
114
- error: {
115
- code: -32e3,
116
- message: "Method not allowed."
117
- },
118
- id: null
119
- }));
120
- }
121
- /**
122
- * Handles POST requests containing JSON-RPC messages
123
- */
124
- async handlePostRequest(e, t, s) {
125
- var i, n, o, d, r;
126
- try {
127
- const a = e.headers.accept;
128
- if (!(a != null && a.includes("application/json")) || !a.includes("text/event-stream")) {
129
- t.writeHead(406).end(JSON.stringify({
130
- jsonrpc: "2.0",
131
- error: {
132
- code: -32e3,
133
- message: "Not Acceptable: Client must accept both application/json and text/event-stream"
134
- },
135
- id: null
136
- }));
137
- return;
138
- }
139
- const p = e.headers["content-type"];
140
- if (!p || !p.includes("application/json")) {
141
- t.writeHead(415).end(JSON.stringify({
142
- jsonrpc: "2.0",
143
- error: {
144
- code: -32e3,
145
- message: "Unsupported Media Type: Content-Type must be application/json"
146
- },
147
- id: null
148
- }));
149
- return;
150
- }
151
- const v = e.auth;
152
- let u;
153
- if (s !== void 0)
154
- u = s;
155
- else {
156
- const l = E.parse(p), c = await M(e, {
157
- limit: T,
158
- encoding: (i = l.parameters.charset) !== null && i !== void 0 ? i : "utf-8"
159
- });
160
- u = JSON.parse(c.toString());
161
- }
162
- let h;
163
- Array.isArray(u) ? h = u.map((l) => g.parse(l)) : h = [g.parse(u)];
164
- const m = h.some(I);
165
- if (m) {
166
- if (this._initialized && this.sessionId !== void 0) {
167
- t.writeHead(400).end(JSON.stringify({
168
- jsonrpc: "2.0",
169
- error: {
170
- code: -32600,
171
- message: "Invalid Request: Server already initialized"
172
- },
173
- id: null
174
- }));
175
- return;
176
- }
177
- if (h.length > 1) {
178
- t.writeHead(400).end(JSON.stringify({
179
- jsonrpc: "2.0",
180
- error: {
181
- code: -32600,
182
- message: "Invalid Request: Only one initialization request is allowed"
183
- },
184
- id: null
185
- }));
186
- return;
187
- }
188
- this.sessionId = (n = this.sessionIdGenerator) === null || n === void 0 ? void 0 : n.call(this), this._initialized = !0, this.sessionId && this._onsessioninitialized && this._onsessioninitialized(this.sessionId);
189
- }
190
- if (!m && (!this.validateSession(e, t) || !this.validateProtocolVersion(e, t)))
191
- return;
192
- const _ = h.some(y);
193
- if (_) {
194
- if (_) {
195
- const l = O();
196
- if (!this._enableJsonResponse) {
197
- const c = {
198
- "Content-Type": "text/event-stream",
199
- "Cache-Control": "no-cache",
200
- Connection: "keep-alive"
201
- };
202
- this.sessionId !== void 0 && (c["mcp-session-id"] = this.sessionId), t.writeHead(200, c);
203
- }
204
- for (const c of h)
205
- y(c) && (this._streamMapping.set(l, t), this._requestToStreamMapping.set(c.id, l));
206
- t.on("close", () => {
207
- this._streamMapping.delete(l);
208
- });
209
- for (const c of h)
210
- (d = this.onmessage) === null || d === void 0 || d.call(this, c, { authInfo: v });
211
- }
212
- } else {
213
- t.writeHead(202).end();
214
- for (const l of h)
215
- (o = this.onmessage) === null || o === void 0 || o.call(this, l, { authInfo: v });
216
- }
217
- } catch (a) {
218
- t.writeHead(400).end(JSON.stringify({
219
- jsonrpc: "2.0",
220
- error: {
221
- code: -32700,
222
- message: "Parse error",
223
- data: String(a)
224
- },
225
- id: null
226
- })), (r = this.onerror) === null || r === void 0 || r.call(this, a);
227
- }
228
- }
229
- /**
230
- * Handles DELETE requests to terminate sessions
231
- */
232
- async handleDeleteRequest(e, t) {
233
- this.validateSession(e, t) && this.validateProtocolVersion(e, t) && (await this.close(), t.writeHead(200).end());
234
- }
235
- /**
236
- * Validates session ID for non-initialization requests
237
- * Returns true if the session is valid, false otherwise
238
- */
239
- validateSession(e, t) {
240
- if (this.sessionIdGenerator === void 0)
241
- return !0;
242
- if (!this._initialized)
243
- return t.writeHead(400).end(JSON.stringify({
244
- jsonrpc: "2.0",
245
- error: {
246
- code: -32e3,
247
- message: "Bad Request: Server not initialized"
248
- },
249
- id: null
250
- })), !1;
251
- const s = e.headers["mcp-session-id"];
252
- if (s) {
253
- if (Array.isArray(s))
254
- return t.writeHead(400).end(JSON.stringify({
255
- jsonrpc: "2.0",
256
- error: {
257
- code: -32e3,
258
- message: "Bad Request: Mcp-Session-Id header must be a single value"
259
- },
260
- id: null
261
- })), !1;
262
- if (s !== this.sessionId)
263
- return t.writeHead(404).end(JSON.stringify({
264
- jsonrpc: "2.0",
265
- error: {
266
- code: -32001,
267
- message: "Session not found"
268
- },
269
- id: null
270
- })), !1;
271
- } else return t.writeHead(400).end(JSON.stringify({
272
- jsonrpc: "2.0",
273
- error: {
274
- code: -32e3,
275
- message: "Bad Request: Mcp-Session-Id header is required"
276
- },
277
- id: null
278
- })), !1;
279
- return !0;
280
- }
281
- validateProtocolVersion(e, t) {
282
- var s;
283
- let i = (s = e.headers["mcp-protocol-version"]) !== null && s !== void 0 ? s : R;
284
- return Array.isArray(i) && (i = i[i.length - 1]), w.includes(i) ? !0 : (t.writeHead(400).end(JSON.stringify({
285
- jsonrpc: "2.0",
286
- error: {
287
- code: -32e3,
288
- message: `Bad Request: Unsupported protocol version (supported versions: ${w.join(", ")})`
289
- },
290
- id: null
291
- })), !1);
292
- }
293
- async close() {
294
- var e;
295
- this._streamMapping.forEach((t) => {
296
- t.end();
297
- }), this._streamMapping.clear(), this._requestResponseMap.clear(), (e = this.onclose) === null || e === void 0 || e.call(this);
298
- }
299
- async send(e, t) {
300
- let s = t == null ? void 0 : t.relatedRequestId;
301
- if ((f(e) || S(e)) && (s = e.id), s === void 0) {
302
- if (f(e) || S(e))
303
- throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
304
- const o = this._streamMapping.get(this._standaloneSseStreamId);
305
- if (o === void 0)
306
- return;
307
- let d;
308
- this._eventStore && (d = await this._eventStore.storeEvent(this._standaloneSseStreamId, e)), this.writeSSEEvent(o, e, d);
309
- return;
310
- }
311
- const i = this._requestToStreamMapping.get(s), n = this._streamMapping.get(i);
312
- if (!i)
313
- throw new Error(`No connection established for request ID: ${String(s)}`);
314
- if (!this._enableJsonResponse) {
315
- let o;
316
- this._eventStore && (o = await this._eventStore.storeEvent(i, e)), n && this.writeSSEEvent(n, e, o);
317
- }
318
- if (f(e) || S(e)) {
319
- this._requestResponseMap.set(s, e);
320
- const o = Array.from(this._requestToStreamMapping.entries()).filter(([r, a]) => this._streamMapping.get(a) === n).map(([r]) => r);
321
- if (o.every((r) => this._requestResponseMap.has(r))) {
322
- if (!n)
323
- throw new Error(`No connection established for request ID: ${String(s)}`);
324
- if (this._enableJsonResponse) {
325
- const r = {
326
- "Content-Type": "application/json"
327
- };
328
- this.sessionId !== void 0 && (r["mcp-session-id"] = this.sessionId);
329
- const a = o.map((p) => this._requestResponseMap.get(p));
330
- n.writeHead(200, r), a.length === 1 ? n.end(JSON.stringify(a[0])) : n.end(JSON.stringify(a));
331
- } else
332
- n.end();
333
- for (const r of o)
334
- this._requestResponseMap.delete(r), this._requestToStreamMapping.delete(r);
335
- }
336
- }
337
- }
338
- }
339
- export {
340
- q as StreamableHTTPServerTransport
341
- };
342
- //# sourceMappingURL=streamableHttp-DXIdDSbF.js.map