@clawpay-hedera/sdk 0.1.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 (102) hide show
  1. package/README.md +294 -0
  2. package/dist/cli/index.d.ts +3 -0
  3. package/dist/cli/index.d.ts.map +1 -0
  4. package/dist/cli/index.js +137 -0
  5. package/dist/cli/index.js.map +1 -0
  6. package/dist/client/hedera-payment.d.ts +25 -0
  7. package/dist/client/hedera-payment.d.ts.map +1 -0
  8. package/dist/client/hedera-payment.js +68 -0
  9. package/dist/client/hedera-payment.js.map +1 -0
  10. package/dist/client/with-x402-client.d.ts +27 -0
  11. package/dist/client/with-x402-client.d.ts.map +1 -0
  12. package/dist/client/with-x402-client.js +136 -0
  13. package/dist/client/with-x402-client.js.map +1 -0
  14. package/dist/client.d.ts +2 -0
  15. package/dist/client.d.ts.map +1 -0
  16. package/dist/client.js +2 -0
  17. package/dist/client.js.map +1 -0
  18. package/dist/handler/proxy/hooks/analytics-hook.d.ts +299 -0
  19. package/dist/handler/proxy/hooks/analytics-hook.d.ts.map +1 -0
  20. package/dist/handler/proxy/hooks/analytics-hook.js +133 -0
  21. package/dist/handler/proxy/hooks/analytics-hook.js.map +1 -0
  22. package/dist/handler/proxy/hooks/auth-headers-hook.d.ts +20 -0
  23. package/dist/handler/proxy/hooks/auth-headers-hook.d.ts.map +1 -0
  24. package/dist/handler/proxy/hooks/auth-headers-hook.js +34 -0
  25. package/dist/handler/proxy/hooks/auth-headers-hook.js.map +1 -0
  26. package/dist/handler/proxy/hooks/hcs-audit-hook.d.ts +133 -0
  27. package/dist/handler/proxy/hooks/hcs-audit-hook.d.ts.map +1 -0
  28. package/dist/handler/proxy/hooks/hcs-audit-hook.js +138 -0
  29. package/dist/handler/proxy/hooks/hcs-audit-hook.js.map +1 -0
  30. package/dist/handler/proxy/hooks/logging-hook.d.ts +100 -0
  31. package/dist/handler/proxy/hooks/logging-hook.d.ts.map +1 -0
  32. package/dist/handler/proxy/hooks/logging-hook.js +14 -0
  33. package/dist/handler/proxy/hooks/logging-hook.js.map +1 -0
  34. package/dist/handler/proxy/hooks/x402-hook.d.ts +246 -0
  35. package/dist/handler/proxy/hooks/x402-hook.d.ts.map +1 -0
  36. package/dist/handler/proxy/hooks/x402-hook.js +219 -0
  37. package/dist/handler/proxy/hooks/x402-hook.js.map +1 -0
  38. package/dist/handler/proxy/hooks.d.ts +12111 -0
  39. package/dist/handler/proxy/hooks.d.ts.map +1 -0
  40. package/dist/handler/proxy/hooks.js +142 -0
  41. package/dist/handler/proxy/hooks.js.map +1 -0
  42. package/dist/handler/proxy/index.d.ts +3 -0
  43. package/dist/handler/proxy/index.d.ts.map +1 -0
  44. package/dist/handler/proxy/index.js +489 -0
  45. package/dist/handler/proxy/index.js.map +1 -0
  46. package/dist/handler/server/index.d.ts +25 -0
  47. package/dist/handler/server/index.d.ts.map +1 -0
  48. package/dist/handler/server/index.js +38 -0
  49. package/dist/handler/server/index.js.map +1 -0
  50. package/dist/handler/server/platform-detection.d.ts +32 -0
  51. package/dist/handler/server/platform-detection.d.ts.map +1 -0
  52. package/dist/handler/server/platform-detection.js +441 -0
  53. package/dist/handler/server/platform-detection.js.map +1 -0
  54. package/dist/handler/server/plugins/with-x402.d.ts +21 -0
  55. package/dist/handler/server/plugins/with-x402.d.ts.map +1 -0
  56. package/dist/handler/server/plugins/with-x402.js +290 -0
  57. package/dist/handler/server/plugins/with-x402.js.map +1 -0
  58. package/dist/handler/server/templates/x402-server.d.ts +16 -0
  59. package/dist/handler/server/templates/x402-server.d.ts.map +1 -0
  60. package/dist/handler/server/templates/x402-server.js +13 -0
  61. package/dist/handler/server/templates/x402-server.js.map +1 -0
  62. package/dist/handler/shared/hedera-price.d.ts +26 -0
  63. package/dist/handler/shared/hedera-price.d.ts.map +1 -0
  64. package/dist/handler/shared/hedera-price.js +54 -0
  65. package/dist/handler/shared/hedera-price.js.map +1 -0
  66. package/dist/handler.d.ts +14 -0
  67. package/dist/handler.d.ts.map +1 -0
  68. package/dist/handler.js +12 -0
  69. package/dist/handler.js.map +1 -0
  70. package/dist/index.d.ts +7 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +5 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/networks/hedera.d.ts +52 -0
  75. package/dist/networks/hedera.d.ts.map +1 -0
  76. package/dist/networks/hedera.js +61 -0
  77. package/dist/networks/hedera.js.map +1 -0
  78. package/dist/server/stdio/index.d.ts +2 -0
  79. package/dist/server/stdio/index.d.ts.map +1 -0
  80. package/dist/server/stdio/index.js +91 -0
  81. package/dist/server/stdio/index.js.map +1 -0
  82. package/dist/server/stdio/proxy-server.d.ts +9 -0
  83. package/dist/server/stdio/proxy-server.d.ts.map +1 -0
  84. package/dist/server/stdio/proxy-server.js +53 -0
  85. package/dist/server/stdio/proxy-server.js.map +1 -0
  86. package/dist/server/stdio/start-stdio-server.d.ts +28 -0
  87. package/dist/server/stdio/start-stdio-server.d.ts.map +1 -0
  88. package/dist/server/stdio/start-stdio-server.js +84 -0
  89. package/dist/server/stdio/start-stdio-server.js.map +1 -0
  90. package/dist/server.d.ts +6 -0
  91. package/dist/server.d.ts.map +1 -0
  92. package/dist/server.js +4 -0
  93. package/dist/server.js.map +1 -0
  94. package/dist/utils/signer.d.ts +4 -0
  95. package/dist/utils/signer.d.ts.map +1 -0
  96. package/dist/utils/signer.js +58 -0
  97. package/dist/utils/signer.js.map +1 -0
  98. package/dist/utils.d.ts +2 -0
  99. package/dist/utils.d.ts.map +1 -0
  100. package/dist/utils.js +2 -0
  101. package/dist/utils.js.map +1 -0
  102. package/package.json +86 -0
@@ -0,0 +1,290 @@
1
+ import { getAddress } from "viem";
2
+ import { decodePayment as decodeX402Payment } from "x402/schemes";
3
+ import { findMatchingPaymentRequirements, processPriceToAtomicAmount } from "x402/shared";
4
+ import { useFacilitator } from "x402/verify";
5
+ import { isHederaNetwork, hederaPriceToAtomicAmount } from "../../shared/hedera-price.js";
6
+ import { HCSAuditHook } from "../../proxy/hooks/hcs-audit-hook.js";
7
+ /** Use local Hedera conversion for Hedera networks, x402 for others */
8
+ function safeProcessPrice(price, network) {
9
+ if (isHederaNetwork(network))
10
+ return hederaPriceToAtomicAmount(price, network);
11
+ return processPriceToAtomicAmount(price, network);
12
+ }
13
+ // Hedera networks supported by ClawPay
14
+ const HEDERA_EVM_NETWORKS = [
15
+ 'hedera-testnet',
16
+ 'hedera',
17
+ ];
18
+ export function withX402(server, cfg) {
19
+ const { verify, settle } = useFacilitator(cfg.facilitator);
20
+ const x402Version = cfg.version ?? 1;
21
+ // HCS audit hook — lazily initialized on first payment if config provided
22
+ const hcsHook = cfg.hcsAudit ? new HCSAuditHook(cfg.hcsAudit) : null;
23
+ // Normalize recipients — Hedera-only
24
+ const normalizeRecipients = (r) => {
25
+ if (!r || typeof r !== "object")
26
+ return {};
27
+ const out = {};
28
+ const isTestnetNetwork = (network) => network.includes("testnet");
29
+ // Expand evm shorthand to Hedera networks
30
+ const maybeFamily = r;
31
+ if (maybeFamily.evm && typeof maybeFamily.evm.address === "string") {
32
+ const useTestnet = maybeFamily.evm.isTestnet;
33
+ for (const net of HEDERA_EVM_NETWORKS) {
34
+ if (useTestnet === undefined || isTestnetNetwork(net) === !!useTestnet) {
35
+ out[net] = maybeFamily.evm.address;
36
+ }
37
+ }
38
+ }
39
+ // Copy explicit per-network mappings
40
+ for (const [key, value] of Object.entries(r)) {
41
+ if (typeof value === "string" && HEDERA_EVM_NETWORKS.includes(key)) {
42
+ out[key] = value;
43
+ }
44
+ }
45
+ return out;
46
+ };
47
+ function paidTool(name, description, price, paramsSchema, annotations, cb) {
48
+ const recipientsByNetwork = normalizeRecipients(cfg.recipient);
49
+ const paymentNetworks = [];
50
+ const networks = Object.keys(recipientsByNetwork);
51
+ for (const network of networks) {
52
+ const payTo = recipientsByNetwork[network];
53
+ if (!network || !payTo)
54
+ continue;
55
+ const atomic = safeProcessPrice(price, network);
56
+ if ("error" in atomic)
57
+ continue;
58
+ const { maxAmountRequired, asset } = atomic;
59
+ paymentNetworks.push({
60
+ network,
61
+ recipient: payTo,
62
+ maxAmountRequired: maxAmountRequired.toString(),
63
+ asset: {
64
+ address: asset.address,
65
+ symbol: 'symbol' in asset ? asset.symbol : undefined,
66
+ decimals: 'decimals' in asset ? asset.decimals : undefined
67
+ },
68
+ type: 'hedera'
69
+ });
70
+ }
71
+ return server.tool(name, description, paramsSchema, {
72
+ ...annotations,
73
+ paymentHint: true,
74
+ paymentPriceUSD: price,
75
+ paymentNetworks,
76
+ paymentVersion: x402Version,
77
+ ...(hcsHook?.getTopicId() ? { hcsTopic: hcsHook.getTopicId() } : {}),
78
+ }, (async (args, extra) => {
79
+ const recipientsByNetwork = normalizeRecipients(cfg.recipient);
80
+ const buildRequirements = async () => {
81
+ const reqs = [];
82
+ const networks = Object.keys(recipientsByNetwork);
83
+ for (const network of networks) {
84
+ const payTo = recipientsByNetwork[network];
85
+ if (!network || !payTo)
86
+ continue;
87
+ const atomic = safeProcessPrice(price, network);
88
+ if ("error" in atomic)
89
+ continue;
90
+ const { maxAmountRequired, asset } = atomic;
91
+ const extra = ("eip712" in asset ? asset.eip712 : undefined);
92
+ const normalizedPayTo = getAddress(String(payTo));
93
+ const normalizedAsset = getAddress(String(asset.address));
94
+ reqs.push({
95
+ scheme: "exact",
96
+ network,
97
+ maxAmountRequired,
98
+ payTo: normalizedPayTo,
99
+ asset: normalizedAsset,
100
+ maxTimeoutSeconds: 300,
101
+ resource: `mcp://${name}`,
102
+ mimeType: "application/json",
103
+ description,
104
+ extra,
105
+ });
106
+ }
107
+ return reqs;
108
+ };
109
+ const accepts = await buildRequirements();
110
+ if (!accepts.length) {
111
+ const payload = { x402Version, error: "PRICE_COMPUTE_FAILED" };
112
+ return {
113
+ isError: true,
114
+ _meta: { "x402/error": payload },
115
+ content: [{ type: "text", text: JSON.stringify(payload) }],
116
+ };
117
+ }
118
+ // Get token from MCP _meta or header
119
+ const requestInfoUnknown = extra.requestInfo;
120
+ const headersUnknown = requestInfoUnknown && requestInfoUnknown.headers;
121
+ const headerToken = (() => {
122
+ if (!headersUnknown)
123
+ return undefined;
124
+ if (typeof headersUnknown.get === "function") {
125
+ return headersUnknown.get("X-PAYMENT") ?? undefined;
126
+ }
127
+ if (typeof headersUnknown === "object" && headersUnknown !== null) {
128
+ const rec = headersUnknown;
129
+ const direct = rec["X-PAYMENT"] ?? rec["x-payment"];
130
+ return typeof direct === "string" ? direct : undefined;
131
+ }
132
+ return undefined;
133
+ })();
134
+ const metaToken = (extra?._meta && extra._meta["x402/payment"]);
135
+ const token = metaToken ?? headerToken;
136
+ const paymentRequired = (reason = "PAYMENT_REQUIRED", extraFields = {}) => {
137
+ const payload = { x402Version, error: reason, accepts, ...extraFields };
138
+ return {
139
+ isError: true,
140
+ _meta: { "x402/error": payload },
141
+ content: [{ type: "text", text: JSON.stringify(payload) }],
142
+ };
143
+ };
144
+ if (!token || typeof token !== "string")
145
+ return paymentRequired();
146
+ // Check if this is a Hedera payment by checking if any accept is Hedera
147
+ const hasHederaAccepts = accepts.some(a => isHederaNetwork(a.network));
148
+ // For Hedera: bypass x402 npm decode (it doesn't support Hedera networks)
149
+ // and call Blocky402 directly with the raw paymentHeader
150
+ if (hasHederaAccepts) {
151
+ // Pick the first Hedera requirement
152
+ const selected = accepts.find(a => isHederaNetwork(a.network));
153
+ if (!selected)
154
+ return paymentRequired("UNABLE_TO_MATCH_PAYMENT_REQUIREMENTS");
155
+ const facilitatorUrl = cfg.facilitator?.url || "https://api.testnet.blocky402.com";
156
+ // Verify directly with Blocky402 (it expects paymentHeader, not paymentPayload)
157
+ const vr = await fetch(`${facilitatorUrl}/verify`, {
158
+ method: 'POST',
159
+ headers: { 'Content-Type': 'application/json' },
160
+ body: JSON.stringify({
161
+ x402Version,
162
+ paymentHeader: token,
163
+ paymentRequirements: selected,
164
+ }),
165
+ });
166
+ if (vr.status !== 200)
167
+ return paymentRequired("INVALID_PAYMENT");
168
+ const verifyResult = await vr.json();
169
+ if (!verifyResult.isValid) {
170
+ return paymentRequired(verifyResult.invalidReason ?? "INVALID_PAYMENT", { payer: verifyResult.payer });
171
+ }
172
+ // Execute the tool
173
+ let result;
174
+ let failed = false;
175
+ try {
176
+ result = await cb(args, extra);
177
+ if (result && typeof result === "object" && "isError" in result && result.isError) {
178
+ failed = true;
179
+ }
180
+ }
181
+ catch (e) {
182
+ failed = true;
183
+ result = {
184
+ isError: true,
185
+ content: [{ type: "text", text: `Tool execution failed: ${String(e)}` }],
186
+ };
187
+ }
188
+ // Settle directly with Blocky402
189
+ if (!failed) {
190
+ try {
191
+ const sr = await fetch(`${facilitatorUrl}/settle`, {
192
+ method: 'POST',
193
+ headers: { 'Content-Type': 'application/json' },
194
+ body: JSON.stringify({
195
+ x402Version,
196
+ paymentHeader: token,
197
+ paymentRequirements: selected,
198
+ }),
199
+ });
200
+ const settleResult = await sr.json();
201
+ if (settleResult.success) {
202
+ result._meta ??= {};
203
+ result._meta["x402/payment-response"] = {
204
+ success: true,
205
+ transaction: settleResult.transaction,
206
+ network: settleResult.network,
207
+ payer: settleResult.payer,
208
+ };
209
+ // HCS audit logging — await so topic metadata gets into response
210
+ if (hcsHook) {
211
+ await hcsHook.processCallToolResult(result, { method: "tools/call", params: { name, arguments: args } }, {}).catch(() => { });
212
+ }
213
+ }
214
+ else {
215
+ return paymentRequired(settleResult.errorReason ?? "SETTLEMENT_FAILED");
216
+ }
217
+ }
218
+ catch {
219
+ return paymentRequired("SETTLEMENT_FAILED");
220
+ }
221
+ }
222
+ return result;
223
+ }
224
+ // Non-Hedera: use standard x402 npm decode + facilitator
225
+ let decoded;
226
+ try {
227
+ decoded = decodeX402Payment(token);
228
+ decoded.x402Version = x402Version;
229
+ }
230
+ catch {
231
+ return paymentRequired("INVALID_PAYMENT");
232
+ }
233
+ const selected = findMatchingPaymentRequirements(accepts, decoded);
234
+ if (!selected)
235
+ return paymentRequired("UNABLE_TO_MATCH_PAYMENT_REQUIREMENTS");
236
+ const vr = await verify(decoded, selected);
237
+ if (!vr.isValid) {
238
+ return paymentRequired(vr.invalidReason ?? "INVALID_PAYMENT", { payer: vr.payer });
239
+ }
240
+ let result;
241
+ let failed = false;
242
+ try {
243
+ result = await cb(args, extra);
244
+ if (result && typeof result === "object" && "isError" in result && result.isError) {
245
+ failed = true;
246
+ }
247
+ }
248
+ catch (e) {
249
+ failed = true;
250
+ result = {
251
+ isError: true,
252
+ content: [{ type: "text", text: `Tool execution failed: ${String(e)}` }],
253
+ };
254
+ }
255
+ if (!failed) {
256
+ try {
257
+ const s = await settle(decoded, selected);
258
+ if (s.success) {
259
+ result._meta ??= {};
260
+ result._meta["x402/payment-response"] = {
261
+ success: true,
262
+ transaction: s.transaction,
263
+ network: s.network,
264
+ payer: s.payer,
265
+ };
266
+ // HCS audit logging — await so topic metadata gets into response
267
+ if (hcsHook) {
268
+ await hcsHook.processCallToolResult(result, { method: "tools/call", params: { name, arguments: args } }, {}).catch(() => { });
269
+ }
270
+ }
271
+ else {
272
+ return paymentRequired(s.errorReason ?? "SETTLEMENT_FAILED");
273
+ }
274
+ }
275
+ catch {
276
+ return paymentRequired("SETTLEMENT_FAILED");
277
+ }
278
+ }
279
+ return result;
280
+ }));
281
+ }
282
+ Object.defineProperty(server, "paidTool", {
283
+ value: paidTool,
284
+ writable: false,
285
+ enumerable: false,
286
+ configurable: true,
287
+ });
288
+ return server;
289
+ }
290
+ //# sourceMappingURL=with-x402.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-x402.js","sourceRoot":"","sources":["../../../../src/handler/server/plugins/with-x402.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,+BAA+B,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAQ1F,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,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AAO,eAAe,CAAC,CAAC,CAAC,WAAW,IAAI,mBAAmB,CAAC,CAAC;oBAC/D,CAAC;gBACH,CAAC;gBAAC,MAAM,CAAC;oBACP,OAAO,eAAe,CAAC,mBAAmB,CAAC,CAAC;gBAC9C,CAAC;YACH,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,CAAuB,CACzB,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE;QACxC,KAAK,EAAE,QAAQ;QACf,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;IAEH,OAAO,MAAiC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import createMcpHandlerWithPlugins, { type ServerOptions as BaseServerOptions } from "../index.js";
3
+ import type { X402AugmentedServer, X402Config } from "../plugins/with-x402.js";
4
+ type HandlerConfig = Parameters<typeof createMcpHandlerWithPlugins>[2];
5
+ export type PaidServerOptions = Omit<BaseServerOptions, "plugins">;
6
+ export type PaidServerInitialize = (server: McpServer & X402AugmentedServer) => Promise<void> | void;
7
+ /**
8
+ * createPaidServer
9
+ * Creates a Request handler for an MCP server augmented with X402 paid tools.
10
+ * You provide your server initializer and the X402 configuration; this wires
11
+ * the `withX402` plugin automatically.
12
+ */
13
+ export declare function createMcpPaidHandler(initializeServer: PaidServerInitialize, x402: X402Config, serverOptions?: PaidServerOptions, config?: HandlerConfig): (request: Request) => Promise<Response>;
14
+ export type { X402Config, X402AugmentedServer, RecipientWithTestnet } from "../plugins/with-x402.js";
15
+ export type { HCSAuditConfig } from "../../proxy/hooks/hcs-audit-hook.js";
16
+ //# sourceMappingURL=x402-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402-server.d.ts","sourceRoot":"","sources":["../../../../src/handler/server/templates/x402-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,2BAA2B,EAAE,EAAe,KAAK,aAAa,IAAI,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhH,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE/E,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAAC,CAAC,CAAC,CAAC;AACvE,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;AACnE,MAAM,MAAM,oBAAoB,GAAG,CACjC,MAAM,EAAE,SAAS,GAAG,mBAAmB,KACpC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE1B;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,gBAAgB,EAAE,oBAAoB,EACtC,IAAI,EAAE,UAAU,EAChB,aAAa,CAAC,EAAE,iBAAiB,EACjC,MAAM,CAAC,EAAE,aAAa,GACrB,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAQzC;AAED,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACrG,YAAY,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import createMcpHandlerWithPlugins, { makePlugins } from "../index.js";
2
+ import { withX402 } from "../plugins/with-x402.js";
3
+ /**
4
+ * createPaidServer
5
+ * Creates a Request handler for an MCP server augmented with X402 paid tools.
6
+ * You provide your server initializer and the X402 configuration; this wires
7
+ * the `withX402` plugin automatically.
8
+ */
9
+ export function createMcpPaidHandler(initializeServer, x402, serverOptions, config) {
10
+ const plugins = makePlugins((server) => withX402(server, x402));
11
+ return createMcpHandlerWithPlugins(initializeServer, { ...serverOptions, plugins }, config);
12
+ }
13
+ //# sourceMappingURL=x402-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402-server.js","sourceRoot":"","sources":["../../../../src/handler/server/templates/x402-server.ts"],"names":[],"mappings":"AACA,OAAO,2BAA2B,EAAE,EAAE,WAAW,EAA2C,MAAM,aAAa,CAAC;AAChH,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AASnD;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,gBAAsC,EACtC,IAAgB,EAChB,aAAiC,EACjC,MAAsB;IAEtB,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,MAAiB,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAE3E,OAAO,2BAA2B,CAChC,gBAAwE,EACxE,EAAE,GAAI,aAAwB,EAAE,OAAO,EAAuC,EAC9E,MAAM,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Local Hedera price-to-atomic-amount conversion.
3
+ *
4
+ * The x402 npm package's `processPriceToAtomicAmount` doesn't support Hedera networks,
5
+ * so we handle it locally using our own Hedera network config.
6
+ */
7
+ import type { Price, Network } from "x402/types";
8
+ import { type HederaNetworkName } from "../../networks/hedera.js";
9
+ export declare function isHederaNetwork(network: Network | string): network is HederaNetworkName;
10
+ /**
11
+ * Convert a USD price string (e.g. "$0.01") to atomic USDC units for Hedera.
12
+ * USDC has 6 decimals, so $0.01 = 10000 atomic units.
13
+ *
14
+ * Returns the same shape as x402's `processPriceToAtomicAmount`.
15
+ */
16
+ export declare function hederaPriceToAtomicAmount(price: Price, network: HederaNetworkName): {
17
+ maxAmountRequired: string;
18
+ asset: {
19
+ address: `0x${string}`;
20
+ decimals: number;
21
+ symbol: string;
22
+ };
23
+ } | {
24
+ error: string;
25
+ };
26
+ //# sourceMappingURL=hedera-price.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hedera-price.d.ts","sourceRoot":"","sources":["../../../src/handler/shared/hedera-price.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAmB,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAYnF,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,IAAI,iBAAiB,CAEvF;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,iBAAiB,GACzB;IAAE,iBAAiB,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE;QAAE,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CA8BxH"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Local Hedera price-to-atomic-amount conversion.
3
+ *
4
+ * The x402 npm package's `processPriceToAtomicAmount` doesn't support Hedera networks,
5
+ * so we handle it locally using our own Hedera network config.
6
+ */
7
+ import { HEDERA_NETWORKS } from "../../networks/hedera.js";
8
+ // Hedera USDC EVM addresses (derived from token entity IDs)
9
+ // Token 0.0.5449 (testnet) -> entity 5449 -> 0x1549 padded
10
+ // Token 0.0.456858 (mainnet) -> entity 456858 -> 0x6f89a padded
11
+ const HEDERA_USDC_EVM = {
12
+ 'hedera-testnet': '0x0000000000000000000000000000000000001549',
13
+ 'hedera': '0x000000000000000000000000000000000006f89a',
14
+ };
15
+ const HEDERA_NETWORK_NAMES = ['hedera-testnet', 'hedera'];
16
+ export function isHederaNetwork(network) {
17
+ return HEDERA_NETWORK_NAMES.includes(network);
18
+ }
19
+ /**
20
+ * Convert a USD price string (e.g. "$0.01") to atomic USDC units for Hedera.
21
+ * USDC has 6 decimals, so $0.01 = 10000 atomic units.
22
+ *
23
+ * Returns the same shape as x402's `processPriceToAtomicAmount`.
24
+ */
25
+ export function hederaPriceToAtomicAmount(price, network) {
26
+ const config = HEDERA_NETWORKS[network];
27
+ if (!config) {
28
+ return { error: `Unsupported Hedera network: ${network}` };
29
+ }
30
+ // Parse price — supports "$0.01", "0.01", etc.
31
+ let amount;
32
+ try {
33
+ const cleaned = String(price).replace(/^\$/, '').trim();
34
+ amount = parseFloat(cleaned);
35
+ if (isNaN(amount) || amount < 0) {
36
+ return { error: `Invalid price: ${price}` };
37
+ }
38
+ }
39
+ catch {
40
+ return { error: `Failed to parse price: ${price}` };
41
+ }
42
+ const decimals = config.usdc.decimals; // 6
43
+ const atomicAmount = BigInt(Math.round(amount * 10 ** decimals));
44
+ const evmAddress = HEDERA_USDC_EVM[network];
45
+ return {
46
+ maxAmountRequired: atomicAmount.toString(),
47
+ asset: {
48
+ address: evmAddress,
49
+ decimals,
50
+ symbol: config.usdc.symbol,
51
+ },
52
+ };
53
+ }
54
+ //# sourceMappingURL=hedera-price.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hedera-price.js","sourceRoot":"","sources":["../../../src/handler/shared/hedera-price.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,eAAe,EAA0B,MAAM,0BAA0B,CAAC;AAEnF,4DAA4D;AAC5D,2DAA2D;AAC3D,gEAAgE;AAChE,MAAM,eAAe,GAA6C;IAChE,gBAAgB,EAAE,4CAA4C;IAC9D,QAAQ,EAAE,4CAA4C;CACvD,CAAC;AAEF,MAAM,oBAAoB,GAAa,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;AAEpE,MAAM,UAAU,eAAe,CAAC,OAAyB;IACvD,OAAO,oBAAoB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACvC,KAAY,EACZ,OAA0B;IAE1B,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,EAAE,KAAK,EAAE,+BAA+B,OAAO,EAAE,EAAE,CAAC;IAC7D,CAAC;IAED,+CAA+C;IAC/C,IAAI,MAAc,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACxD,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,OAAO,EAAE,KAAK,EAAE,kBAAkB,KAAK,EAAE,EAAE,CAAC;QAC9C,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,KAAK,EAAE,0BAA0B,KAAK,EAAE,EAAE,CAAC;IACtD,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI;IAC3C,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,EAAE,IAAI,QAAQ,CAAC,CAAC,CAAC;IACjE,MAAM,UAAU,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IAE5C,OAAO;QACL,iBAAiB,EAAE,YAAY,CAAC,QAAQ,EAAE;QAC1C,KAAK,EAAE;YACL,OAAO,EAAE,UAAU;YACnB,QAAQ;YACR,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM;SAC3B;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ import createMcpHandler from "./handler/server/index.js";
2
+ export { createMcpPaidHandler } from "./handler/server/templates/x402-server.js";
3
+ export { withX402 } from "./handler/server/plugins/with-x402.js";
4
+ export { makePlugins, composePlugins } from "./handler/server/index.js";
5
+ export { createMcpHandler };
6
+ export { withProxy } from "./handler/proxy/index.js";
7
+ export { Hook } from "./handler/proxy/hooks.js";
8
+ export { LoggingHook } from "./handler/proxy/hooks/logging-hook.js";
9
+ export { AuthHeadersHook } from "./handler/proxy/hooks/auth-headers-hook.js";
10
+ export { X402MonetizationHook } from "./handler/proxy/hooks/x402-hook.js";
11
+ export { AnalyticsHook } from "./handler/proxy/hooks/analytics-hook.js";
12
+ export { HCSAuditHook } from "./handler/proxy/hooks/hcs-audit-hook.js";
13
+ export type { RequestExtra, ToolCallRequestHookResult, ToolCallResponseHookResult, } from "./handler/proxy/hooks.js";
14
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,YAAY,EACR,YAAY,EACZ,yBAAyB,EACzB,0BAA0B,GAC7B,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,12 @@
1
+ import createMcpHandler from "./handler/server/index.js";
2
+ export { createMcpPaidHandler } from "./handler/server/templates/x402-server.js";
3
+ export { withX402 } from "./handler/server/plugins/with-x402.js";
4
+ export { makePlugins, composePlugins } from "./handler/server/index.js";
5
+ export { createMcpHandler };
6
+ export { withProxy } from "./handler/proxy/index.js";
7
+ export { LoggingHook } from "./handler/proxy/hooks/logging-hook.js";
8
+ export { AuthHeadersHook } from "./handler/proxy/hooks/auth-headers-hook.js";
9
+ export { X402MonetizationHook } from "./handler/proxy/hooks/x402-hook.js";
10
+ export { AnalyticsHook } from "./handler/proxy/hooks/analytics-hook.js";
11
+ export { HCSAuditHook } from "./handler/proxy/hooks/hcs-audit-hook.js";
12
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { startStdioServer, createServerConnections, ServerType, type ServerConnection } from './server/stdio/start-stdio-server.js';
2
+ export { proxyServer } from './server/stdio/proxy-server.js';
3
+ export { HEDERA_NETWORKS, SUPPORTED_HEDERA_NETWORKS, DEFAULT_HEDERA_NETWORK, HEDERA_FACILITATOR_URL, getHashScanUrl, getHCSTopicUrl, type HederaNetworkName, } from './networks/hedera.js';
4
+ export type { Account } from 'viem';
5
+ export type { Client } from '@modelcontextprotocol/sdk/client/index.js';
6
+ export type { Server } from '@modelcontextprotocol/sdk/server/index.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,gBAAgB,EAChB,uBAAuB,EACvB,UAAU,EACV,KAAK,gBAAgB,EACxB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAG7D,OAAO,EACH,eAAe,EACf,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,EACtB,cAAc,EACd,cAAc,EACd,KAAK,iBAAiB,GACzB,MAAM,sBAAsB,CAAC;AAG9B,YAAY,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,YAAY,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACxE,YAAY,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { startStdioServer, createServerConnections, ServerType } from './server/stdio/start-stdio-server.js';
2
+ export { proxyServer } from './server/stdio/proxy-server.js';
3
+ // Hedera network configuration
4
+ export { HEDERA_NETWORKS, SUPPORTED_HEDERA_NETWORKS, DEFAULT_HEDERA_NETWORK, HEDERA_FACILITATOR_URL, getHashScanUrl, getHCSTopicUrl, } from './networks/hedera.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,gBAAgB,EAChB,uBAAuB,EACvB,UAAU,EAEb,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE7D,+BAA+B;AAC/B,OAAO,EACH,eAAe,EACf,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,EACtB,cAAc,EACd,cAAc,GAEjB,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Hedera network configuration for ClawPay
3
+ * Supports HTS USDC and native HBAR payments via x402
4
+ */
5
+ export declare const HEDERA_NETWORKS: {
6
+ readonly 'hedera-testnet': {
7
+ readonly name: "Hedera Testnet";
8
+ readonly chainId: 296;
9
+ readonly rpcUrl: "https://testnet.hashio.io/api";
10
+ readonly mirrorNodeUrl: "https://testnet.mirrornode.hedera.com";
11
+ readonly usdc: {
12
+ readonly tokenId: "0.0.5449";
13
+ readonly decimals: 6;
14
+ readonly symbol: "USDC";
15
+ };
16
+ readonly hbar: {
17
+ readonly decimals: 8;
18
+ readonly symbol: "HBAR";
19
+ };
20
+ readonly isTestnet: true;
21
+ };
22
+ readonly hedera: {
23
+ readonly name: "Hedera Mainnet";
24
+ readonly chainId: 295;
25
+ readonly rpcUrl: "https://mainnet.hashio.io/api";
26
+ readonly mirrorNodeUrl: "https://mainnet.mirrornode.hedera.com";
27
+ readonly usdc: {
28
+ readonly tokenId: "0.0.456858";
29
+ readonly decimals: 6;
30
+ readonly symbol: "USDC";
31
+ };
32
+ readonly hbar: {
33
+ readonly decimals: 8;
34
+ readonly symbol: "HBAR";
35
+ };
36
+ readonly isTestnet: false;
37
+ };
38
+ };
39
+ export type HederaNetworkName = keyof typeof HEDERA_NETWORKS;
40
+ export declare const SUPPORTED_HEDERA_NETWORKS: HederaNetworkName[];
41
+ export declare const DEFAULT_HEDERA_NETWORK: HederaNetworkName;
42
+ /** Facilitator endpoint for Hedera x402 payments */
43
+ export declare const HEDERA_FACILITATOR_URL = "https://api.testnet.blocky402.com";
44
+ /**
45
+ * Get the HashScan explorer URL for a transaction
46
+ */
47
+ export declare function getHashScanUrl(txId: string, network?: HederaNetworkName): string;
48
+ /**
49
+ * Get the HashScan explorer URL for an HCS topic
50
+ */
51
+ export declare function getHCSTopicUrl(topicId: string, network?: HederaNetworkName): string;
52
+ //# sourceMappingURL=hedera.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hedera.d.ts","sourceRoot":"","sources":["../../src/networks/hedera.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiClB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,eAAe,CAAC;AAE7D,eAAO,MAAM,yBAAyB,EAAE,iBAAiB,EAAiC,CAAC;AAE3F,eAAO,MAAM,sBAAsB,EAAE,iBAAoC,CAAC;AAE1E,oDAAoD;AACpD,eAAO,MAAM,sBAAsB,sCAAsC,CAAC;AAE1E;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAoC,GAAG,MAAM,CAKlG;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAoC,GAAG,MAAM,CAKrG"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Hedera network configuration for ClawPay
3
+ * Supports HTS USDC and native HBAR payments via x402
4
+ */
5
+ export const HEDERA_NETWORKS = {
6
+ 'hedera-testnet': {
7
+ name: 'Hedera Testnet',
8
+ chainId: 296,
9
+ rpcUrl: 'https://testnet.hashio.io/api',
10
+ mirrorNodeUrl: 'https://testnet.mirrornode.hedera.com',
11
+ usdc: {
12
+ tokenId: '0.0.5449',
13
+ decimals: 6,
14
+ symbol: 'USDC',
15
+ },
16
+ hbar: {
17
+ decimals: 8,
18
+ symbol: 'HBAR',
19
+ },
20
+ isTestnet: true,
21
+ },
22
+ 'hedera': {
23
+ name: 'Hedera Mainnet',
24
+ chainId: 295,
25
+ rpcUrl: 'https://mainnet.hashio.io/api',
26
+ mirrorNodeUrl: 'https://mainnet.mirrornode.hedera.com',
27
+ usdc: {
28
+ tokenId: '0.0.456858',
29
+ decimals: 6,
30
+ symbol: 'USDC',
31
+ },
32
+ hbar: {
33
+ decimals: 8,
34
+ symbol: 'HBAR',
35
+ },
36
+ isTestnet: false,
37
+ },
38
+ };
39
+ export const SUPPORTED_HEDERA_NETWORKS = ['hedera-testnet', 'hedera'];
40
+ export const DEFAULT_HEDERA_NETWORK = 'hedera-testnet';
41
+ /** Facilitator endpoint for Hedera x402 payments */
42
+ export const HEDERA_FACILITATOR_URL = 'https://api.testnet.blocky402.com';
43
+ /**
44
+ * Get the HashScan explorer URL for a transaction
45
+ */
46
+ export function getHashScanUrl(txId, network = 'hedera-testnet') {
47
+ const base = network === 'hedera'
48
+ ? 'https://hashscan.io/mainnet'
49
+ : 'https://hashscan.io/testnet';
50
+ return `${base}/transaction/${txId}`;
51
+ }
52
+ /**
53
+ * Get the HashScan explorer URL for an HCS topic
54
+ */
55
+ export function getHCSTopicUrl(topicId, network = 'hedera-testnet') {
56
+ const base = network === 'hedera'
57
+ ? 'https://hashscan.io/mainnet'
58
+ : 'https://hashscan.io/testnet';
59
+ return `${base}/topic/${topicId}`;
60
+ }
61
+ //# sourceMappingURL=hedera.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hedera.js","sourceRoot":"","sources":["../../src/networks/hedera.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,gBAAgB,EAAE;QAChB,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,GAAG;QACZ,MAAM,EAAE,+BAA+B;QACvC,aAAa,EAAE,uCAAuC;QACtD,IAAI,EAAE;YACJ,OAAO,EAAE,UAAU;YACnB,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,MAAM;SACf;QACD,IAAI,EAAE;YACJ,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,MAAM;SACf;QACD,SAAS,EAAE,IAAI;KAChB;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,GAAG;QACZ,MAAM,EAAE,+BAA+B;QACvC,aAAa,EAAE,uCAAuC;QACtD,IAAI,EAAE;YACJ,OAAO,EAAE,YAAY;YACrB,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,MAAM;SACf;QACD,IAAI,EAAE;YACJ,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,MAAM;SACf;QACD,SAAS,EAAE,KAAK;KACjB;CACO,CAAC;AAIX,MAAM,CAAC,MAAM,yBAAyB,GAAwB,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;AAE3F,MAAM,CAAC,MAAM,sBAAsB,GAAsB,gBAAgB,CAAC;AAE1E,oDAAoD;AACpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,mCAAmC,CAAC;AAE1E;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,UAA6B,gBAAgB;IACxF,MAAM,IAAI,GAAG,OAAO,KAAK,QAAQ;QAC/B,CAAC,CAAC,6BAA6B;QAC/B,CAAC,CAAC,6BAA6B,CAAC;IAClC,OAAO,GAAG,IAAI,gBAAgB,IAAI,EAAE,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,UAA6B,gBAAgB;IAC3F,MAAM,IAAI,GAAG,OAAO,KAAK,QAAQ;QAC/B,CAAC,CAAC,6BAA6B;QAC/B,CAAC,CAAC,6BAA6B,CAAC;IAClC,OAAO,GAAG,IAAI,UAAU,OAAO,EAAE,CAAC;AACpC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/stdio/index.ts"],"names":[],"mappings":""}