@dimcool/mcp 0.1.14 → 0.1.17

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 +145 -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(
@@ -26805,6 +26841,105 @@ function registerMarketTools(server2, client) {
26805
26841
  );
26806
26842
  }
26807
26843
 
26844
+ // src/tools/notifications.ts
26845
+ function registerNotificationsTools(server2, client) {
26846
+ server2.tool(
26847
+ "dim_get_pending_events",
26848
+ "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.",
26849
+ {},
26850
+ async () => {
26851
+ try {
26852
+ const events = client.drainEvents();
26853
+ return {
26854
+ content: [
26855
+ {
26856
+ type: "text",
26857
+ text: JSON.stringify(
26858
+ {
26859
+ count: events.length,
26860
+ events,
26861
+ hint: events.length === 0 ? "No new events since last check." : "Process these events and take action as needed."
26862
+ },
26863
+ null,
26864
+ 2
26865
+ )
26866
+ }
26867
+ ]
26868
+ };
26869
+ } catch (error) {
26870
+ return {
26871
+ content: [
26872
+ {
26873
+ type: "text",
26874
+ text: `Failed to get pending events: ${error instanceof Error ? error.message : String(error)}`
26875
+ }
26876
+ ],
26877
+ isError: true
26878
+ };
26879
+ }
26880
+ }
26881
+ );
26882
+ server2.tool(
26883
+ "dim_check_notifications",
26884
+ "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.",
26885
+ {},
26886
+ async () => {
26887
+ try {
26888
+ if (!client.isAuthenticated) {
26889
+ return {
26890
+ content: [
26891
+ {
26892
+ type: "text",
26893
+ text: "Not authenticated. Call dim_login first."
26894
+ }
26895
+ ],
26896
+ isError: true
26897
+ };
26898
+ }
26899
+ const [notifications, dmThreads, friendRequests] = await Promise.all([
26900
+ client.sdk.notifications.list({ page: 1, limit: 20 }),
26901
+ client.sdk.chat.listDmThreads(),
26902
+ client.sdk.users.getIncomingFriendRequests()
26903
+ ]);
26904
+ const unreadDms = dmThreads.filter(
26905
+ (t) => (t.unreadCount ?? 0) > 0
26906
+ );
26907
+ return {
26908
+ content: [
26909
+ {
26910
+ type: "text",
26911
+ text: JSON.stringify(
26912
+ {
26913
+ unreadNotificationCount: notifications.unreadCount,
26914
+ notifications: notifications.notifications.filter(
26915
+ (n) => !n.read
26916
+ ),
26917
+ unreadDmThreads: unreadDms,
26918
+ incomingFriendRequests: friendRequests,
26919
+ pendingWsEvents: client.pendingEventCount,
26920
+ hint: "Use dim_get_pending_events to drain buffered real-time events."
26921
+ },
26922
+ null,
26923
+ 2
26924
+ )
26925
+ }
26926
+ ]
26927
+ };
26928
+ } catch (error) {
26929
+ return {
26930
+ content: [
26931
+ {
26932
+ type: "text",
26933
+ text: `Failed to check notifications: ${error instanceof Error ? error.message : String(error)}`
26934
+ }
26935
+ ],
26936
+ isError: true
26937
+ };
26938
+ }
26939
+ }
26940
+ );
26941
+ }
26942
+
26808
26943
  // src/tools/instructions.ts
26809
26944
  var DIM_INSTRUCTIONS = [
26810
26945
  {
@@ -26937,7 +27072,15 @@ var DIM_INSTRUCTIONS = [
26937
27072
  name: "dim_redeem_shares",
26938
27073
  description: "Redeem shares after market resolution."
26939
27074
  },
26940
- { name: "dim_get_market_analytics", description: "Get market analytics." }
27075
+ { name: "dim_get_market_analytics", description: "Get market analytics." },
27076
+ {
27077
+ name: "dim_get_pending_events",
27078
+ description: "Drain buffered real-time events (DMs, challenges, game turns). Call regularly to stay aware."
27079
+ },
27080
+ {
27081
+ name: "dim_check_notifications",
27082
+ description: "Check unread notifications, unread DM threads, and incoming friend requests in one call."
27083
+ }
26941
27084
  ];
26942
27085
  function registerInstructionsTool(server2) {
26943
27086
  server2.tool(
@@ -27171,6 +27314,7 @@ function createDimMcpServer(config) {
27171
27314
  registerReferralTools(server2, client);
27172
27315
  registerSupportTools(server2, client);
27173
27316
  registerMarketTools(server2, client);
27317
+ registerNotificationsTools(server2, client);
27174
27318
  registerResources(server2, client);
27175
27319
  return { server: server2, client };
27176
27320
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimcool/mcp",
3
- "version": "0.1.14",
3
+ "version": "0.1.17",
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": {