@beeper/desktop-mcp 4.1.293 → 4.2.1

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 (122) hide show
  1. package/README.md +2 -7
  2. package/handlers/get-accounts.d.mts +3 -0
  3. package/handlers/get-accounts.d.mts.map +1 -0
  4. package/handlers/get-accounts.d.ts +3 -0
  5. package/handlers/get-accounts.d.ts.map +1 -0
  6. package/handlers/get-accounts.js +32 -0
  7. package/handlers/get-accounts.js.map +1 -0
  8. package/handlers/get-accounts.mjs +28 -0
  9. package/handlers/get-accounts.mjs.map +1 -0
  10. package/handlers/get-chat.d.mts +3 -0
  11. package/handlers/get-chat.d.mts.map +1 -0
  12. package/handlers/get-chat.d.ts +3 -0
  13. package/handlers/get-chat.d.ts.map +1 -0
  14. package/handlers/get-chat.js +20 -0
  15. package/handlers/get-chat.js.map +1 -0
  16. package/handlers/get-chat.mjs +16 -0
  17. package/handlers/get-chat.mjs.map +1 -0
  18. package/handlers/index.d.mts +3 -0
  19. package/handlers/index.d.mts.map +1 -0
  20. package/handlers/index.d.ts +3 -0
  21. package/handlers/index.d.ts.map +1 -0
  22. package/handlers/index.js +30 -0
  23. package/handlers/index.js.map +1 -0
  24. package/handlers/index.mjs +27 -0
  25. package/handlers/index.mjs.map +1 -0
  26. package/handlers/list-chats.d.mts +3 -0
  27. package/handlers/list-chats.d.mts.map +1 -0
  28. package/handlers/list-chats.d.ts +3 -0
  29. package/handlers/list-chats.d.ts.map +1 -0
  30. package/handlers/list-chats.js +46 -0
  31. package/handlers/list-chats.js.map +1 -0
  32. package/handlers/list-chats.mjs +42 -0
  33. package/handlers/list-chats.mjs.map +1 -0
  34. package/handlers/list-messages.d.mts +3 -0
  35. package/handlers/list-messages.d.mts.map +1 -0
  36. package/handlers/list-messages.d.ts +3 -0
  37. package/handlers/list-messages.d.ts.map +1 -0
  38. package/handlers/list-messages.js +34 -0
  39. package/handlers/list-messages.js.map +1 -0
  40. package/handlers/list-messages.mjs +30 -0
  41. package/handlers/list-messages.mjs.map +1 -0
  42. package/handlers/open-app.d.mts +3 -0
  43. package/handlers/open-app.d.mts.map +1 -0
  44. package/handlers/open-app.d.ts +3 -0
  45. package/handlers/open-app.d.ts.map +1 -0
  46. package/handlers/open-app.js +26 -0
  47. package/handlers/open-app.js.map +1 -0
  48. package/handlers/open-app.mjs +22 -0
  49. package/handlers/open-app.mjs.map +1 -0
  50. package/handlers/search-chats.d.mts +3 -0
  51. package/handlers/search-chats.d.mts.map +1 -0
  52. package/handlers/search-chats.d.ts +3 -0
  53. package/handlers/search-chats.d.ts.map +1 -0
  54. package/handlers/search-chats.js +38 -0
  55. package/handlers/search-chats.js.map +1 -0
  56. package/handlers/search-chats.mjs +34 -0
  57. package/handlers/search-chats.mjs.map +1 -0
  58. package/handlers/search-messages.d.mts +3 -0
  59. package/handlers/search-messages.d.mts.map +1 -0
  60. package/handlers/search-messages.d.ts +3 -0
  61. package/handlers/search-messages.d.ts.map +1 -0
  62. package/handlers/search-messages.js +11 -0
  63. package/handlers/search-messages.js.map +1 -0
  64. package/handlers/search-messages.mjs +7 -0
  65. package/handlers/search-messages.mjs.map +1 -0
  66. package/handlers/search.d.mts +3 -0
  67. package/handlers/search.d.mts.map +1 -0
  68. package/handlers/search.d.ts +3 -0
  69. package/handlers/search.d.ts.map +1 -0
  70. package/handlers/search.js +29 -0
  71. package/handlers/search.js.map +1 -0
  72. package/handlers/search.mjs +25 -0
  73. package/handlers/search.mjs.map +1 -0
  74. package/handlers/send-message.d.mts +3 -0
  75. package/handlers/send-message.d.mts.map +1 -0
  76. package/handlers/send-message.d.ts +3 -0
  77. package/handlers/send-message.d.ts.map +1 -0
  78. package/handlers/send-message.js +20 -0
  79. package/handlers/send-message.js.map +1 -0
  80. package/handlers/send-message.mjs +16 -0
  81. package/handlers/send-message.mjs.map +1 -0
  82. package/handlers/utils.d.mts +29 -0
  83. package/handlers/utils.d.mts.map +1 -0
  84. package/handlers/utils.d.ts +29 -0
  85. package/handlers/utils.d.ts.map +1 -0
  86. package/handlers/utils.js +296 -0
  87. package/handlers/utils.js.map +1 -0
  88. package/handlers/utils.mjs +282 -0
  89. package/handlers/utils.mjs.map +1 -0
  90. package/http.d.mts +6 -0
  91. package/http.d.mts.map +1 -1
  92. package/http.d.ts +6 -0
  93. package/http.d.ts.map +1 -1
  94. package/http.js +7 -4
  95. package/http.js.map +1 -1
  96. package/http.mjs +3 -3
  97. package/http.mjs.map +1 -1
  98. package/package.json +13 -2
  99. package/server.js +1 -1
  100. package/server.js.map +1 -1
  101. package/server.mjs +1 -1
  102. package/server.mjs.map +1 -1
  103. package/src/handlers/get-accounts.ts +28 -0
  104. package/src/handlers/get-chat.ts +18 -0
  105. package/src/handlers/index.ts +29 -0
  106. package/src/handlers/list-chats.ts +47 -0
  107. package/src/handlers/list-messages.ts +33 -0
  108. package/src/handlers/open-app.ts +20 -0
  109. package/src/handlers/search-chats.ts +39 -0
  110. package/src/handlers/search-messages.ts +8 -0
  111. package/src/handlers/search.ts +24 -0
  112. package/src/handlers/send-message.ts +17 -0
  113. package/src/handlers/utils.ts +381 -0
  114. package/src/http.ts +3 -3
  115. package/src/server.ts +1 -1
  116. package/src/tools/index.ts +2 -1
  117. package/tools/index.d.mts.map +1 -1
  118. package/tools/index.d.ts.map +1 -1
  119. package/tools/index.js +2 -1
  120. package/tools/index.js.map +1 -1
  121. package/tools/index.mjs +2 -1
  122. package/tools/index.mjs.map +1 -1
@@ -0,0 +1,29 @@
1
+ import type { Endpoint, HandlerFunction } from '../tools';
2
+
3
+ import { handler as get_accounts } from './get-accounts';
4
+ import { handler as open_in_app } from './open-app';
5
+ import { handler as search } from './search';
6
+ import { handler as get_chat } from './get-chat';
7
+ import { handler as search_chats } from './search-chats';
8
+ import { handler as search_messages } from './search-messages';
9
+ import { handler as send_message } from './send-message';
10
+
11
+ const HANDLER_OVERRIDES: Record<string, HandlerFunction> = {
12
+ get_accounts,
13
+ open_in_app,
14
+ focus_app: open_in_app,
15
+ search,
16
+ get_chat,
17
+ search_chats,
18
+ search_messages,
19
+ send_message,
20
+ };
21
+
22
+ export function mapEndpoint(endpoint: Endpoint): Endpoint {
23
+ const handler = HANDLER_OVERRIDES[endpoint.tool.name];
24
+ if (!handler) return endpoint;
25
+ return {
26
+ ...endpoint,
27
+ handler,
28
+ };
29
+ }
@@ -0,0 +1,47 @@
1
+ import type { HandlerFunction } from '../tools/types';
2
+ import { asMarkdownContentResult, formatChatToMarkdown } from './utils';
3
+
4
+ export const handler: HandlerFunction = async (client, args) => {
5
+ const body = args as any;
6
+ const output = await client.chats.search(body);
7
+
8
+ const lines: string[] = [];
9
+ lines.push('# Chats');
10
+
11
+ const items = output.items || [];
12
+ const hasMore = !!output.hasMore;
13
+
14
+ if (hasMore) {
15
+ lines.push(`\nShowing ${items.length} chats (more available)`);
16
+ if (output.oldestCursor) {
17
+ lines.push(`Next page (older): cursor='${output.oldestCursor}', direction='before'`);
18
+ }
19
+ if (output.newestCursor) {
20
+ lines.push(`Previous page (newer): cursor='${output.newestCursor}', direction='after'`);
21
+ }
22
+ } else if (items.length > 0) {
23
+ lines.push(`\nShowing ${items.length} chat${items.length === 1 ? '' : 's'}`);
24
+ }
25
+
26
+ if (items.length === 0) {
27
+ lines.push('\nNo chats found.');
28
+ } else {
29
+ for (const chatWithPreview of items) {
30
+ lines.push(formatChatToMarkdown(chatWithPreview, undefined));
31
+ const preview = (chatWithPreview as any).preview;
32
+ if (preview) {
33
+ lines.push(`**Last message**: ${preview.text || '(no text)'}`);
34
+ if (preview.senderName) {
35
+ lines.push(`**From**: ${preview.senderName}`);
36
+ }
37
+ lines.push(`**Timestamp**: ${preview.timestamp}`);
38
+ }
39
+ }
40
+ }
41
+ lines.push('\n# Using this information\n');
42
+ lines.push(
43
+ '- Pass the "chatID" to get_chat or search_messages for details about a chat, or send_message to send a message to a chat.',
44
+ );
45
+ lines.push('- Link the "open" link to the user to allow them to view the chat in Beeper Desktop.');
46
+ return asMarkdownContentResult(lines);
47
+ };
@@ -0,0 +1,33 @@
1
+ import { asTextContentResult, type HandlerFunction } from '../tools/types';
2
+ import { mapMessagesToText } from './utils';
3
+
4
+ export const handler: HandlerFunction = async (client, args) => {
5
+ const body = args as any;
6
+ const output = await client.messages.search(body);
7
+
8
+ const lines: string[] = [];
9
+ lines.push('# Messages');
10
+
11
+ const items = (output as any).items || [];
12
+ const hasMore = !!(output as any).hasMore;
13
+
14
+ if (hasMore) {
15
+ lines.push(`\nShowing ${items.length} messages (more available)`);
16
+ if ((output as any).oldestCursor) {
17
+ lines.push(`Next page (older): cursor='${(output as any).oldestCursor}', direction='before'`);
18
+ }
19
+ if ((output as any).newestCursor) {
20
+ lines.push(`Previous page (newer): cursor='${(output as any).newestCursor}', direction='after'`);
21
+ }
22
+ } else if (items.length > 0) {
23
+ lines.push(`\nShowing ${items.length} message${items.length === 1 ? '' : 's'}`);
24
+ }
25
+
26
+ if (items.length === 0) {
27
+ lines.push('\nNo messages found.');
28
+ } else {
29
+ lines.push(mapMessagesToText(output as any, body, undefined));
30
+ }
31
+
32
+ return asTextContentResult(lines.join('\n'));
33
+ };
@@ -0,0 +1,20 @@
1
+ import { asTextContentResult, type HandlerFunction } from '../tools/types';
2
+
3
+ export const handler: HandlerFunction = async (client, args) => {
4
+ const body = args as any;
5
+ const output = await client.focus(body);
6
+
7
+ const lines: string[] = [];
8
+ if (output.success) {
9
+ lines.push('Beeper was opened.');
10
+ if (body?.chatID) {
11
+ const chatRef = String(body.chatID);
12
+ lines.push(`Focused chat: ${chatRef}`);
13
+ }
14
+ if (body?.draftText) lines.push(`Draft text populated: ${body.draftText}`);
15
+ if (body?.draftAttachmentPath) lines.push(`Draft attachment populated: ${body.draftAttachmentPath}`);
16
+ } else {
17
+ lines.push('Failed to open Beeper.');
18
+ }
19
+ return asTextContentResult(lines.join('\n'));
20
+ };
@@ -0,0 +1,39 @@
1
+ import type { HandlerFunction } from '../tools/types';
2
+ import { asMarkdownContentResult, formatChatToMarkdown } from './utils';
3
+
4
+ export const handler: HandlerFunction = async (client, args) => {
5
+ const body = args as any;
6
+ const output = await client.chats.search(body);
7
+
8
+ const lines: string[] = [];
9
+ lines.push('# Chats');
10
+
11
+ const items = output.items || [];
12
+ const hasMore = !!output.hasMore;
13
+
14
+ if (hasMore) {
15
+ lines.push(`\nFound ${items.length}+ chats (showing ${items.length})`);
16
+ if (output.oldestCursor) {
17
+ lines.push(`Next page (older): cursor='${output.oldestCursor}', direction='before'`);
18
+ }
19
+ if (output.newestCursor) {
20
+ lines.push(`Previous page (newer): cursor='${output.newestCursor}', direction='after'`);
21
+ }
22
+ } else if (items.length > 0) {
23
+ lines.push(`\nFound ${items.length} chat${items.length === 1 ? '' : 's'}`);
24
+ }
25
+
26
+ if (items.length === 0) {
27
+ lines.push('\nNo chats found.');
28
+ } else {
29
+ for (const chat of items) {
30
+ lines.push(formatChatToMarkdown(chat, undefined));
31
+ }
32
+ }
33
+ lines.push('\n# Using this information\n');
34
+ lines.push(
35
+ '- Pass the "chatID" to get_chat or search_messages for details about a chat, or send_message to send a message to a chat.',
36
+ );
37
+ lines.push('- Link the "open" link to the user to allow them to view the chat in Beeper Desktop.');
38
+ return asMarkdownContentResult(lines);
39
+ };
@@ -0,0 +1,8 @@
1
+ import type { HandlerFunction } from '../tools/types';
2
+ import { mapMessagesToText, asMarkdownContentResult } from './utils';
3
+
4
+ export const handler: HandlerFunction = async (client, args) => {
5
+ const body = args as any;
6
+ const output = await client.messages.search(body);
7
+ return asMarkdownContentResult(mapMessagesToText(output, body, undefined));
8
+ };
@@ -0,0 +1,24 @@
1
+ import type { HandlerFunction } from '../tools/types';
2
+ import { asMarkdownContentResult, formatChatToMarkdown, mapMessagesToText } from './utils';
3
+
4
+ export const handler: HandlerFunction = async (client, args) => {
5
+ const body = args as any;
6
+ const output = await client.search(body);
7
+
8
+ const lines: string[] = [];
9
+ if (body?.query) lines.push(`Query: "${body.query}"`);
10
+ const results = output?.results;
11
+ if (results?.chats?.length) {
12
+ lines.push('\n# Chats');
13
+ for (const chat of results.chats) lines.push(formatChatToMarkdown(chat, undefined));
14
+ }
15
+ if (results?.in_groups?.length) {
16
+ lines.push('\n# In Groups');
17
+ for (const chat of results.in_groups) lines.push(formatChatToMarkdown(chat, undefined));
18
+ }
19
+ if (results?.messages?.items?.length) {
20
+ lines.push('\n# Messages');
21
+ lines.push(mapMessagesToText(results.messages as any, body, undefined));
22
+ }
23
+ return asMarkdownContentResult(lines);
24
+ };
@@ -0,0 +1,17 @@
1
+ import type { HandlerFunction } from '../tools/types';
2
+ import { asMarkdownContentResult, createOpenLink } from './utils';
3
+
4
+ export const handler: HandlerFunction = async (client, args) => {
5
+ const body = args as any;
6
+ const output = await client.messages.send(body);
7
+
8
+ const lines: string[] = [];
9
+ if (output.pendingMessageID) {
10
+ const deeplink = createOpenLink('', body?.chatID ?? '');
11
+ if (deeplink) lines.push(`**Open the chat in Beeper**: ${deeplink}`);
12
+ } else {
13
+ lines.push('Failed to send message.');
14
+ }
15
+
16
+ return asMarkdownContentResult(lines);
17
+ };
@@ -0,0 +1,381 @@
1
+ import {
2
+ differenceInMilliseconds,
3
+ differenceInDays,
4
+ endOfDay,
5
+ format,
6
+ isToday,
7
+ isYesterday,
8
+ isSameYear,
9
+ parse,
10
+ } from 'date-fns';
11
+ import type * as Shared from '@beeper/desktop-api/resources/shared';
12
+ import type * as ChatsAPI from '@beeper/desktop-api/resources/chats/chats';
13
+ import { ToolCallResult } from '../tools/types';
14
+
15
+ const MILLIS_IN_WEEK = 86400000 * 7;
16
+
17
+ type Message = Shared.Message;
18
+ type Chat = ChatsAPI.Chat;
19
+ type User = Shared.User;
20
+ type MessageReaction = NonNullable<Message['reactions']>[number];
21
+
22
+ export const formatRelativeDate = (date: Date) => {
23
+ const timeDifference = differenceInMilliseconds(endOfDay(new Date()), date);
24
+
25
+ if (isToday(date)) return 'Today';
26
+ if (isYesterday(date)) return 'Yesterday';
27
+
28
+ return new Intl.DateTimeFormat(
29
+ 'default',
30
+ timeDifference < MILLIS_IN_WEEK ?
31
+ {
32
+ weekday: 'long',
33
+ }
34
+ : isSameYear(date, new Date()) ?
35
+ {
36
+ weekday: 'short',
37
+ month: 'short',
38
+ day: 'numeric',
39
+ }
40
+ : {
41
+ year: 'numeric',
42
+ month: 'short',
43
+ day: 'numeric',
44
+ },
45
+ ).format(date);
46
+ };
47
+
48
+ export const formatBytes = (bytes: number, decimals = 0) => {
49
+ if (bytes === 0) return '0 B';
50
+
51
+ const k = 1024;
52
+ const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
53
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
54
+
55
+ return `${Math.floor(parseFloat((bytes / k ** i).toFixed(decimals)))}${sizes[i]}`;
56
+ };
57
+
58
+ const skinToneRegex = /\uD83C[\uDFFB-\uDFFF]/g;
59
+ const removeSkinTone = (emojiString: string): string => emojiString.replace(skinToneRegex, '');
60
+
61
+ export function groupReactions(reactions: MessageReaction[]): { [key: string]: MessageReaction[] } {
62
+ const map: { [key: string]: MessageReaction[] } = {};
63
+ reactions.forEach((reaction) => {
64
+ if (!reaction.reactionKey) return;
65
+ const key = removeSkinTone(reaction.reactionKey);
66
+ map[key] ||= [];
67
+ map[key].push(reaction);
68
+ });
69
+ return map;
70
+ }
71
+
72
+ export const getParticipantName = (participant: User, preferFirstName?: boolean): string =>
73
+ participant.fullName && preferFirstName ?
74
+ participant.fullName.split(' ')[0]!
75
+ : participant.fullName ||
76
+ participant.username ||
77
+ participant.email ||
78
+ participant.phoneNumber ||
79
+ participant.id;
80
+
81
+ export const createOpenLink = (baseURL: string, localChatIDOrChatID: string, messageKey?: string) =>
82
+ `${baseURL}/open/${encodeURIComponent(localChatIDOrChatID)}${messageKey ? `/${messageKey}` : ''}`;
83
+
84
+ export const formatParticipantsToMarkdown = (participants: User[] | undefined, limit = 3): string => {
85
+ if (!participants || participants.length === 0) return '';
86
+
87
+ const names = participants
88
+ .slice(0, limit)
89
+ .map((p) => p.fullName || p.username || p.id)
90
+ .filter(Boolean);
91
+
92
+ if (participants.length > limit) {
93
+ const othersCount = participants.length - limit;
94
+ names.push(`& ${othersCount} other${othersCount === 1 ? '' : 's'}`);
95
+ }
96
+
97
+ return names.join(', ');
98
+ };
99
+
100
+ export const formatReactionsToMarkdown = (
101
+ reactions: Message['reactions'],
102
+ participants?: Map<string, User>,
103
+ ): string => {
104
+ if (!reactions || reactions.length === 0) return '';
105
+
106
+ const reactionMap = groupReactions(reactions);
107
+ const reactionParts: string[] = [];
108
+ for (const [reactionKey, reactionList] of Object.entries(reactionMap)) {
109
+ const count = reactionList.length;
110
+ const reactorNames = reactionList
111
+ .slice(0, 5)
112
+ .map((r) => {
113
+ if (!r.participantID) return null;
114
+ const participant = participants?.get(r.participantID);
115
+ return participant ? getParticipantName(participant) : r.participantID;
116
+ })
117
+ .filter(Boolean);
118
+
119
+ let reactorInfo = '';
120
+ if (reactorNames.length > 0) {
121
+ if (count > 5) {
122
+ const othersCount = count - 5;
123
+ reactorInfo = ` (${reactorNames.join(', ')} & ${othersCount} other${othersCount === 1 ? '' : 's'})`;
124
+ } else {
125
+ reactorInfo = ` (${reactorNames.join(', ')})`;
126
+ }
127
+ }
128
+
129
+ reactionParts.push(`${reactionKey} ${count}${reactorInfo}`);
130
+ }
131
+
132
+ return reactionParts.length > 0 ? ` [${reactionParts.join(' ')}]` : '';
133
+ };
134
+
135
+ export const formatAttachmentToMarkdown = (attachment: Shared.Attachment | undefined): string => {
136
+ if (!attachment) return '';
137
+
138
+ const typeEmoji =
139
+ {
140
+ img: 'šŸ–¼',
141
+ video: 'šŸŽ„',
142
+ audio: 'šŸŽµ',
143
+ unknown: 'šŸ“Ž',
144
+ }[attachment.type] || 'šŸ“Ž';
145
+
146
+ const fileName = attachment.fileName || 'file';
147
+ const url = attachment.srcURL || '';
148
+ const hasBothDimensions =
149
+ typeof attachment.size?.width === 'number' && typeof attachment.size?.height === 'number';
150
+
151
+ const metaInfo: string[] = [];
152
+ if (attachment.fileSize) {
153
+ metaInfo.push(formatBytes(attachment.fileSize));
154
+ }
155
+ if (hasBothDimensions) {
156
+ metaInfo.push(`${attachment.size!.width}x${attachment.size!.height}`);
157
+ }
158
+
159
+ const metaString = metaInfo.length > 0 ? ` (${metaInfo.join(', ')})` : '';
160
+
161
+ return `\n${typeEmoji} [${fileName}](${url})${metaString}`;
162
+ };
163
+
164
+ export const formatChatToMarkdown = (chat: Chat, baseURL: string | undefined): string => {
165
+ const openURL = baseURL ? createOpenLink(baseURL, chat.localChatID ?? chat.id) : undefined;
166
+ const title = openURL ? `[${chat.title}](${openURL})` : chat.title;
167
+ const participantList =
168
+ chat.participants?.items ? formatParticipantsToMarkdown(chat.participants.items, 3) : '';
169
+ const participantInfo = participantList ? ` with ${participantList}` : '';
170
+ const lines: string[] = [];
171
+ lines.push(`\n## ${title} (chatID: ${chat.localChatID})`);
172
+ let chatLine = `Chat on ${chat.network}${participantInfo}.`;
173
+ if (typeof chat.unreadCount === 'number' && chat.unreadCount > 0) {
174
+ chatLine += ` It has ${chat.unreadCount} unread message${chat.unreadCount === 1 ? '' : 's'}.`;
175
+ }
176
+ lines.push(chatLine);
177
+ lines.push(`**Type**: ${chat.type}`);
178
+ if (chat.lastActivity) lines.push(`**Last Activity**: ${chat.lastActivity}`);
179
+ const status: string[] = [];
180
+ if (chat.isArchived) status.push('archived');
181
+ if (chat.isMuted) status.push('muted');
182
+ if (chat.isPinned) status.push('pinned');
183
+ if (status.length > 0) lines.push(`This chat is ${status.join(', ')}.`);
184
+ return lines.join('\n');
185
+ };
186
+
187
+ const parseLocalDateKey = (key: string): Date => {
188
+ const parsed = parse(key, 'yyyy-MM-dd', new Date());
189
+ if (isNaN(parsed.getTime())) {
190
+ throw new Error(`Invalid date key: ${key}`);
191
+ }
192
+ return parsed;
193
+ };
194
+
195
+ interface MessagesResponse {
196
+ items: Message[];
197
+ chats: Record<string, Chat>;
198
+ hasMore?: boolean;
199
+ oldestCursor?: string;
200
+ newestCursor?: string;
201
+ }
202
+
203
+ export const mapMessagesToText = (
204
+ output: Shared.MessagesCursorSearch,
205
+ input?: {
206
+ query?: string;
207
+ sender?: string;
208
+ mediaTypes?: string[];
209
+ },
210
+ ctx?: { apiBaseURL?: string; maxTextLength?: number },
211
+ ) => {
212
+ const { items, hasMore } = output;
213
+ const chats = (output as any)?.body?.chats ?? {};
214
+
215
+ const messageCount = items.length;
216
+ const chatCount = Object.keys(chats).length;
217
+
218
+ // Determine if search filters would cause gaps in timeline
219
+ // Gaps occur when filtering by: query text, sender, or media types
220
+ // Gaps do NOT occur when only filtering by: chatIDs, accountIDs, chatType, or date ranges
221
+ const hasGapCausingFilters =
222
+ input && (input.query || input.sender || (input.mediaTypes && input.mediaTypes.length > 0));
223
+
224
+ const paginationInfo: string[] = [];
225
+ if (messageCount === 0) {
226
+ if (!chats || chatCount === 0) {
227
+ paginationInfo.push('No matching chats found');
228
+ } else {
229
+ paginationInfo.push(`No messages found in ${chatCount} chat${chatCount === 1 ? '' : 's'}`);
230
+ }
231
+ } else if (hasMore) {
232
+ paginationInfo.push(
233
+ `Found ${messageCount}+ messages across ${chatCount} chat${
234
+ chatCount === 1 ? '' : 's'
235
+ } (showing ${messageCount})`,
236
+ );
237
+ if (output.oldestCursor) {
238
+ paginationInfo.push(`Next page (older): cursor='${output.oldestCursor}', direction='before'`);
239
+ }
240
+ if (output.newestCursor) {
241
+ paginationInfo.push(`Previous page (newer): cursor='${output.newestCursor}', direction='after'`);
242
+ }
243
+ } else {
244
+ paginationInfo.push(
245
+ `Found ${messageCount} message${messageCount === 1 ? '' : 's'} across ${chatCount} chat${
246
+ chatCount === 1 ? '' : 's'
247
+ } (complete)`,
248
+ );
249
+ }
250
+
251
+ if (hasGapCausingFilters && messageCount > 0) {
252
+ paginationInfo.push('āš ļø Filtered results: only showing messages matching your search criteria.');
253
+ }
254
+
255
+ const messagesByChat = new Map<string, typeof items>();
256
+ for (const message of items) {
257
+ const chatMessages = messagesByChat.get(message.chatID) || [];
258
+ chatMessages.push(message);
259
+ messagesByChat.set(message.chatID, chatMessages);
260
+ }
261
+
262
+ const chatSummaries: string[] = [];
263
+ for (const [chatID, messages] of messagesByChat) {
264
+ const chat = chats[chatID];
265
+ if (chat) {
266
+ chatSummaries.push(`# ${chat.title} [${messages.length} message${messages.length === 1 ? '' : 's'}]`);
267
+ }
268
+ }
269
+
270
+ const headerLines = [...paginationInfo, '', ...chatSummaries];
271
+
272
+ const summary = headerLines.join('\n');
273
+
274
+ const chatSections: string[] = [];
275
+
276
+ for (const [chatID, messages] of messagesByChat) {
277
+ const chat = chats[chatID];
278
+ if (!chat) continue;
279
+
280
+ const participantList =
281
+ chat.participants?.items ? formatParticipantsToMarkdown(chat.participants.items, 3) : '';
282
+ const participantInfo = participantList ? ` with ${participantList}` : '';
283
+ const openURL = ctx?.apiBaseURL ? createOpenLink(ctx.apiBaseURL, chat.localChatID ?? chat.id) : undefined;
284
+ const title = openURL ? `[${chat.title}](${openURL})` : chat.title;
285
+ chatSections.push(`# ${title} (chatID: ${chat.localChatID})`);
286
+ chatSections.push(`Chat on ${chat.network}${participantInfo}.`);
287
+ chatSections.push('');
288
+
289
+ const messagesByDate = new Map<string, Message[]>();
290
+ for (const message of messages) {
291
+ const dateKey = format(new Date(message.timestamp), 'yyyy-MM-dd');
292
+ const dateMessages = messagesByDate.get(dateKey) || [];
293
+ dateMessages.push(message);
294
+ messagesByDate.set(dateKey, dateMessages);
295
+ }
296
+
297
+ const sortedDates = Array.from(messagesByDate.keys()).sort();
298
+
299
+ const participantMap =
300
+ chat?.participants?.items ?
301
+ new Map<string, User>(chat.participants.items.map((p: User) => [p.id, p]))
302
+ : undefined;
303
+
304
+ for (let i = 0; i < sortedDates.length; i++) {
305
+ const dateKey = sortedDates[i]!;
306
+ const dateObj = parseLocalDateKey(dateKey);
307
+ const relativeTime = formatRelativeDate(dateObj);
308
+ chatSections.push(`## ${relativeTime} (${dateKey})`);
309
+ chatSections.push('');
310
+
311
+ const dateMessages = messagesByDate.get(dateKey) || [];
312
+ dateMessages.sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
313
+
314
+ for (const message of dateMessages) {
315
+ const time = new Date(message.timestamp);
316
+ const timeStr = format(time, 'HH:mm');
317
+
318
+ const baseSenderName = message.senderName || message.senderID;
319
+ const senderName = message.isSender ? `${baseSenderName} (You)` : baseSenderName;
320
+
321
+ const maxTextLength = ctx?.maxTextLength ?? 1000;
322
+ let text = message.text || '';
323
+ if (text && text.length > maxTextLength) {
324
+ const remainingChars = text.length - maxTextLength;
325
+ text = text.substring(0, maxTextLength) + `... [+${remainingChars} chars]`;
326
+ }
327
+
328
+ const attachment = message.attachments?.[0]; // Assume single attachment
329
+ const attachmentChatID = chat.localChatID ?? chat.id;
330
+ const attachmentLink =
331
+ attachment && attachmentChatID ?
332
+ `\nšŸ“Ž [${attachment.fileName || 'attachment'}](beeper-mcp://attachments/${attachmentChatID}/${
333
+ message.id
334
+ }/0)`
335
+ : '';
336
+ const reactionsStr = formatReactionsToMarkdown(message.reactions, participantMap);
337
+
338
+ const sortKeyLink =
339
+ chat.localChatID ?
340
+ `([open at sort key](${createOpenLink(
341
+ ctx?.apiBaseURL || '',
342
+ chat.localChatID,
343
+ String(message.sortKey),
344
+ )}))`
345
+ : `(sortKey: ${message.sortKey})`;
346
+ const messageStr = `**${senderName}** (${timeStr}): ${text}${attachmentLink}${reactionsStr} ${sortKeyLink}`;
347
+
348
+ chatSections.push(messageStr);
349
+ chatSections.push('');
350
+ }
351
+
352
+ // Add date gap indicator when dates are not consecutive
353
+ if (i < sortedDates.length - 1) {
354
+ const nextDateKey = sortedDates[i + 1]!;
355
+ const currentDate = parseLocalDateKey(dateKey!);
356
+ const nextDate = parseLocalDateKey(nextDateKey);
357
+ const dayDiff = differenceInDays(nextDate, currentDate);
358
+
359
+ // Only show gap if dates are not consecutive
360
+ if (dayDiff > 1) {
361
+ const gapDays = dayDiff - 1;
362
+ chatSections.push(`*[... ${gapDays} day${gapDays === 1 ? '' : 's'} gap ...]*`);
363
+ chatSections.push('');
364
+ }
365
+ }
366
+ }
367
+ }
368
+
369
+ return [summary, '', ...chatSections].join('\n');
370
+ };
371
+
372
+ export function asMarkdownContentResult(text: string | string[]): ToolCallResult {
373
+ return {
374
+ content: [
375
+ {
376
+ type: 'text',
377
+ text: Array.isArray(text) ? text.join('\n') : text,
378
+ },
379
+ ],
380
+ };
381
+ }
package/src/http.ts CHANGED
@@ -71,7 +71,7 @@ const newServer = ({
71
71
  return server;
72
72
  };
73
73
 
74
- const post =
74
+ export const post =
75
75
  (options: { clientOptions: ClientOptions; mcpOptions: McpOptions }) =>
76
76
  async (req: express.Request, res: express.Response) => {
77
77
  const server = newServer({ ...options, req, res });
@@ -85,7 +85,7 @@ const post =
85
85
  await transport.handleRequest(req, res, req.body);
86
86
  };
87
87
 
88
- const get = async (req: express.Request, res: express.Response) => {
88
+ export const get = async (req: express.Request, res: express.Response) => {
89
89
  res.status(405).json({
90
90
  jsonrpc: '2.0',
91
91
  error: {
@@ -95,7 +95,7 @@ const get = async (req: express.Request, res: express.Response) => {
95
95
  });
96
96
  };
97
97
 
98
- const del = async (req: express.Request, res: express.Response) => {
98
+ export const del = async (req: express.Request, res: express.Response) => {
99
99
  res.status(405).json({
100
100
  jsonrpc: '2.0',
101
101
  error: {
package/src/server.ts CHANGED
@@ -34,7 +34,7 @@ export const newMcpServer = () =>
34
34
  new McpServer(
35
35
  {
36
36
  name: 'beeper_desktop_api_api',
37
- version: '4.1.293',
37
+ version: '4.2.1',
38
38
  },
39
39
  {
40
40
  capabilities: { tools: {}, logging: {} },
@@ -15,11 +15,12 @@ import clear_chat_reminder from './chats/reminders/clear-chat-reminder';
15
15
  import list_messages from './messages/list-messages';
16
16
  import search_messages from './messages/search-messages';
17
17
  import send_message from './messages/send-message';
18
+ import { mapEndpoint } from '../handlers';
18
19
 
19
20
  export const endpoints: Endpoint[] = [];
20
21
 
21
22
  function addEndpoint(endpoint: Endpoint) {
22
- endpoints.push(endpoint);
23
+ endpoints.push(mapEndpoint(endpoint));
23
24
  }
24
25
 
25
26
  addEndpoint(focus_app);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/tools/index.ts"],"names":[],"mappings":"OAEO,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE;AAE9C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;AAc/C,eAAO,MAAM,SAAS,EAAE,QAAQ,EAAO,CAAC;AAkBxC,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,UAAU,GAAG,WAAW,GAAG,KAAK,GAAG,MAAM,CAAC;IAChD,EAAE,EAAE,SAAS,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CA4B1E"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/tools/index.ts"],"names":[],"mappings":"OAEO,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE;AAE9C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;AAe/C,eAAO,MAAM,SAAS,EAAE,QAAQ,EAAO,CAAC;AAkBxC,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,UAAU,GAAG,WAAW,GAAG,KAAK,GAAG,MAAM,CAAC;IAChD,EAAE,EAAE,SAAS,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CA4B1E"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/tools/index.ts"],"names":[],"mappings":"OAEO,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE;AAE9C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;AAc/C,eAAO,MAAM,SAAS,EAAE,QAAQ,EAAO,CAAC;AAkBxC,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,UAAU,GAAG,WAAW,GAAG,KAAK,GAAG,MAAM,CAAC;IAChD,EAAE,EAAE,SAAS,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CA4B1E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/tools/index.ts"],"names":[],"mappings":"OAEO,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE;AAE9C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;AAe/C,eAAO,MAAM,SAAS,EAAE,QAAQ,EAAO,CAAC;AAkBxC,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,UAAU,GAAG,WAAW,GAAG,KAAK,GAAG,MAAM,CAAC;IAChD,EAAE,EAAE,SAAS,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CA4B1E"}
package/tools/index.js CHANGED
@@ -17,9 +17,10 @@ const clear_chat_reminder_1 = __importDefault(require("./chats/reminders/clear-c
17
17
  const list_messages_1 = __importDefault(require("./messages/list-messages.js"));
18
18
  const search_messages_1 = __importDefault(require("./messages/search-messages.js"));
19
19
  const send_message_1 = __importDefault(require("./messages/send-message.js"));
20
+ const handlers_1 = require("../handlers/index.js");
20
21
  exports.endpoints = [];
21
22
  function addEndpoint(endpoint) {
22
- exports.endpoints.push(endpoint);
23
+ exports.endpoints.push((0, handlers_1.mapEndpoint)(endpoint));
23
24
  }
24
25
  addEndpoint(focus_app_1.default);
25
26
  addEndpoint(search_1.default);