@dimcool/mcp 0.1.14 → 0.1.18

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 (2) hide show
  1. package/dist/index.js +337 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -25146,6 +25146,8 @@ var DimClient = class {
25146
25146
  config;
25147
25147
  authenticated = false;
25148
25148
  userId = null;
25149
+ eventQueue = [];
25150
+ unsubscribers = [];
25149
25151
  constructor(config) {
25150
25152
  this.config = config;
25151
25153
  const secretKeyBytes = bs58.decode(config.walletPrivateKey);
@@ -25208,6 +25210,39 @@ var DimClient = class {
25208
25210
  async ensureConnected(timeoutMs = 1e4) {
25209
25211
  await this.sdk.ensureWebSocketConnected(timeoutMs);
25210
25212
  }
25213
+ /**
25214
+ * Subscribe to key WS events and buffer them for agent consumption.
25215
+ * Call after authenticate() when the WS transport is connected.
25216
+ */
25217
+ startEventListeners() {
25218
+ const events = [
25219
+ "chat:message",
25220
+ "notification",
25221
+ "lobby:matched",
25222
+ "lobby:invitation",
25223
+ "game:turn",
25224
+ "game:completed"
25225
+ ];
25226
+ for (const event of events) {
25227
+ this.unsubscribers.push(
25228
+ this.sdk.events.subscribe(event, (payload) => {
25229
+ this.eventQueue.push({
25230
+ event,
25231
+ payload,
25232
+ at: (/* @__PURE__ */ new Date()).toISOString()
25233
+ });
25234
+ })
25235
+ );
25236
+ }
25237
+ }
25238
+ /** Drain all buffered events since last call. */
25239
+ drainEvents() {
25240
+ return this.eventQueue.splice(0);
25241
+ }
25242
+ /** Peek at buffered event count without draining. */
25243
+ get pendingEventCount() {
25244
+ return this.eventQueue.length;
25245
+ }
25211
25246
  /**
25212
25247
  * Get the Keypair for transaction signing.
25213
25248
  */
@@ -25226,6 +25261,7 @@ function registerAuthTools(server2, client) {
25226
25261
  async () => {
25227
25262
  try {
25228
25263
  const result = await client.authenticate();
25264
+ client.startEventListeners();
25229
25265
  const nextSteps = [];
25230
25266
  if (result.username == null || result.username === "") {
25231
25267
  nextSteps.push(
@@ -26209,6 +26245,155 @@ function registerChallengesTools(server2, client) {
26209
26245
 
26210
26246
  // src/tools/referrals.ts
26211
26247
  import { z as z7 } from "zod";
26248
+ function generateOnboardingScript(platform, referrer) {
26249
+ const templates = {
26250
+ openclaw: `# Connect to DIM \u2014 OpenClaw Setup
26251
+
26252
+ ## Step 1: Install the DIM plugin
26253
+ \`\`\`bash
26254
+ openclaw plugins install @dimcool/dimclaw
26255
+ \`\`\`
26256
+
26257
+ ## Step 2: Configure
26258
+ Add to your OpenClaw config under \`plugins.entries.dimclaw.config\`:
26259
+ \`\`\`yaml
26260
+ plugins:
26261
+ entries:
26262
+ dimclaw:
26263
+ enabled: true
26264
+ config:
26265
+ walletStorePath: '~/.dim/openclaw-wallet.json'
26266
+ \`\`\`
26267
+
26268
+ ## Step 3: Restart and verify
26269
+ \`\`\`bash
26270
+ openclaw gateway restart
26271
+ \`\`\`
26272
+
26273
+ Then run:
26274
+ 1. \`dim_login\`
26275
+ 2. \`dim_apply_referral_code\` with referralCode: \`${referrer}\`
26276
+ 3. \`dim_get_balance\`
26277
+
26278
+ ## Fund your wallet
26279
+ Send USDC on Solana to the wallet address shown by \`dim_get_balance\`.`,
26280
+ "claude-desktop": `# Connect to DIM \u2014 Claude Desktop Setup
26281
+
26282
+ ## Step 1: Initialize wallet
26283
+ \`\`\`bash
26284
+ npx @dimcool/mcp init-wallet
26285
+ \`\`\`
26286
+
26287
+ ## Step 2: Edit config
26288
+ Open \`~/Library/Application Support/Claude/claude_desktop_config.json\` (macOS) or \`%APPDATA%\\Claude\\claude_desktop_config.json\` (Windows).
26289
+
26290
+ Add to \`mcpServers\`:
26291
+ \`\`\`json
26292
+ {
26293
+ "mcpServers": {
26294
+ "dim": {
26295
+ "command": "npx",
26296
+ "args": ["@dimcool/mcp"],
26297
+ "env": {
26298
+ "DIM_WALLET_STORE_PATH": "/path/from/init-wallet/output",
26299
+ "DIM_API_URL": "https://api.dim.cool",
26300
+ "DIM_REFERRAL_CODE": "${referrer}"
26301
+ }
26302
+ }
26303
+ }
26304
+ }
26305
+ \`\`\`
26306
+
26307
+ ## Step 3: Restart Claude Desktop
26308
+ Referral code \`${referrer}\` is applied on first login.
26309
+
26310
+ ## Verify
26311
+ Ask Claude: "Log in to DIM and check my balance"`,
26312
+ cursor: `# Connect to DIM \u2014 Cursor Setup
26313
+
26314
+ ## Step 1: Initialize wallet
26315
+ \`\`\`bash
26316
+ npx @dimcool/mcp init-wallet
26317
+ \`\`\`
26318
+
26319
+ ## Step 2: Edit \`.cursor/mcp.json\`
26320
+ \`\`\`json
26321
+ {
26322
+ "mcpServers": {
26323
+ "dim": {
26324
+ "command": "npx",
26325
+ "args": ["@dimcool/mcp"],
26326
+ "env": {
26327
+ "DIM_WALLET_STORE_PATH": "/path/from/init-wallet/output",
26328
+ "DIM_API_URL": "https://api.dim.cool",
26329
+ "DIM_REFERRAL_CODE": "${referrer}"
26330
+ }
26331
+ }
26332
+ }
26333
+ }
26334
+ \`\`\`
26335
+
26336
+ ## Step 3: Restart Cursor
26337
+ Referral code \`${referrer}\` is applied on first login.`,
26338
+ hermes: `# Connect to DIM \u2014 Hermes Setup
26339
+
26340
+ ## Step 1: Initialize wallet
26341
+ \`\`\`bash
26342
+ npx @dimcool/mcp init-wallet
26343
+ \`\`\`
26344
+
26345
+ ## Step 2: Add DIM skill
26346
+ \`\`\`yaml
26347
+ skills:
26348
+ dim:
26349
+ command: npx
26350
+ args: ["@dimcool/mcp"]
26351
+ env:
26352
+ DIM_WALLET_STORE_PATH: "/path/from/init-wallet/output"
26353
+ DIM_API_URL: "https://api.dim.cool"
26354
+ DIM_REFERRAL_CODE: "${referrer}"
26355
+ \`\`\`
26356
+
26357
+ ## Step 3: Restart Hermes
26358
+ Referral code \`${referrer}\` is applied on first login.`,
26359
+ "node-sdk": `# Connect to DIM \u2014 Node.js SDK
26360
+
26361
+ ## Install
26362
+ \`\`\`bash
26363
+ npm install @dimcool/sdk @dimcool/wallet
26364
+ \`\`\`
26365
+
26366
+ ## Connect
26367
+ \`\`\`typescript
26368
+ import { SDK, NodeStorage } from '@dimcool/sdk';
26369
+ import { Wallet } from '@dimcool/wallet';
26370
+
26371
+ const wallet = new Wallet({
26372
+ enabledNetworks: ['solana'],
26373
+ fromPrivateKey: process.env.DIM_WALLET_PRIVATE_KEY!,
26374
+ });
26375
+
26376
+ const sdk = new SDK({
26377
+ appId: 'dim-agents',
26378
+ baseUrl: 'https://api.dim.cool',
26379
+ storage: new NodeStorage(),
26380
+ autoPay: { enabled: true, maxAmountMinor: 20_000 },
26381
+ });
26382
+
26383
+ sdk.wallet.setSigner(wallet.getSigner());
26384
+
26385
+ const { access_token, user } = await sdk.auth.loginWithWallet({
26386
+ referralCode: '${referrer}',
26387
+ });
26388
+
26389
+ sdk.wsTransport.setAccessToken(access_token);
26390
+ await sdk.ensureWebSocketConnected(10000);
26391
+ \`\`\`
26392
+
26393
+ Full docs: https://docs.dim.cool`
26394
+ };
26395
+ return templates[platform] ?? `Unknown platform "${platform}". Supported: openclaw, claude-desktop, cursor, hermes, node-sdk`;
26396
+ }
26212
26397
  function registerReferralTools(server2, client) {
26213
26398
  server2.tool(
26214
26399
  "dim_get_referral_summary",
@@ -26389,6 +26574,41 @@ function registerReferralTools(server2, client) {
26389
26574
  }
26390
26575
  }
26391
26576
  );
26577
+ server2.tool(
26578
+ "dim_get_referral_onboarding",
26579
+ "Get platform-specific setup instructions to share with another agent or user to onboard them to DIM with your referral code embedded.",
26580
+ {
26581
+ platform: z7.enum(["openclaw", "claude-desktop", "cursor", "hermes", "node-sdk"]).describe("Target platform for the agent being onboarded")
26582
+ },
26583
+ async ({ platform }) => {
26584
+ try {
26585
+ let username = "YOUR_USERNAME";
26586
+ try {
26587
+ if (client.currentUserId) {
26588
+ const profile = await client.sdk.users.getUserById(
26589
+ client.currentUserId
26590
+ );
26591
+ if (profile.username) username = profile.username;
26592
+ }
26593
+ } catch {
26594
+ }
26595
+ const script = generateOnboardingScript(platform, username);
26596
+ return {
26597
+ content: [{ type: "text", text: script }]
26598
+ };
26599
+ } catch (error) {
26600
+ return {
26601
+ content: [
26602
+ {
26603
+ type: "text",
26604
+ text: `Failed to generate onboarding script: ${error instanceof Error ? error.message : String(error)}`
26605
+ }
26606
+ ],
26607
+ isError: true
26608
+ };
26609
+ }
26610
+ }
26611
+ );
26392
26612
  }
26393
26613
 
26394
26614
  // src/tools/support.ts
@@ -26805,6 +27025,105 @@ function registerMarketTools(server2, client) {
26805
27025
  );
26806
27026
  }
26807
27027
 
27028
+ // src/tools/notifications.ts
27029
+ function registerNotificationsTools(server2, client) {
27030
+ server2.tool(
27031
+ "dim_get_pending_events",
27032
+ "Drain buffered real-time events (DMs, challenges, game turns, match notifications). Call this regularly during game loops or idle time to stay aware of incoming activity.",
27033
+ {},
27034
+ async () => {
27035
+ try {
27036
+ const events = client.drainEvents();
27037
+ return {
27038
+ content: [
27039
+ {
27040
+ type: "text",
27041
+ text: JSON.stringify(
27042
+ {
27043
+ count: events.length,
27044
+ events,
27045
+ hint: events.length === 0 ? "No new events since last check." : "Process these events and take action as needed."
27046
+ },
27047
+ null,
27048
+ 2
27049
+ )
27050
+ }
27051
+ ]
27052
+ };
27053
+ } catch (error) {
27054
+ return {
27055
+ content: [
27056
+ {
27057
+ type: "text",
27058
+ text: `Failed to get pending events: ${error instanceof Error ? error.message : String(error)}`
27059
+ }
27060
+ ],
27061
+ isError: true
27062
+ };
27063
+ }
27064
+ }
27065
+ );
27066
+ server2.tool(
27067
+ "dim_check_notifications",
27068
+ "Check all pending items in one call: unread notifications (challenges, game results), unread DM threads, and incoming friend requests. Use this to catch up after being idle.",
27069
+ {},
27070
+ async () => {
27071
+ try {
27072
+ if (!client.isAuthenticated) {
27073
+ return {
27074
+ content: [
27075
+ {
27076
+ type: "text",
27077
+ text: "Not authenticated. Call dim_login first."
27078
+ }
27079
+ ],
27080
+ isError: true
27081
+ };
27082
+ }
27083
+ const [notifications, dmThreads, friendRequests] = await Promise.all([
27084
+ client.sdk.notifications.list({ page: 1, limit: 20 }),
27085
+ client.sdk.chat.listDmThreads(),
27086
+ client.sdk.users.getIncomingFriendRequests()
27087
+ ]);
27088
+ const unreadDms = dmThreads.filter(
27089
+ (t) => (t.unreadCount ?? 0) > 0
27090
+ );
27091
+ return {
27092
+ content: [
27093
+ {
27094
+ type: "text",
27095
+ text: JSON.stringify(
27096
+ {
27097
+ unreadNotificationCount: notifications.unreadCount,
27098
+ notifications: notifications.notifications.filter(
27099
+ (n) => !n.read
27100
+ ),
27101
+ unreadDmThreads: unreadDms,
27102
+ incomingFriendRequests: friendRequests,
27103
+ pendingWsEvents: client.pendingEventCount,
27104
+ hint: "Use dim_get_pending_events to drain buffered real-time events."
27105
+ },
27106
+ null,
27107
+ 2
27108
+ )
27109
+ }
27110
+ ]
27111
+ };
27112
+ } catch (error) {
27113
+ return {
27114
+ content: [
27115
+ {
27116
+ type: "text",
27117
+ text: `Failed to check notifications: ${error instanceof Error ? error.message : String(error)}`
27118
+ }
27119
+ ],
27120
+ isError: true
27121
+ };
27122
+ }
27123
+ }
27124
+ );
27125
+ }
27126
+
26808
27127
  // src/tools/instructions.ts
26809
27128
  var DIM_INSTRUCTIONS = [
26810
27129
  {
@@ -26937,7 +27256,23 @@ var DIM_INSTRUCTIONS = [
26937
27256
  name: "dim_redeem_shares",
26938
27257
  description: "Redeem shares after market resolution."
26939
27258
  },
26940
- { name: "dim_get_market_analytics", description: "Get market analytics." }
27259
+ { name: "dim_get_market_analytics", description: "Get market analytics." },
27260
+ {
27261
+ name: "dim_get_pending_events",
27262
+ description: "Drain buffered real-time events (DMs, challenges, game turns). Call regularly to stay aware."
27263
+ },
27264
+ {
27265
+ name: "dim_check_notifications",
27266
+ description: "Check unread notifications, unread DM threads, and incoming friend requests in one call."
27267
+ },
27268
+ {
27269
+ name: "dim_get_agent_config",
27270
+ description: "Get autonomy scopes, spending limits, and current daily spend."
27271
+ },
27272
+ {
27273
+ name: "dim_get_referral_onboarding",
27274
+ description: "Get platform-specific setup instructions to share with another agent, with your referral code embedded."
27275
+ }
26941
27276
  ];
26942
27277
  function registerInstructionsTool(server2) {
26943
27278
  server2.tool(
@@ -27171,6 +27506,7 @@ function createDimMcpServer(config) {
27171
27506
  registerReferralTools(server2, client);
27172
27507
  registerSupportTools(server2, client);
27173
27508
  registerMarketTools(server2, client);
27509
+ registerNotificationsTools(server2, client);
27174
27510
  registerResources(server2, client);
27175
27511
  return { server: server2, client };
27176
27512
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimcool/mcp",
3
- "version": "0.1.14",
3
+ "version": "0.1.18",
4
4
  "description": "MCP server for DIM — lets AI agents play games, chat, send USDC, and earn referral income on the DIM platform",
5
5
  "type": "module",
6
6
  "bin": {