@deredex/mcp 0.0.0-stage → 0.4.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.
@@ -0,0 +1,151 @@
1
+ // CRM accounts tools — list / get / create / update / archive.
2
+ //
3
+ // Accounts are the "company" entity in the CRM (contacts belong to
4
+ // accounts, deals belong to accounts). Backend routes live in
5
+ // services/backend/modules/crm/module.go under /api/crm/accounts.
6
+ import { z } from "zod";
7
+ // -- list_accounts ------------------------------------------------------
8
+ export const listAccountsInput = {
9
+ q: z
10
+ .string()
11
+ .optional()
12
+ .describe("Free-text search across name, domain, industry. Omit for no filter."),
13
+ ownerUserId: z
14
+ .string()
15
+ .uuid()
16
+ .optional()
17
+ .describe("Restrict to accounts owned by a specific user."),
18
+ industry: z
19
+ .string()
20
+ .optional()
21
+ .describe("Filter by industry label."),
22
+ includeArchived: z
23
+ .boolean()
24
+ .optional()
25
+ .describe("Include archived accounts (default false)."),
26
+ limit: z
27
+ .number()
28
+ .int()
29
+ .min(1)
30
+ .max(100)
31
+ .optional()
32
+ .describe("Cap on rows returned (default 25, max 100)."),
33
+ };
34
+ export async function listAccounts(client, args) {
35
+ const params = new URLSearchParams();
36
+ if (args.q)
37
+ params.set("q", args.q);
38
+ if (args.ownerUserId)
39
+ params.set("ownerUserId", args.ownerUserId);
40
+ if (args.industry)
41
+ params.set("industry", args.industry);
42
+ if (args.includeArchived)
43
+ params.set("archived", "true");
44
+ if (args.limit)
45
+ params.set("limit", String(args.limit));
46
+ const qs = params.toString();
47
+ const resp = await client.get(`/api/crm/accounts${qs ? "?" + qs : ""}`);
48
+ return resp.items;
49
+ }
50
+ export const listAccountsDescription = "List CRM accounts (companies). Optional filters: free-text `q`, `ownerUserId`, `industry`. Default cap 25, max 100.";
51
+ // -- get_account --------------------------------------------------------
52
+ export const getAccountInput = {
53
+ id: z.string().uuid().describe("Account UUID."),
54
+ };
55
+ export async function getAccount(client, args) {
56
+ return client.get(`/api/crm/accounts/${encodeURIComponent(args.id)}`);
57
+ }
58
+ export const getAccountDescription = "Fetch a single CRM account by UUID.";
59
+ // -- create_account -----------------------------------------------------
60
+ export const createAccountInput = {
61
+ name: z.string().min(1).max(200).describe("Company / account name."),
62
+ domain: z
63
+ .string()
64
+ .max(200)
65
+ .optional()
66
+ .describe("Optional web domain, e.g. 'example.com'."),
67
+ industry: z
68
+ .string()
69
+ .max(100)
70
+ .optional()
71
+ .describe("Optional industry label — free text."),
72
+ sizeBucket: z
73
+ .string()
74
+ .max(50)
75
+ .optional()
76
+ .describe("Optional company-size bucket (e.g. '11-50', '201-500')."),
77
+ ownerUserId: z
78
+ .string()
79
+ .uuid()
80
+ .optional()
81
+ .describe("Optional owner user UUID. Defaults to the token holder when omitted."),
82
+ parentAccountId: z
83
+ .string()
84
+ .uuid()
85
+ .optional()
86
+ .describe("Optional parent account UUID for hierarchical account structures."),
87
+ renewalDate: z
88
+ .string()
89
+ .regex(/^\d{4}-\d{2}-\d{2}$/)
90
+ .optional()
91
+ .describe("Optional contract renewal date in ISO YYYY-MM-DD format."),
92
+ };
93
+ export async function createAccount(client, args) {
94
+ return client.post("/api/crm/accounts", args);
95
+ }
96
+ export const createAccountDescription = "Create a new CRM account (company). Only `name` is required.";
97
+ // -- update_account -----------------------------------------------------
98
+ export const updateAccountInput = {
99
+ id: z.string().uuid().describe("Account UUID to update."),
100
+ name: z.string().min(1).max(200).optional().describe("New name."),
101
+ domain: z
102
+ .string()
103
+ .max(200)
104
+ .nullable()
105
+ .optional()
106
+ .describe("New domain, or null to clear."),
107
+ industry: z
108
+ .string()
109
+ .max(100)
110
+ .nullable()
111
+ .optional()
112
+ .describe("New industry, or null to clear."),
113
+ sizeBucket: z
114
+ .string()
115
+ .max(50)
116
+ .nullable()
117
+ .optional()
118
+ .describe("New size bucket, or null to clear."),
119
+ ownerUserId: z
120
+ .string()
121
+ .uuid()
122
+ .nullable()
123
+ .optional()
124
+ .describe("New owner UUID, or null to clear."),
125
+ parentAccountId: z
126
+ .string()
127
+ .uuid()
128
+ .nullable()
129
+ .optional()
130
+ .describe("New parent UUID, or null to detach from the hierarchy."),
131
+ renewalDate: z
132
+ .string()
133
+ .regex(/^\d{4}-\d{2}-\d{2}$/)
134
+ .nullable()
135
+ .optional()
136
+ .describe("New renewal date (YYYY-MM-DD), or null to clear."),
137
+ };
138
+ export async function updateAccount(client, args) {
139
+ const { id, ...body } = args;
140
+ return client.patch(`/api/crm/accounts/${encodeURIComponent(id)}`, body);
141
+ }
142
+ export const updateAccountDescription = "Partial-update a CRM account. Only fields supplied are changed. Send `null` for nullable fields to clear.";
143
+ // -- archive_account ----------------------------------------------------
144
+ export const archiveAccountInput = {
145
+ id: z.string().uuid().describe("Account UUID to archive."),
146
+ };
147
+ export async function archiveAccount(client, args) {
148
+ await client.del(`/api/crm/accounts/${encodeURIComponent(args.id)}`);
149
+ return { archived: true };
150
+ }
151
+ export const archiveAccountDescription = "Soft-archive a CRM account. Contacts and deals linked to it remain intact.";
@@ -0,0 +1,164 @@
1
+ // CRM contacts tools — list / get / create / update / archive +
2
+ // list_contact_notes / add_contact_note.
3
+ //
4
+ // These are the day-one AI verbs: "who's on file", "add a note
5
+ // about the call I just had", "update this person's email."
6
+ // Backend routes live in services/backend/modules/crm/module.go
7
+ // under /api/crm/contacts.
8
+ import { z } from "zod";
9
+ // -- list_contacts ------------------------------------------------------
10
+ export const listContactsInput = {
11
+ q: z
12
+ .string()
13
+ .optional()
14
+ .describe("Free-text search across name, email, phone, title, company name. Omit for no search filter."),
15
+ accountId: z
16
+ .string()
17
+ .uuid()
18
+ .optional()
19
+ .describe("Restrict to contacts linked to a specific account."),
20
+ ownerUserId: z
21
+ .string()
22
+ .uuid()
23
+ .optional()
24
+ .describe("Restrict to contacts owned by a specific user."),
25
+ includeArchived: z
26
+ .boolean()
27
+ .optional()
28
+ .describe("Include archived contacts (default false)."),
29
+ limit: z
30
+ .number()
31
+ .int()
32
+ .min(1)
33
+ .max(100)
34
+ .optional()
35
+ .describe("Cap on the number of contacts returned (default 25, max 100)."),
36
+ };
37
+ export async function listContacts(client, args) {
38
+ const params = new URLSearchParams();
39
+ if (args.q)
40
+ params.set("q", args.q);
41
+ if (args.accountId)
42
+ params.set("accountId", args.accountId);
43
+ if (args.ownerUserId)
44
+ params.set("ownerUserId", args.ownerUserId);
45
+ if (args.includeArchived)
46
+ params.set("archived", "true");
47
+ if (args.limit)
48
+ params.set("limit", String(args.limit));
49
+ const qs = params.toString();
50
+ const resp = await client.get(`/api/crm/contacts${qs ? "?" + qs : ""}`);
51
+ return resp.items;
52
+ }
53
+ export const listContactsDescription = "List CRM contacts. Optional filters: free-text `q` search, `accountId`, `ownerUserId`. Default cap 25, max 100.";
54
+ // -- get_contact --------------------------------------------------------
55
+ export const getContactInput = {
56
+ id: z.string().uuid().describe("Contact UUID."),
57
+ };
58
+ export async function getContact(client, args) {
59
+ return client.get(`/api/crm/contacts/${encodeURIComponent(args.id)}`);
60
+ }
61
+ export const getContactDescription = "Fetch a single CRM contact by UUID.";
62
+ // -- create_contact -----------------------------------------------------
63
+ export const createContactInput = {
64
+ firstName: z.string().min(1).max(100).describe("First / given name."),
65
+ lastName: z.string().min(1).max(100).describe("Last / family name."),
66
+ email: z
67
+ .string()
68
+ .email()
69
+ .optional()
70
+ .describe("Optional email address. Must be a valid email if supplied."),
71
+ phone: z.string().max(50).optional().describe("Optional phone number."),
72
+ title: z.string().max(200).optional().describe("Optional job title."),
73
+ companyName: z
74
+ .string()
75
+ .max(200)
76
+ .optional()
77
+ .describe("Optional company name — free text. Distinct from `accountId` which links to a CRM account row."),
78
+ accountId: z
79
+ .string()
80
+ .uuid()
81
+ .optional()
82
+ .describe("Optional CRM account UUID to link this contact to."),
83
+ ownerUserId: z
84
+ .string()
85
+ .uuid()
86
+ .optional()
87
+ .describe("Optional owner user UUID. Defaults to the token holder when omitted."),
88
+ };
89
+ export async function createContact(client, args) {
90
+ return client.post("/api/crm/contacts", args);
91
+ }
92
+ export const createContactDescription = "Create a new CRM contact. `firstName` + `lastName` are required. Optional: email / phone / title / companyName / accountId / ownerUserId.";
93
+ // -- update_contact -----------------------------------------------------
94
+ export const updateContactInput = {
95
+ id: z.string().uuid().describe("Contact UUID to update."),
96
+ firstName: z.string().min(1).max(100).optional().describe("New first name."),
97
+ lastName: z.string().min(1).max(100).optional().describe("New last name."),
98
+ email: z
99
+ .string()
100
+ .email()
101
+ .nullable()
102
+ .optional()
103
+ .describe("New email. Send null to clear."),
104
+ phone: z
105
+ .string()
106
+ .max(50)
107
+ .nullable()
108
+ .optional()
109
+ .describe("New phone. Send null to clear."),
110
+ title: z
111
+ .string()
112
+ .max(200)
113
+ .nullable()
114
+ .optional()
115
+ .describe("New job title. Send null to clear."),
116
+ accountId: z
117
+ .string()
118
+ .uuid()
119
+ .nullable()
120
+ .optional()
121
+ .describe("New linked account UUID, or null to clear."),
122
+ ownerUserId: z
123
+ .string()
124
+ .uuid()
125
+ .nullable()
126
+ .optional()
127
+ .describe("New owner UUID, or null to clear (defaults back to no owner)."),
128
+ };
129
+ export async function updateContact(client, args) {
130
+ const { id, ...body } = args;
131
+ return client.patch(`/api/crm/contacts/${encodeURIComponent(id)}`, body);
132
+ }
133
+ export const updateContactDescription = "Partial-update a CRM contact. Only fields supplied are changed. Send `null` for nullable fields to clear them.";
134
+ // -- archive_contact ----------------------------------------------------
135
+ export const archiveContactInput = {
136
+ id: z.string().uuid().describe("Contact UUID to archive."),
137
+ };
138
+ export async function archiveContact(client, args) {
139
+ await client.del(`/api/crm/contacts/${encodeURIComponent(args.id)}`);
140
+ return { archived: true };
141
+ }
142
+ export const archiveContactDescription = "Soft-archive a CRM contact. Row remains queryable via `list_contacts` with `includeArchived: true`.";
143
+ // -- list_contact_notes -------------------------------------------------
144
+ export const listContactNotesInput = {
145
+ contactId: z.string().uuid().describe("Contact UUID to load notes for."),
146
+ };
147
+ export async function listContactNotes(client, args) {
148
+ const resp = await client.get(`/api/crm/contacts/${encodeURIComponent(args.contactId)}/notes`);
149
+ return resp.items;
150
+ }
151
+ export const listContactNotesDescription = "List timeline notes attached to a CRM contact.";
152
+ // -- add_contact_note ---------------------------------------------------
153
+ export const addContactNoteInput = {
154
+ contactId: z.string().uuid().describe("Contact UUID to attach the note to."),
155
+ body: z
156
+ .string()
157
+ .min(1)
158
+ .max(20000)
159
+ .describe("Note body — free-form markdown; will land on the contact timeline."),
160
+ };
161
+ export async function addContactNote(client, args) {
162
+ return client.post(`/api/crm/contacts/${encodeURIComponent(args.contactId)}/notes`, { body: args.body });
163
+ }
164
+ export const addContactNoteDescription = "Attach a timeline note to a CRM contact. Useful after logging a call, meeting, or observation.";
@@ -0,0 +1,205 @@
1
+ // CRM deals tools — list / get / create / update / move_stage /
2
+ // archive + note ops.
3
+ //
4
+ // Deals are the sales opportunity entity. The most common AI verbs
5
+ // here are stage transitions ("mark this deal as won") and note
6
+ // logging ("add what happened on today's call"). Backend routes live
7
+ // in services/backend/modules/crm/module.go under /api/crm/deals.
8
+ import { z } from "zod";
9
+ // -- list_deals ---------------------------------------------------------
10
+ export const listDealsInput = {
11
+ q: z.string().optional().describe("Free-text search across deal name."),
12
+ stage: z
13
+ .string()
14
+ .optional()
15
+ .describe("Filter by stage. Common values: lead, qualified, proposal, won, lost."),
16
+ accountId: z
17
+ .string()
18
+ .uuid()
19
+ .optional()
20
+ .describe("Restrict to deals linked to a specific account."),
21
+ ownerUserId: z
22
+ .string()
23
+ .uuid()
24
+ .optional()
25
+ .describe("Restrict to deals owned by a specific user."),
26
+ includeArchived: z
27
+ .boolean()
28
+ .optional()
29
+ .describe("Include archived deals (default false)."),
30
+ limit: z
31
+ .number()
32
+ .int()
33
+ .min(1)
34
+ .max(100)
35
+ .optional()
36
+ .describe("Cap on rows returned (default 25, max 100)."),
37
+ };
38
+ export async function listDeals(client, args) {
39
+ const params = new URLSearchParams();
40
+ if (args.q)
41
+ params.set("q", args.q);
42
+ if (args.stage)
43
+ params.set("stage", args.stage);
44
+ if (args.accountId)
45
+ params.set("accountId", args.accountId);
46
+ if (args.ownerUserId)
47
+ params.set("ownerUserId", args.ownerUserId);
48
+ if (args.includeArchived)
49
+ params.set("archived", "true");
50
+ if (args.limit)
51
+ params.set("limit", String(args.limit));
52
+ const qs = params.toString();
53
+ const resp = await client.get(`/api/crm/deals${qs ? "?" + qs : ""}`);
54
+ return resp.items;
55
+ }
56
+ export const listDealsDescription = "List CRM deals. Optional filters: free-text `q`, `stage`, `accountId`, `ownerUserId`. Default cap 25, max 100.";
57
+ // -- get_deal -----------------------------------------------------------
58
+ export const getDealInput = {
59
+ id: z.string().uuid().describe("Deal UUID."),
60
+ };
61
+ export async function getDeal(client, args) {
62
+ return client.get(`/api/crm/deals/${encodeURIComponent(args.id)}`);
63
+ }
64
+ export const getDealDescription = "Fetch a single CRM deal by UUID.";
65
+ // -- create_deal --------------------------------------------------------
66
+ export const createDealInput = {
67
+ name: z.string().min(1).max(200).describe("Deal name."),
68
+ amount: z
69
+ .string()
70
+ .regex(/^\d+(\.\d{1,4})?$/)
71
+ .optional()
72
+ .describe("Deal amount as a decimal string, e.g. '12500' or '12500.00'. Preserves precision."),
73
+ currency: z
74
+ .string()
75
+ .length(3)
76
+ .optional()
77
+ .describe("ISO 4217 currency code, e.g. 'USD'. Default is tenant currency."),
78
+ stage: z
79
+ .string()
80
+ .optional()
81
+ .describe("Initial stage. Common values: lead, qualified, proposal, won, lost. Default is 'lead'."),
82
+ probability: z
83
+ .number()
84
+ .int()
85
+ .min(0)
86
+ .max(100)
87
+ .optional()
88
+ .describe("Win probability 0-100."),
89
+ closeDate: z
90
+ .string()
91
+ .regex(/^\d{4}-\d{2}-\d{2}$/)
92
+ .optional()
93
+ .describe("Actual/planned close date in YYYY-MM-DD format."),
94
+ expectedCloseDate: z
95
+ .string()
96
+ .regex(/^\d{4}-\d{2}-\d{2}$/)
97
+ .optional()
98
+ .describe("Expected close date for pipeline forecasting."),
99
+ accountId: z
100
+ .string()
101
+ .uuid()
102
+ .optional()
103
+ .describe("Linked CRM account UUID."),
104
+ primaryContactId: z
105
+ .string()
106
+ .uuid()
107
+ .optional()
108
+ .describe("Primary contact UUID."),
109
+ ownerUserId: z
110
+ .string()
111
+ .uuid()
112
+ .optional()
113
+ .describe("Owner UUID. Defaults to the token holder when omitted."),
114
+ };
115
+ export async function createDeal(client, args) {
116
+ return client.post("/api/crm/deals", args);
117
+ }
118
+ export const createDealDescription = "Create a new CRM deal. Only `name` is required. Amount is a decimal string to preserve precision.";
119
+ // -- update_deal --------------------------------------------------------
120
+ export const updateDealInput = {
121
+ id: z.string().uuid().describe("Deal UUID to update."),
122
+ name: z.string().min(1).max(200).optional().describe("New name."),
123
+ amount: z
124
+ .string()
125
+ .regex(/^\d+(\.\d{1,4})?$/)
126
+ .optional()
127
+ .describe("New amount as a decimal string."),
128
+ currency: z
129
+ .string()
130
+ .length(3)
131
+ .optional()
132
+ .describe("New ISO 4217 currency code."),
133
+ stage: z.string().optional().describe("New stage."),
134
+ probability: z
135
+ .number()
136
+ .int()
137
+ .min(0)
138
+ .max(100)
139
+ .optional()
140
+ .describe("New probability 0-100."),
141
+ closeDate: z
142
+ .string()
143
+ .regex(/^\d{4}-\d{2}-\d{2}$/)
144
+ .optional()
145
+ .describe("New close date."),
146
+ accountId: z
147
+ .string()
148
+ .uuid()
149
+ .nullable()
150
+ .optional()
151
+ .describe("New linked account UUID, or null to clear."),
152
+ primaryContactId: z
153
+ .string()
154
+ .uuid()
155
+ .nullable()
156
+ .optional()
157
+ .describe("New primary contact UUID, or null to clear."),
158
+ };
159
+ export async function updateDeal(client, args) {
160
+ const { id, ...body } = args;
161
+ return client.patch(`/api/crm/deals/${encodeURIComponent(id)}`, body);
162
+ }
163
+ export const updateDealDescription = "Partial-update a CRM deal. Only fields supplied are changed. Use `move_deal_to_stage` for the common 'change the stage' path; it's more discoverable.";
164
+ // -- move_deal_to_stage -------------------------------------------------
165
+ export const moveDealToStageInput = {
166
+ id: z.string().uuid().describe("Deal UUID."),
167
+ stage: z
168
+ .string()
169
+ .describe("Target stage. Common values: lead, qualified, proposal, won, lost."),
170
+ };
171
+ export async function moveDealToStage(client, args) {
172
+ return client.patch(`/api/crm/deals/${encodeURIComponent(args.id)}`, { stage: args.stage });
173
+ }
174
+ export const moveDealToStageDescription = "Move a CRM deal to a new stage. Under the hood this PATCHes just the `stage` field. The backend logs a stage-history row you can view via the shell's deal detail page.";
175
+ // -- archive_deal -------------------------------------------------------
176
+ export const archiveDealInput = {
177
+ id: z.string().uuid().describe("Deal UUID to archive."),
178
+ };
179
+ export async function archiveDeal(client, args) {
180
+ await client.del(`/api/crm/deals/${encodeURIComponent(args.id)}`);
181
+ return { archived: true };
182
+ }
183
+ export const archiveDealDescription = "Soft-archive a CRM deal. Row remains queryable via `list_deals` with `includeArchived: true`.";
184
+ // -- list_deal_notes ----------------------------------------------------
185
+ export const listDealNotesInput = {
186
+ dealId: z.string().uuid().describe("Deal UUID to load notes for."),
187
+ };
188
+ export async function listDealNotes(client, args) {
189
+ const resp = await client.get(`/api/crm/deals/${encodeURIComponent(args.dealId)}/notes`);
190
+ return resp.items;
191
+ }
192
+ export const listDealNotesDescription = "List timeline notes attached to a CRM deal.";
193
+ // -- add_deal_note ------------------------------------------------------
194
+ export const addDealNoteInput = {
195
+ dealId: z.string().uuid().describe("Deal UUID to attach the note to."),
196
+ body: z
197
+ .string()
198
+ .min(1)
199
+ .max(20000)
200
+ .describe("Note body — free-form markdown. Lands on the deal timeline."),
201
+ };
202
+ export async function addDealNote(client, args) {
203
+ return client.post(`/api/crm/deals/${encodeURIComponent(args.dealId)}/notes`, { body: args.body });
204
+ }
205
+ export const addDealNoteDescription = "Attach a timeline note to a CRM deal. Useful after logging a call, meeting, or observation.";
@@ -0,0 +1,137 @@
1
+ // Notifications tools — list / get_unread_count / mark_notification_read
2
+ // (Trio 161 fork 1).
3
+ //
4
+ // These wrap the existing /api/notifications endpoints (already
5
+ // reachable via API-token bearer auth — see
6
+ // backend/internal/auth/readonly_test.go). The MCP server is a
7
+ // dumb proxy: no local aggregation, no state, no polling loop.
8
+ // Long-poll subscription lands in fork 2.
9
+ //
10
+ // Why the shape:
11
+ //
12
+ // - list_notifications returns Items directly (unwrapped from
13
+ // the ListResp envelope). Total is dropped because callers
14
+ // that need pagination should hit limit / offset, not a
15
+ // total count. Matches list_tasks / list_contacts posture.
16
+ //
17
+ // - Payload is exposed as a plain object even though its shape
18
+ // varies per notification kind. Model prompts should look at
19
+ // kind first, then interpret payload accordingly. Common
20
+ // fields (title, url, actor) are documented in the schema
21
+ // description so Claude can quote them without a schema lookup.
22
+ //
23
+ // - mark_notification_read is one-at-a-time. Bulk marking (all
24
+ // of a kind, or all under a group key) is intentionally NOT
25
+ // exposed here — those are dangerous when driven by an LLM.
26
+ // If a workflow needs bulk-mark, add a purpose-specific tool
27
+ // (e.g. clear_form_submission_alerts) instead of a generic
28
+ // mark-all so the model's approval-worthy intent is explicit.
29
+ import { z } from "zod";
30
+ // -- list_notifications ------------------------------------------------
31
+ export const listNotificationsInput = {
32
+ unreadOnly: z
33
+ .boolean()
34
+ .optional()
35
+ .describe("Only return notifications where readAt is null. Use when the model asks 'what's new?'."),
36
+ kind: z
37
+ .string()
38
+ .optional()
39
+ .describe("Post-filter to a specific kind (e.g. 'crm.deal_stage_changed', 'forms.submission_received'). The backend endpoint has no kind filter yet, so we page + filter client-side; keep `limit` reasonable."),
40
+ limit: z
41
+ .number()
42
+ .int()
43
+ .min(1)
44
+ .max(100)
45
+ .optional()
46
+ .describe("Cap on returned rows (default 20, max 100)."),
47
+ offset: z
48
+ .number()
49
+ .int()
50
+ .min(0)
51
+ .optional()
52
+ .describe("Pagination offset (default 0)."),
53
+ };
54
+ export async function listNotifications(client, args) {
55
+ const params = new URLSearchParams();
56
+ if (args.unreadOnly)
57
+ params.set("unread_only", "true");
58
+ if (args.limit)
59
+ params.set("limit", String(args.limit));
60
+ if (args.offset)
61
+ params.set("offset", String(args.offset));
62
+ const qs = params.toString();
63
+ const path = `/api/notifications/${qs ? "?" + qs : ""}`;
64
+ const resp = await client.get(path);
65
+ let items = resp.items;
66
+ if (args.kind) {
67
+ items = items.filter((n) => n.kind === args.kind);
68
+ }
69
+ return items;
70
+ }
71
+ export const listNotificationsDescription = "List the token holder's recent notifications, newest-first. Use `unreadOnly` to narrow to the inbox badge count. `kind` filters client-side; when a specific kind is expected, prefer a lower `limit` (20) so filtering doesn't waste the roundtrip.";
72
+ // -- get_unread_count --------------------------------------------------
73
+ export const getUnreadCountInput = {};
74
+ export async function getUnreadCount(client) {
75
+ const resp = await client.get("/api/notifications/unread-count");
76
+ return resp.count;
77
+ }
78
+ export const getUnreadCountDescription = "Return the number of unread notifications for the token holder. Cheap (partial index lookup); safe to poll every ~30s.";
79
+ // -- mark_notification_read --------------------------------------------
80
+ export const markNotificationReadInput = {
81
+ notificationId: z
82
+ .string()
83
+ .uuid()
84
+ .describe("The notification UUID to mark as read."),
85
+ };
86
+ export async function markNotificationRead(client, args) {
87
+ await client.post(`/api/notifications/${encodeURIComponent(args.notificationId)}/mark-read`, {});
88
+ return { id: args.notificationId, status: "read" };
89
+ }
90
+ export const markNotificationReadDescription = "Mark a single notification as read. Idempotent — a second call on an already-read row succeeds silently. Errors 404 if the id doesn't belong to the token holder.";
91
+ // -- wait_for_notification (fork 2) ------------------------------------
92
+ // Server enforces its own hard cap (60s); mirror it in the schema
93
+ // so Claude doesn't waste a call by asking for 300s. Below the
94
+ // cap, the value is honored verbatim.
95
+ const WAIT_MAX_TIMEOUT_SEC = 60;
96
+ export const waitForNotificationInput = {
97
+ timeoutSeconds: z
98
+ .number()
99
+ .int()
100
+ .min(1)
101
+ .max(WAIT_MAX_TIMEOUT_SEC)
102
+ .optional()
103
+ .describe("How long to block waiting for a matching notification (1–60s, default 30). The server caps at 60s regardless."),
104
+ kinds: z
105
+ .array(z.string())
106
+ .optional()
107
+ .describe("Optional allowlist of notification kinds to wait for (e.g. ['forms.submission_received', 'crm.deal_stage_changed']). Empty / omitted = match any kind."),
108
+ since: z
109
+ .string()
110
+ .optional()
111
+ .describe("RFC 3339 timestamp. When provided, the server first checks the DB for a matching event created strictly after `since` and returns it immediately if found. Use the `createdAt` of the last notification you've handled to make polling deterministic; without this, events fired between polls are missed."),
112
+ };
113
+ export async function waitForNotification(client, args) {
114
+ const timeout = args.timeoutSeconds ?? 30;
115
+ const params = new URLSearchParams();
116
+ params.set("timeout", String(timeout));
117
+ if (args.kinds && args.kinds.length > 0) {
118
+ params.set("kinds", args.kinds.join(","));
119
+ }
120
+ if (args.since) {
121
+ params.set("since", args.since);
122
+ }
123
+ const path = `/api/notifications/wait?${params.toString()}`;
124
+ // Give the HTTP client a few extra seconds beyond the server's
125
+ // wait deadline so a slow return path doesn't manifest as a
126
+ // spurious client-side timeout.
127
+ const opts = { timeoutMs: (timeout + 5) * 1000 };
128
+ const { status, body } = await client.rawGetStatus(path, opts);
129
+ if (status === 204 || body === undefined) {
130
+ return { status: "timeout" };
131
+ }
132
+ return { status: "arrived", notification: body };
133
+ }
134
+ export const waitForNotificationDescription = "Block until a matching notification arrives (up to `timeoutSeconds`, default 30, max 60). Returns { status: 'arrived', notification } on match or { status: 'timeout' } when the wait window expired. For deterministic polling, pass `since` = the last notification's `createdAt` so events that fire between polls aren't missed. Without `since`, only events created after this call started are delivered — call list_notifications first to catch up.";
135
+ // Placeholder to satisfy TypeScript when the zod module is
136
+ // treeshaken (mirrors other tool files).
137
+ export const _z = z;