@suigar/mcp 0.1.0 → 0.2.0-beta.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 (77) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +201 -0
  3. package/README.md +79 -110
  4. package/dist/app/index.html +181 -0
  5. package/dist/bin.mjs +3 -7
  6. package/dist/bin.mjs.map +1 -0
  7. package/dist/client.d.mts +41 -11
  8. package/dist/client.d.mts.map +1 -0
  9. package/dist/client.mjs +107 -34
  10. package/dist/client.mjs.map +1 -0
  11. package/dist/dry-run.mjs +163 -0
  12. package/dist/dry-run.mjs.map +1 -0
  13. package/dist/format.mjs +24 -0
  14. package/dist/format.mjs.map +1 -0
  15. package/dist/index.d.mts +5 -9
  16. package/dist/index.mjs +4 -8
  17. package/dist/schemas.d.mts +642 -0
  18. package/dist/schemas.d.mts.map +1 -0
  19. package/dist/schemas.mjs +113 -0
  20. package/dist/schemas.mjs.map +1 -0
  21. package/dist/server.d.mts +21 -69
  22. package/dist/server.d.mts.map +1 -0
  23. package/dist/server.mjs +172 -411
  24. package/dist/server.mjs.map +1 -0
  25. package/dist/tools.d.mts +14 -155
  26. package/dist/tools.d.mts.map +1 -0
  27. package/dist/tools.mjs +297 -553
  28. package/dist/tools.mjs.map +1 -0
  29. package/dist/types.d.mts +109 -83
  30. package/dist/types.d.mts.map +1 -0
  31. package/package.json +83 -61
  32. package/dist/bin.cjs +0 -11
  33. package/dist/bin.d.cts +0 -1
  34. package/dist/client.cjs +0 -46
  35. package/dist/client.d.cts +0 -17
  36. package/dist/coin.cjs +0 -86
  37. package/dist/coin.d.cts +0 -35
  38. package/dist/coin.d.mts +0 -35
  39. package/dist/coin.mjs +0 -86
  40. package/dist/config.cjs +0 -183
  41. package/dist/config.d.cts +0 -15
  42. package/dist/config.d.mts +0 -15
  43. package/dist/config.mjs +0 -174
  44. package/dist/index.cjs +0 -53
  45. package/dist/index.d.cts +0 -10
  46. package/dist/mcp-support.cjs +0 -62
  47. package/dist/mcp-support.d.cts +0 -16
  48. package/dist/mcp-support.d.mts +0 -16
  49. package/dist/mcp-support.mjs +0 -60
  50. package/dist/metadata.cjs +0 -51
  51. package/dist/metadata.d.cts +0 -52
  52. package/dist/metadata.d.mts +0 -52
  53. package/dist/metadata.mjs +0 -47
  54. package/dist/server.cjs +0 -433
  55. package/dist/server.d.cts +0 -73
  56. package/dist/tools.cjs +0 -617
  57. package/dist/tools.d.cts +0 -158
  58. package/dist/transactions.cjs +0 -294
  59. package/dist/transactions.d.cts +0 -40
  60. package/dist/transactions.d.mts +0 -40
  61. package/dist/transactions.mjs +0 -286
  62. package/dist/types.d.cts +0 -111
  63. package/node_modules/@suigar/currency-registry/dist/index.cjs +0 -121
  64. package/node_modules/@suigar/currency-registry/dist/index.d.cts +0 -50
  65. package/node_modules/@suigar/currency-registry/dist/index.d.mts +0 -50
  66. package/node_modules/@suigar/currency-registry/dist/index.mjs +0 -110
  67. package/node_modules/@suigar/currency-registry/package.json +0 -31
  68. package/node_modules/@suigar/game-registry/dist/index.cjs +0 -310
  69. package/node_modules/@suigar/game-registry/dist/index.d.cts +0 -65
  70. package/node_modules/@suigar/game-registry/dist/index.d.mts +0 -65
  71. package/node_modules/@suigar/game-registry/dist/index.mjs +0 -292
  72. package/node_modules/@suigar/game-registry/package.json +0 -31
  73. package/node_modules/@suigar/sui-rpc-pool/dist/index.cjs +0 -45590
  74. package/node_modules/@suigar/sui-rpc-pool/dist/index.d.cts +0 -465
  75. package/node_modules/@suigar/sui-rpc-pool/dist/index.d.mts +0 -465
  76. package/node_modules/@suigar/sui-rpc-pool/dist/index.mjs +0 -45570
  77. package/node_modules/@suigar/sui-rpc-pool/package.json +0 -31
package/dist/server.mjs CHANGED
@@ -1,431 +1,192 @@
1
+ import { coinflipInputSchema, configIdInputSchema, limboInputSchema, pvpCoinflipCancelInputSchema, pvpCoinflipCreateInputSchema, pvpCoinflipJoinInputSchema, rangeInputSchema, readConfigInputSchema, readGameMetadataInputSchema, toolOutputSchema } from "./schemas.mjs";
1
2
  import { buildCoinflipTransactionTool, buildLimboTransactionTool, buildPlinkoTransactionTool, buildPvpCoinflipCancelTransactionTool, buildPvpCoinflipCreateTransactionTool, buildPvpCoinflipJoinTransactionTool, buildRangeTransactionTool, buildWheelTransactionTool, readConfigTool, readGameMetadataTool } from "./tools.mjs";
2
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { readFileSync } from "node:fs";
4
+ import { readFile } from "node:fs/promises";
5
+ import { RESOURCE_MIME_TYPE, registerAppResource, registerAppTool } from "@modelcontextprotocol/ext-apps/server";
6
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
7
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
- import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
5
8
  //#region src/server.ts
6
- const json = (value) => JSON.stringify(value, null, 2);
7
- const TOOL_DEFINITIONS = [
8
- {
9
- name: "read_config",
10
- description: "Resolve Suigar config for the target network, defaulting to testnet.",
11
- inputSchema: {
12
- type: "object",
13
- properties: {
14
- network: {
15
- type: "string",
16
- default: "testnet"
17
- },
18
- providerUrl: { type: "string" },
19
- graphqlUrl: { type: "string" },
20
- config: {
21
- type: "object",
22
- additionalProperties: true
23
- }
24
- },
25
- additionalProperties: true
26
- },
27
- handler: readConfigTool
28
- },
29
- {
30
- name: "read_game_metadata",
31
- description: "Read Suigar game metadata, on-chain settings metadata, and optional currency metadata.",
32
- inputSchema: {
33
- type: "object",
34
- properties: {
35
- game: { type: "string" },
36
- coinType: { type: "string" },
37
- network: {
38
- type: "string",
39
- default: "testnet"
40
- },
41
- config: {
42
- type: "object",
43
- additionalProperties: true
44
- }
45
- },
46
- additionalProperties: true
9
+ const SUIGAR_MCP_APP_RESOURCE_URI = "ui://suigar/transaction-inspector.html";
10
+ const packageJson = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
11
+ const errorText = (error) => {
12
+ if (error instanceof Error) return `${error.name}: ${error.message}`;
13
+ return String(error);
14
+ };
15
+ const hasErrorCode = (error, code) => error instanceof Error && "code" in error && error.code === code;
16
+ const withToolErrors = (handler) => async (input) => {
17
+ try {
18
+ return await handler(input);
19
+ } catch (error) {
20
+ return {
21
+ isError: true,
22
+ content: [{
23
+ type: "text",
24
+ text: `${errorText(error)}\n\nCheck required fields, network, coin type, and SDK config overrides. The MCP server only builds unsigned transactions and never signs or executes them.`
25
+ }]
26
+ };
27
+ }
28
+ };
29
+ const readSuigarMcpAppHtml = async () => {
30
+ try {
31
+ return await readFile(new URL("./app/index.html", import.meta.url), "utf8");
32
+ } catch (error) {
33
+ if (!hasErrorCode(error, "ENOENT")) throw error;
34
+ throw new Error("Unable to find bundled Suigar MCP App HTML.", { cause: error });
35
+ }
36
+ };
37
+ const createSuigarMcpAppResourceResult = async () => ({ contents: [{
38
+ uri: SUIGAR_MCP_APP_RESOURCE_URI,
39
+ mimeType: RESOURCE_MIME_TYPE,
40
+ text: await readSuigarMcpAppHtml(),
41
+ _meta: { ui: { csp: {
42
+ connectDomains: [],
43
+ resourceDomains: []
44
+ } } }
45
+ }] });
46
+ const createSuigarMcpServer = () => {
47
+ const server = new McpServer({
48
+ name: "suigar",
49
+ version: packageJson.version
50
+ });
51
+ server.registerTool("read_config", {
52
+ title: "Read Suigar Config",
53
+ description: "Resolve Suigar SDK config for mainnet or testnet. Defaults to testnet.",
54
+ inputSchema: readConfigInputSchema,
55
+ outputSchema: toolOutputSchema,
56
+ annotations: {
57
+ readOnlyHint: true,
58
+ destructiveHint: false,
59
+ idempotentHint: true,
60
+ openWorldHint: false
61
+ }
62
+ }, withToolErrors(readConfigTool));
63
+ registerAppResource(server, "Suigar Transaction Inspector", SUIGAR_MCP_APP_RESOURCE_URI, { description: "Compact MCP App UI for inspecting Suigar config, transaction plans, summaries, dry-runs, and serialized bytes." }, createSuigarMcpAppResourceResult);
64
+ const appToolMeta = { ui: { resourceUri: SUIGAR_MCP_APP_RESOURCE_URI } };
65
+ registerAppTool(server, "read_game_metadata", {
66
+ title: "Read Suigar Game Metadata",
67
+ description: "Read SDK-backed metadata for a supported Suigar game and coin type.",
68
+ inputSchema: readGameMetadataInputSchema,
69
+ outputSchema: toolOutputSchema,
70
+ annotations: {
71
+ readOnlyHint: true,
72
+ destructiveHint: false,
73
+ idempotentHint: true,
74
+ openWorldHint: false
47
75
  },
48
- handler: readGameMetadataTool
49
- },
50
- {
51
- name: "build_coinflip_transaction",
52
- description: "Build, dry-run, or inspect a Suigar coinflip transaction on testnet by default.",
53
- inputSchema: {
54
- type: "object",
55
- properties: {
56
- mode: {
57
- type: "string",
58
- enum: [
59
- "build",
60
- "dry-run",
61
- "read-only"
62
- ],
63
- default: "build"
64
- },
65
- network: {
66
- type: "string",
67
- default: "testnet"
68
- },
69
- owner: { type: "string" },
70
- coinType: { type: "string" },
71
- stake: { type: "number" },
72
- cashStake: { type: "number" },
73
- betCount: { type: "number" },
74
- side: {
75
- type: "string",
76
- enum: ["heads", "tails"]
77
- },
78
- coinObjectIds: {
79
- type: "array",
80
- items: { type: "string" }
81
- },
82
- partner: { type: "string" },
83
- metadata: {
84
- type: "object",
85
- additionalProperties: true
86
- },
87
- config: {
88
- type: "object",
89
- additionalProperties: true
90
- }
91
- },
92
- additionalProperties: true
76
+ _meta: appToolMeta
77
+ }, withToolErrors(readGameMetadataTool));
78
+ registerAppTool(server, "build_coinflip_transaction", {
79
+ title: "Build Coinflip Transaction",
80
+ description: "Build, dry-run, or inspect an unsigned Suigar coinflip transaction.",
81
+ inputSchema: coinflipInputSchema,
82
+ outputSchema: toolOutputSchema,
83
+ annotations: {
84
+ readOnlyHint: false,
85
+ destructiveHint: false,
86
+ idempotentHint: false,
87
+ openWorldHint: true
93
88
  },
94
- handler: buildCoinflipTransactionTool
95
- },
96
- {
97
- name: "build_limbo_transaction",
98
- description: "Build, dry-run, or inspect a Suigar limbo transaction.",
99
- inputSchema: {
100
- type: "object",
101
- properties: {
102
- mode: {
103
- type: "string",
104
- enum: [
105
- "build",
106
- "dry-run",
107
- "read-only"
108
- ],
109
- default: "build"
110
- },
111
- network: {
112
- type: "string",
113
- default: "testnet"
114
- },
115
- owner: { type: "string" },
116
- coinType: { type: "string" },
117
- stake: { type: "number" },
118
- cashStake: { type: "number" },
119
- betCount: { type: "number" },
120
- targetMultiplier: { type: "number" },
121
- coinObjectIds: {
122
- type: "array",
123
- items: { type: "string" }
124
- },
125
- partner: { type: "string" },
126
- metadata: {
127
- type: "object",
128
- additionalProperties: true
129
- },
130
- config: {
131
- type: "object",
132
- additionalProperties: true
133
- }
134
- },
135
- additionalProperties: true
89
+ _meta: appToolMeta
90
+ }, withToolErrors(buildCoinflipTransactionTool));
91
+ registerAppTool(server, "build_limbo_transaction", {
92
+ title: "Build Limbo Transaction",
93
+ description: "Build, dry-run, or inspect an unsigned Suigar limbo transaction.",
94
+ inputSchema: limboInputSchema,
95
+ outputSchema: toolOutputSchema,
96
+ annotations: {
97
+ readOnlyHint: false,
98
+ destructiveHint: false,
99
+ idempotentHint: false,
100
+ openWorldHint: true
136
101
  },
137
- handler: buildLimboTransactionTool
138
- },
139
- {
140
- name: "build_plinko_transaction",
141
- description: "Build, dry-run, or inspect a Suigar plinko transaction.",
142
- inputSchema: {
143
- type: "object",
144
- properties: {
145
- mode: {
146
- type: "string",
147
- enum: [
148
- "build",
149
- "dry-run",
150
- "read-only"
151
- ],
152
- default: "build"
153
- },
154
- network: {
155
- type: "string",
156
- default: "testnet"
157
- },
158
- owner: { type: "string" },
159
- coinType: { type: "string" },
160
- stake: { type: "number" },
161
- cashStake: { type: "number" },
162
- betCount: { type: "number" },
163
- configId: { type: "number" },
164
- coinObjectIds: {
165
- type: "array",
166
- items: { type: "string" }
167
- },
168
- partner: { type: "string" },
169
- metadata: {
170
- type: "object",
171
- additionalProperties: true
172
- },
173
- config: {
174
- type: "object",
175
- additionalProperties: true
176
- }
177
- },
178
- additionalProperties: true
102
+ _meta: appToolMeta
103
+ }, withToolErrors(buildLimboTransactionTool));
104
+ registerAppTool(server, "build_plinko_transaction", {
105
+ title: "Build Plinko Transaction",
106
+ description: "Build, dry-run, or inspect an unsigned Suigar plinko transaction.",
107
+ inputSchema: configIdInputSchema,
108
+ outputSchema: toolOutputSchema,
109
+ annotations: {
110
+ readOnlyHint: false,
111
+ destructiveHint: false,
112
+ idempotentHint: false,
113
+ openWorldHint: true
179
114
  },
180
- handler: buildPlinkoTransactionTool
181
- },
182
- {
183
- name: "build_wheel_transaction",
184
- description: "Build, dry-run, or inspect a Suigar wheel transaction.",
185
- inputSchema: {
186
- type: "object",
187
- properties: {
188
- mode: {
189
- type: "string",
190
- enum: [
191
- "build",
192
- "dry-run",
193
- "read-only"
194
- ],
195
- default: "build"
196
- },
197
- network: {
198
- type: "string",
199
- default: "testnet"
200
- },
201
- owner: { type: "string" },
202
- coinType: { type: "string" },
203
- stake: { type: "number" },
204
- cashStake: { type: "number" },
205
- betCount: { type: "number" },
206
- configId: { type: "number" },
207
- coinObjectIds: {
208
- type: "array",
209
- items: { type: "string" }
210
- },
211
- partner: { type: "string" },
212
- metadata: {
213
- type: "object",
214
- additionalProperties: true
215
- },
216
- config: {
217
- type: "object",
218
- additionalProperties: true
219
- }
220
- },
221
- additionalProperties: true
115
+ _meta: appToolMeta
116
+ }, withToolErrors(buildPlinkoTransactionTool));
117
+ registerAppTool(server, "build_wheel_transaction", {
118
+ title: "Build Wheel Transaction",
119
+ description: "Build, dry-run, or inspect an unsigned Suigar wheel transaction.",
120
+ inputSchema: configIdInputSchema,
121
+ outputSchema: toolOutputSchema,
122
+ annotations: {
123
+ readOnlyHint: false,
124
+ destructiveHint: false,
125
+ idempotentHint: false,
126
+ openWorldHint: true
222
127
  },
223
- handler: buildWheelTransactionTool
224
- },
225
- {
226
- name: "build_range_transaction",
227
- description: "Build, dry-run, or inspect a Suigar range transaction.",
228
- inputSchema: {
229
- type: "object",
230
- properties: {
231
- mode: {
232
- type: "string",
233
- enum: [
234
- "build",
235
- "dry-run",
236
- "read-only"
237
- ],
238
- default: "build"
239
- },
240
- network: {
241
- type: "string",
242
- default: "testnet"
243
- },
244
- owner: { type: "string" },
245
- coinType: { type: "string" },
246
- stake: { type: "number" },
247
- cashStake: { type: "number" },
248
- betCount: { type: "number" },
249
- leftPoint: { type: "number" },
250
- rightPoint: { type: "number" },
251
- outOfRange: { type: "boolean" },
252
- coinObjectIds: {
253
- type: "array",
254
- items: { type: "string" }
255
- },
256
- partner: { type: "string" },
257
- metadata: {
258
- type: "object",
259
- additionalProperties: true
260
- },
261
- config: {
262
- type: "object",
263
- additionalProperties: true
264
- }
265
- },
266
- additionalProperties: true
128
+ _meta: appToolMeta
129
+ }, withToolErrors(buildWheelTransactionTool));
130
+ registerAppTool(server, "build_range_transaction", {
131
+ title: "Build Range Transaction",
132
+ description: "Build, dry-run, or inspect an unsigned Suigar range transaction.",
133
+ inputSchema: rangeInputSchema,
134
+ outputSchema: toolOutputSchema,
135
+ annotations: {
136
+ readOnlyHint: false,
137
+ destructiveHint: false,
138
+ idempotentHint: false,
139
+ openWorldHint: true
267
140
  },
268
- handler: buildRangeTransactionTool
269
- },
270
- {
271
- name: "build_pvp_coinflip_create_transaction",
272
- description: "Build, dry-run, or inspect a Suigar PvP coinflip create transaction.",
273
- inputSchema: {
274
- type: "object",
275
- properties: {
276
- mode: {
277
- type: "string",
278
- enum: [
279
- "build",
280
- "dry-run",
281
- "read-only"
282
- ],
283
- default: "build"
284
- },
285
- network: {
286
- type: "string",
287
- default: "testnet"
288
- },
289
- owner: { type: "string" },
290
- coinType: { type: "string" },
291
- stake: { type: "number" },
292
- creatorSide: {
293
- type: "string",
294
- enum: ["heads", "tails"]
295
- },
296
- isPrivate: { type: "boolean" },
297
- coinObjectIds: {
298
- type: "array",
299
- items: { type: "string" }
300
- },
301
- partner: { type: "string" },
302
- metadata: {
303
- type: "object",
304
- additionalProperties: true
305
- },
306
- config: {
307
- type: "object",
308
- additionalProperties: true
309
- }
310
- },
311
- additionalProperties: true
141
+ _meta: appToolMeta
142
+ }, withToolErrors(buildRangeTransactionTool));
143
+ registerAppTool(server, "build_pvp_coinflip_create_transaction", {
144
+ title: "Build PvP Coinflip Create",
145
+ description: "Build, dry-run, or inspect an unsigned Suigar PvP coinflip lobby creation transaction.",
146
+ inputSchema: pvpCoinflipCreateInputSchema,
147
+ outputSchema: toolOutputSchema,
148
+ annotations: {
149
+ readOnlyHint: false,
150
+ destructiveHint: false,
151
+ idempotentHint: false,
152
+ openWorldHint: true
312
153
  },
313
- handler: buildPvpCoinflipCreateTransactionTool
314
- },
315
- {
316
- name: "build_pvp_coinflip_join_transaction",
317
- description: "Build, dry-run, or inspect a Suigar PvP coinflip join transaction.",
318
- inputSchema: {
319
- type: "object",
320
- properties: {
321
- mode: {
322
- type: "string",
323
- enum: [
324
- "build",
325
- "dry-run",
326
- "read-only"
327
- ],
328
- default: "build"
329
- },
330
- network: {
331
- type: "string",
332
- default: "testnet"
333
- },
334
- owner: { type: "string" },
335
- gameId: { type: "string" },
336
- coinType: { type: "string" },
337
- stake: { type: "number" },
338
- coinObjectIds: {
339
- type: "array",
340
- items: { type: "string" }
341
- },
342
- partner: { type: "string" },
343
- metadata: {
344
- type: "object",
345
- additionalProperties: true
346
- },
347
- config: {
348
- type: "object",
349
- additionalProperties: true
350
- }
351
- },
352
- additionalProperties: true
154
+ _meta: appToolMeta
155
+ }, withToolErrors(buildPvpCoinflipCreateTransactionTool));
156
+ registerAppTool(server, "build_pvp_coinflip_join_transaction", {
157
+ title: "Build PvP Coinflip Join",
158
+ description: "Build, dry-run, or inspect an unsigned Suigar PvP coinflip join transaction.",
159
+ inputSchema: pvpCoinflipJoinInputSchema,
160
+ outputSchema: toolOutputSchema,
161
+ annotations: {
162
+ readOnlyHint: false,
163
+ destructiveHint: false,
164
+ idempotentHint: false,
165
+ openWorldHint: true
353
166
  },
354
- handler: buildPvpCoinflipJoinTransactionTool
355
- },
356
- {
357
- name: "build_pvp_coinflip_cancel_transaction",
358
- description: "Build, dry-run, or inspect a Suigar PvP coinflip cancel transaction.",
359
- inputSchema: {
360
- type: "object",
361
- properties: {
362
- mode: {
363
- type: "string",
364
- enum: [
365
- "build",
366
- "dry-run",
367
- "read-only"
368
- ],
369
- default: "build"
370
- },
371
- network: {
372
- type: "string",
373
- default: "testnet"
374
- },
375
- owner: { type: "string" },
376
- gameId: { type: "string" },
377
- coinType: { type: "string" },
378
- config: {
379
- type: "object",
380
- additionalProperties: true
381
- }
382
- },
383
- additionalProperties: true
167
+ _meta: appToolMeta
168
+ }, withToolErrors(buildPvpCoinflipJoinTransactionTool));
169
+ registerAppTool(server, "build_pvp_coinflip_cancel_transaction", {
170
+ title: "Build PvP Coinflip Cancel",
171
+ description: "Build, dry-run, or inspect an unsigned Suigar PvP coinflip cancel transaction.",
172
+ inputSchema: pvpCoinflipCancelInputSchema,
173
+ outputSchema: toolOutputSchema,
174
+ annotations: {
175
+ readOnlyHint: false,
176
+ destructiveHint: false,
177
+ idempotentHint: false,
178
+ openWorldHint: true
384
179
  },
385
- handler: buildPvpCoinflipCancelTransactionTool
386
- }
387
- ];
388
- const createSuigarMcpServer = () => {
389
- const server = new Server({
390
- name: "suigar",
391
- version: "0.0.0"
392
- }, { capabilities: { tools: {} } });
393
- server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOL_DEFINITIONS.map(({ name, description, inputSchema }) => ({
394
- name,
395
- description,
396
- inputSchema
397
- })) }));
398
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
399
- const tool = TOOL_DEFINITIONS.find((entry) => entry.name === request.params.name);
400
- if (!tool) return {
401
- isError: true,
402
- content: [{
403
- type: "text",
404
- text: `Unknown tool: ${request.params.name}`
405
- }]
406
- };
407
- try {
408
- return { content: [{
409
- type: "text",
410
- text: json(await tool.handler(request.params.arguments ?? {}))
411
- }] };
412
- } catch (error) {
413
- return {
414
- isError: true,
415
- content: [{
416
- type: "text",
417
- text: error instanceof Error ? error.message : String(error ?? "Unknown error")
418
- }]
419
- };
420
- }
421
- });
180
+ _meta: appToolMeta
181
+ }, withToolErrors(buildPvpCoinflipCancelTransactionTool));
422
182
  return server;
423
183
  };
424
184
  const startSuigarMcpServer = async () => {
425
185
  const server = createSuigarMcpServer();
426
186
  const transport = new StdioServerTransport();
427
187
  await server.connect(transport);
428
- return server;
429
188
  };
430
189
  //#endregion
431
- export { createSuigarMcpServer, startSuigarMcpServer };
190
+ export { SUIGAR_MCP_APP_RESOURCE_URI, createSuigarMcpAppResourceResult, createSuigarMcpServer, readSuigarMcpAppHtml, startSuigarMcpServer };
191
+
192
+ //# sourceMappingURL=server.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.mjs","names":[],"sources":["../src/server.ts"],"sourcesContent":["// Copyright (c) Suigar\n// SPDX-License-Identifier: Apache-2.0\n\nimport { readFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport {\n\tregisterAppResource,\n\tregisterAppTool,\n\tRESOURCE_MIME_TYPE,\n} from '@modelcontextprotocol/ext-apps/server';\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport {\n\tcoinflipInputSchema,\n\tconfigIdInputSchema,\n\tlimboInputSchema,\n\tpvpCoinflipCancelInputSchema,\n\tpvpCoinflipCreateInputSchema,\n\tpvpCoinflipJoinInputSchema,\n\trangeInputSchema,\n\treadConfigInputSchema,\n\treadGameMetadataInputSchema,\n\ttoolOutputSchema,\n} from './schemas.js';\nimport {\n\tbuildCoinflipTransactionTool,\n\tbuildLimboTransactionTool,\n\tbuildPlinkoTransactionTool,\n\tbuildPvpCoinflipCancelTransactionTool,\n\tbuildPvpCoinflipCreateTransactionTool,\n\tbuildPvpCoinflipJoinTransactionTool,\n\tbuildRangeTransactionTool,\n\tbuildWheelTransactionTool,\n\treadConfigTool,\n\treadGameMetadataTool,\n} from './tools.js';\nimport type { ToolTextResult } from './types.js';\n\nexport const SUIGAR_MCP_APP_RESOURCE_URI =\n\t'ui://suigar/transaction-inspector.html';\n\nconst packageJson = JSON.parse(\n\treadFileSync(new URL('../package.json', import.meta.url), 'utf8'),\n) as { version: string };\n\nconst errorText = (error: unknown) => {\n\tif (error instanceof Error) {\n\t\treturn `${error.name}: ${error.message}`;\n\t}\n\treturn String(error);\n};\n\nconst hasErrorCode = (\n\terror: unknown,\n\tcode: string,\n): error is Error & { code: string } =>\n\terror instanceof Error &&\n\t'code' in error &&\n\t(error as { code: unknown }).code === code;\n\nconst withToolErrors =\n\t<TInput>(handler: (input: TInput) => Promise<ToolTextResult>) =>\n\tasync (\n\t\tinput: TInput,\n\t): Promise<\n\t\t| ToolTextResult\n\t\t| { isError: true; content: [{ type: 'text'; text: string }] }\n\t> => {\n\t\ttry {\n\t\t\treturn await handler(input);\n\t\t} catch (error) {\n\t\t\treturn {\n\t\t\t\tisError: true,\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\ttext: `${errorText(error)}\\n\\nCheck required fields, network, coin type, and SDK config overrides. The MCP server only builds unsigned transactions and never signs or executes them.`,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\t};\n\nexport const readSuigarMcpAppHtml = async () => {\n\ttry {\n\t\treturn await readFile(new URL('./app/index.html', import.meta.url), 'utf8');\n\t} catch (error) {\n\t\tif (!hasErrorCode(error, 'ENOENT')) {\n\t\t\tthrow error;\n\t\t}\n\t\tthrow new Error('Unable to find bundled Suigar MCP App HTML.', {\n\t\t\tcause: error,\n\t\t});\n\t}\n};\n\nexport const createSuigarMcpAppResourceResult = async () => ({\n\tcontents: [\n\t\t{\n\t\t\turi: SUIGAR_MCP_APP_RESOURCE_URI,\n\t\t\tmimeType: RESOURCE_MIME_TYPE,\n\t\t\ttext: await readSuigarMcpAppHtml(),\n\t\t\t_meta: {\n\t\t\t\tui: {\n\t\t\t\t\tcsp: {\n\t\t\t\t\t\tconnectDomains: [],\n\t\t\t\t\t\tresourceDomains: [],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t],\n});\n\nexport const createSuigarMcpServer = () => {\n\tconst server = new McpServer({\n\t\tname: 'suigar',\n\t\tversion: packageJson.version,\n\t});\n\n\tserver.registerTool(\n\t\t'read_config',\n\t\t{\n\t\t\ttitle: 'Read Suigar Config',\n\t\t\tdescription:\n\t\t\t\t'Resolve Suigar SDK config for mainnet or testnet. Defaults to testnet.',\n\t\t\tinputSchema: readConfigInputSchema,\n\t\t\toutputSchema: toolOutputSchema,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: true,\n\t\t\t\tdestructiveHint: false,\n\t\t\t\tidempotentHint: true,\n\t\t\t\topenWorldHint: false,\n\t\t\t},\n\t\t},\n\t\twithToolErrors(readConfigTool),\n\t);\n\n\tregisterAppResource(\n\t\tserver,\n\t\t'Suigar Transaction Inspector',\n\t\tSUIGAR_MCP_APP_RESOURCE_URI,\n\t\t{\n\t\t\tdescription:\n\t\t\t\t'Compact MCP App UI for inspecting Suigar config, transaction plans, summaries, dry-runs, and serialized bytes.',\n\t\t},\n\t\tcreateSuigarMcpAppResourceResult,\n\t);\n\n\tconst appToolMeta = {\n\t\tui: {\n\t\t\tresourceUri: SUIGAR_MCP_APP_RESOURCE_URI,\n\t\t},\n\t};\n\n\tregisterAppTool(\n\t\tserver,\n\t\t'read_game_metadata',\n\t\t{\n\t\t\ttitle: 'Read Suigar Game Metadata',\n\t\t\tdescription:\n\t\t\t\t'Read SDK-backed metadata for a supported Suigar game and coin type.',\n\t\t\tinputSchema: readGameMetadataInputSchema,\n\t\t\toutputSchema: toolOutputSchema,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: true,\n\t\t\t\tdestructiveHint: false,\n\t\t\t\tidempotentHint: true,\n\t\t\t\topenWorldHint: false,\n\t\t\t},\n\t\t\t_meta: appToolMeta,\n\t\t},\n\t\twithToolErrors(readGameMetadataTool),\n\t);\n\n\tregisterAppTool(\n\t\tserver,\n\t\t'build_coinflip_transaction',\n\t\t{\n\t\t\ttitle: 'Build Coinflip Transaction',\n\t\t\tdescription:\n\t\t\t\t'Build, dry-run, or inspect an unsigned Suigar coinflip transaction.',\n\t\t\tinputSchema: coinflipInputSchema,\n\t\t\toutputSchema: toolOutputSchema,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: false,\n\t\t\t\tdestructiveHint: false,\n\t\t\t\tidempotentHint: false,\n\t\t\t\topenWorldHint: true,\n\t\t\t},\n\t\t\t_meta: appToolMeta,\n\t\t},\n\t\twithToolErrors(buildCoinflipTransactionTool),\n\t);\n\n\tregisterAppTool(\n\t\tserver,\n\t\t'build_limbo_transaction',\n\t\t{\n\t\t\ttitle: 'Build Limbo Transaction',\n\t\t\tdescription:\n\t\t\t\t'Build, dry-run, or inspect an unsigned Suigar limbo transaction.',\n\t\t\tinputSchema: limboInputSchema,\n\t\t\toutputSchema: toolOutputSchema,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: false,\n\t\t\t\tdestructiveHint: false,\n\t\t\t\tidempotentHint: false,\n\t\t\t\topenWorldHint: true,\n\t\t\t},\n\t\t\t_meta: appToolMeta,\n\t\t},\n\t\twithToolErrors(buildLimboTransactionTool),\n\t);\n\n\tregisterAppTool(\n\t\tserver,\n\t\t'build_plinko_transaction',\n\t\t{\n\t\t\ttitle: 'Build Plinko Transaction',\n\t\t\tdescription:\n\t\t\t\t'Build, dry-run, or inspect an unsigned Suigar plinko transaction.',\n\t\t\tinputSchema: configIdInputSchema,\n\t\t\toutputSchema: toolOutputSchema,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: false,\n\t\t\t\tdestructiveHint: false,\n\t\t\t\tidempotentHint: false,\n\t\t\t\topenWorldHint: true,\n\t\t\t},\n\t\t\t_meta: appToolMeta,\n\t\t},\n\t\twithToolErrors(buildPlinkoTransactionTool),\n\t);\n\n\tregisterAppTool(\n\t\tserver,\n\t\t'build_wheel_transaction',\n\t\t{\n\t\t\ttitle: 'Build Wheel Transaction',\n\t\t\tdescription:\n\t\t\t\t'Build, dry-run, or inspect an unsigned Suigar wheel transaction.',\n\t\t\tinputSchema: configIdInputSchema,\n\t\t\toutputSchema: toolOutputSchema,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: false,\n\t\t\t\tdestructiveHint: false,\n\t\t\t\tidempotentHint: false,\n\t\t\t\topenWorldHint: true,\n\t\t\t},\n\t\t\t_meta: appToolMeta,\n\t\t},\n\t\twithToolErrors(buildWheelTransactionTool),\n\t);\n\n\tregisterAppTool(\n\t\tserver,\n\t\t'build_range_transaction',\n\t\t{\n\t\t\ttitle: 'Build Range Transaction',\n\t\t\tdescription:\n\t\t\t\t'Build, dry-run, or inspect an unsigned Suigar range transaction.',\n\t\t\tinputSchema: rangeInputSchema,\n\t\t\toutputSchema: toolOutputSchema,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: false,\n\t\t\t\tdestructiveHint: false,\n\t\t\t\tidempotentHint: false,\n\t\t\t\topenWorldHint: true,\n\t\t\t},\n\t\t\t_meta: appToolMeta,\n\t\t},\n\t\twithToolErrors(buildRangeTransactionTool),\n\t);\n\n\tregisterAppTool(\n\t\tserver,\n\t\t'build_pvp_coinflip_create_transaction',\n\t\t{\n\t\t\ttitle: 'Build PvP Coinflip Create',\n\t\t\tdescription:\n\t\t\t\t'Build, dry-run, or inspect an unsigned Suigar PvP coinflip lobby creation transaction.',\n\t\t\tinputSchema: pvpCoinflipCreateInputSchema,\n\t\t\toutputSchema: toolOutputSchema,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: false,\n\t\t\t\tdestructiveHint: false,\n\t\t\t\tidempotentHint: false,\n\t\t\t\topenWorldHint: true,\n\t\t\t},\n\t\t\t_meta: appToolMeta,\n\t\t},\n\t\twithToolErrors(buildPvpCoinflipCreateTransactionTool),\n\t);\n\n\tregisterAppTool(\n\t\tserver,\n\t\t'build_pvp_coinflip_join_transaction',\n\t\t{\n\t\t\ttitle: 'Build PvP Coinflip Join',\n\t\t\tdescription:\n\t\t\t\t'Build, dry-run, or inspect an unsigned Suigar PvP coinflip join transaction.',\n\t\t\tinputSchema: pvpCoinflipJoinInputSchema,\n\t\t\toutputSchema: toolOutputSchema,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: false,\n\t\t\t\tdestructiveHint: false,\n\t\t\t\tidempotentHint: false,\n\t\t\t\topenWorldHint: true,\n\t\t\t},\n\t\t\t_meta: appToolMeta,\n\t\t},\n\t\twithToolErrors(buildPvpCoinflipJoinTransactionTool),\n\t);\n\n\tregisterAppTool(\n\t\tserver,\n\t\t'build_pvp_coinflip_cancel_transaction',\n\t\t{\n\t\t\ttitle: 'Build PvP Coinflip Cancel',\n\t\t\tdescription:\n\t\t\t\t'Build, dry-run, or inspect an unsigned Suigar PvP coinflip cancel transaction.',\n\t\t\tinputSchema: pvpCoinflipCancelInputSchema,\n\t\t\toutputSchema: toolOutputSchema,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: false,\n\t\t\t\tdestructiveHint: false,\n\t\t\t\tidempotentHint: false,\n\t\t\t\topenWorldHint: true,\n\t\t\t},\n\t\t\t_meta: appToolMeta,\n\t\t},\n\t\twithToolErrors(buildPvpCoinflipCancelTransactionTool),\n\t);\n\n\treturn server;\n};\n\nexport const startSuigarMcpServer = async () => {\n\tconst server = createSuigarMcpServer();\n\tconst transport = new StdioServerTransport();\n\tawait server.connect(transport);\n};\n"],"mappings":";;;;;;;;AAsCA,MAAa,8BACZ;AAED,MAAM,cAAc,KAAK,MACxB,aAAa,IAAI,IAAI,mBAAmB,OAAO,KAAK,GAAG,GAAG,MAAM,CACjE;AAEA,MAAM,aAAa,UAAmB;CACrC,IAAI,iBAAiB,OACpB,OAAO,GAAG,MAAM,KAAK,IAAI,MAAM;CAEhC,OAAO,OAAO,KAAK;AACpB;AAEA,MAAM,gBACL,OACA,SAEA,iBAAiB,SACjB,UAAU,SACT,MAA4B,SAAS;AAEvC,MAAM,kBACI,YACT,OACC,UAII;CACJ,IAAI;EACH,OAAO,MAAM,QAAQ,KAAK;CAC3B,SAAS,OAAO;EACf,OAAO;GACN,SAAS;GACT,SAAS,CACR;IACC,MAAM;IACN,MAAM,GAAG,UAAU,KAAK,EAAE;GAC3B,CACD;EACD;CACD;AACD;AAED,MAAa,uBAAuB,YAAY;CAC/C,IAAI;EACH,OAAO,MAAM,SAAS,IAAI,IAAI,oBAAoB,OAAO,KAAK,GAAG,GAAG,MAAM;CAC3E,SAAS,OAAO;EACf,IAAI,CAAC,aAAa,OAAO,QAAQ,GAChC,MAAM;EAEP,MAAM,IAAI,MAAM,+CAA+C,EAC9D,OAAO,MACR,CAAC;CACF;AACD;AAEA,MAAa,mCAAmC,aAAa,EAC5D,UAAU,CACT;CACC,KAAK;CACL,UAAU;CACV,MAAM,MAAM,qBAAqB;CACjC,OAAO,EACN,IAAI,EACH,KAAK;EACJ,gBAAgB,CAAC;EACjB,iBAAiB,CAAC;CACnB,EACD,EACD;AACD,CACD,EACD;AAEA,MAAa,8BAA8B;CAC1C,MAAM,SAAS,IAAI,UAAU;EAC5B,MAAM;EACN,SAAS,YAAY;CACtB,CAAC;CAED,OAAO,aACN,eACA;EACC,OAAO;EACP,aACC;EACD,aAAa;EACb,cAAc;EACd,aAAa;GACZ,cAAc;GACd,iBAAiB;GACjB,gBAAgB;GAChB,eAAe;EAChB;CACD,GACA,eAAe,cAAc,CAC9B;CAEA,oBACC,QACA,gCACA,6BACA,EACC,aACC,iHACF,GACA,gCACD;CAEA,MAAM,cAAc,EACnB,IAAI,EACH,aAAa,4BACd,EACD;CAEA,gBACC,QACA,sBACA;EACC,OAAO;EACP,aACC;EACD,aAAa;EACb,cAAc;EACd,aAAa;GACZ,cAAc;GACd,iBAAiB;GACjB,gBAAgB;GAChB,eAAe;EAChB;EACA,OAAO;CACR,GACA,eAAe,oBAAoB,CACpC;CAEA,gBACC,QACA,8BACA;EACC,OAAO;EACP,aACC;EACD,aAAa;EACb,cAAc;EACd,aAAa;GACZ,cAAc;GACd,iBAAiB;GACjB,gBAAgB;GAChB,eAAe;EAChB;EACA,OAAO;CACR,GACA,eAAe,4BAA4B,CAC5C;CAEA,gBACC,QACA,2BACA;EACC,OAAO;EACP,aACC;EACD,aAAa;EACb,cAAc;EACd,aAAa;GACZ,cAAc;GACd,iBAAiB;GACjB,gBAAgB;GAChB,eAAe;EAChB;EACA,OAAO;CACR,GACA,eAAe,yBAAyB,CACzC;CAEA,gBACC,QACA,4BACA;EACC,OAAO;EACP,aACC;EACD,aAAa;EACb,cAAc;EACd,aAAa;GACZ,cAAc;GACd,iBAAiB;GACjB,gBAAgB;GAChB,eAAe;EAChB;EACA,OAAO;CACR,GACA,eAAe,0BAA0B,CAC1C;CAEA,gBACC,QACA,2BACA;EACC,OAAO;EACP,aACC;EACD,aAAa;EACb,cAAc;EACd,aAAa;GACZ,cAAc;GACd,iBAAiB;GACjB,gBAAgB;GAChB,eAAe;EAChB;EACA,OAAO;CACR,GACA,eAAe,yBAAyB,CACzC;CAEA,gBACC,QACA,2BACA;EACC,OAAO;EACP,aACC;EACD,aAAa;EACb,cAAc;EACd,aAAa;GACZ,cAAc;GACd,iBAAiB;GACjB,gBAAgB;GAChB,eAAe;EAChB;EACA,OAAO;CACR,GACA,eAAe,yBAAyB,CACzC;CAEA,gBACC,QACA,yCACA;EACC,OAAO;EACP,aACC;EACD,aAAa;EACb,cAAc;EACd,aAAa;GACZ,cAAc;GACd,iBAAiB;GACjB,gBAAgB;GAChB,eAAe;EAChB;EACA,OAAO;CACR,GACA,eAAe,qCAAqC,CACrD;CAEA,gBACC,QACA,uCACA;EACC,OAAO;EACP,aACC;EACD,aAAa;EACb,cAAc;EACd,aAAa;GACZ,cAAc;GACd,iBAAiB;GACjB,gBAAgB;GAChB,eAAe;EAChB;EACA,OAAO;CACR,GACA,eAAe,mCAAmC,CACnD;CAEA,gBACC,QACA,yCACA;EACC,OAAO;EACP,aACC;EACD,aAAa;EACb,cAAc;EACd,aAAa;GACZ,cAAc;GACd,iBAAiB;GACjB,gBAAgB;GAChB,eAAe;EAChB;EACA,OAAO;CACR,GACA,eAAe,qCAAqC,CACrD;CAEA,OAAO;AACR;AAEA,MAAa,uBAAuB,YAAY;CAC/C,MAAM,SAAS,sBAAsB;CACrC,MAAM,YAAY,IAAI,qBAAqB;CAC3C,MAAM,OAAO,QAAQ,SAAS;AAC/B"}