pushfa-mcp 0.0.0-stage → 2.0.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.
- package/README.md +56 -2
- package/package.json +18 -4
- package/pushfa-mcp.mjs +628 -0
- package/src/client.mjs +59 -0
- package/src/config.mjs +11 -0
- package/src/drafts.mjs +63 -0
- package/src/guides.mjs +72 -0
- package/src/index.mjs +111 -0
- package/src/schemas.mjs +160 -0
- package/src/tools.mjs +197 -0
package/src/tools.mjs
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { callApi, unexpectedResponse } from './client.mjs';
|
|
2
|
+
import { enabled } from './config.mjs';
|
|
3
|
+
import { confirmDraft, prepareDraft } from './drafts.mjs';
|
|
4
|
+
import { guideUrls, readInstallationGuide } from './guides.mjs';
|
|
5
|
+
import {
|
|
6
|
+
actions, aliasAudience, audience, bool, choice, deviceInput, fcmToken, groupInput, input,
|
|
7
|
+
integer, isObject, keyName, list, message, profileFields, profileId, reports, scalarMap, string, text,
|
|
8
|
+
topicId, uuid, uuidPattern, webhook,
|
|
9
|
+
} from './schemas.mjs';
|
|
10
|
+
|
|
11
|
+
const tools = [
|
|
12
|
+
{
|
|
13
|
+
name: 'pushfa_read_installation_guide',
|
|
14
|
+
description: 'Read the current official Markdown guide before installing or upgrading Pushfa in a Web Push, native Android, or native iOS project. The first page includes section offsets; continue with next_offset or jump to a section using the returned revision.',
|
|
15
|
+
inputSchema: input({
|
|
16
|
+
platform: { ...choice(...Object.keys(guideUrls)), description: 'Use web for websites and PWAs, including Web Push on iOS.' },
|
|
17
|
+
offset: { ...integer(0), description: 'Omit for the first page, or pass next_offset or a section offset from this guide.' },
|
|
18
|
+
revision: { type: 'string', pattern: '^[a-f0-9]{64}$', description: 'Required when reading from a nonzero offset. Use the returned revision.' },
|
|
19
|
+
}, ['platform']),
|
|
20
|
+
annotations: { readOnlyHint: true },
|
|
21
|
+
run: readInstallationGuide,
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
if (enabled.read) tools.push(
|
|
26
|
+
{
|
|
27
|
+
name: 'pushfa_get_subscriber_state',
|
|
28
|
+
description: 'Check whether up to 25 known Pushfa subscriber IDs exist and have an active push subscription. Includes topic IDs.',
|
|
29
|
+
inputSchema: input({ subscriber_ids: list(text(191, 'A Pushfa subscriber ID.'), 25) }),
|
|
30
|
+
annotations: { readOnlyHint: true },
|
|
31
|
+
run: async ({ subscriber_ids }) => {
|
|
32
|
+
const ids = [...new Set(subscriber_ids.map(id => id.trim()).map(id => uuidPattern.test(id) ? id.toLowerCase() : id))];
|
|
33
|
+
const data = await callApi('subscribers/state', { subscriber_ids: ids });
|
|
34
|
+
if (!Array.isArray(data?.subscribers)) throw unexpectedResponse();
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
subscribers: data.subscribers.map(({ subscriber_id, exists, has_push, invalidated_at, topics }) => ({
|
|
38
|
+
subscriber_id,
|
|
39
|
+
exists,
|
|
40
|
+
push_active: has_push,
|
|
41
|
+
invalidated_at: invalidated_at ?? null,
|
|
42
|
+
topic_ids: topics ?? [],
|
|
43
|
+
})),
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'pushfa_get_notification_status',
|
|
49
|
+
description: 'Check queue, send, delivery and click status for up to 1000 notification IDs. Returns the failure code for failed sends.',
|
|
50
|
+
inputSchema: input({ notification_ids: list(uuid, 1000) }),
|
|
51
|
+
annotations: { readOnlyHint: true },
|
|
52
|
+
run: async ({ notification_ids }) => {
|
|
53
|
+
const ids = [...new Set(notification_ids.map(id => id.toLowerCase()))];
|
|
54
|
+
const data = await callApi('check-notification-status', { notification_ids: ids });
|
|
55
|
+
if (!Array.isArray(data?.[0])) throw unexpectedResponse();
|
|
56
|
+
|
|
57
|
+
const notifications = data[0].map(({ id, status, is_clicked, send_at, sent_at, delivered_at, clicked_at, failure_code }) => ({
|
|
58
|
+
notification_id: id, status, is_clicked, send_at, sent_at, delivered_at, clicked_at, failure_code,
|
|
59
|
+
}));
|
|
60
|
+
const found = new Set(notifications.map(row => row.notification_id.toLowerCase()));
|
|
61
|
+
|
|
62
|
+
return { notifications, missing_notification_ids: ids.filter(id => !found.has(id)) };
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// Backend routes under /api/webservices. Each preparation tool binds the
|
|
68
|
+
// exact method, endpoint, and arguments to its one-use confirmation ID.
|
|
69
|
+
apiTool('get_alias', 'alias/get', 'Get the primary alias for a subscriber.', deviceInput());
|
|
70
|
+
apiTool('get_custom_aliases', 'aliases/get', 'Get a subscriber’s labeled custom aliases.', deviceInput());
|
|
71
|
+
apiTool('get_brackets', 'brackets/get', 'Get a subscriber’s personalization properties.', deviceInput());
|
|
72
|
+
apiTool('get_user_topics', 'topics/user-topics', 'Get the topics a subscriber belongs to.', deviceInput(), {
|
|
73
|
+
project: topics => ({ topics }),
|
|
74
|
+
});
|
|
75
|
+
apiTool('get_topic_members', 'topics/topic-members', 'Get up to 100 topic members with subscriber ID, device and active push status.', input({ topic_uuid: topicId }), {
|
|
76
|
+
project: members => ({
|
|
77
|
+
members: members.map(({ subscriber_id, device, is_valid, token }) => ({
|
|
78
|
+
subscriber_id, device, push_active: is_valid === true && Boolean(token),
|
|
79
|
+
})),
|
|
80
|
+
}),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
apiTool('prepare_notification', 'send-single-message', 'Send one normal notification by subscriber_id or fcm_token.', deviceInput(
|
|
84
|
+
{ ...message, ...actions, ...reports, ...webhook }, ['title', 'body'],
|
|
85
|
+
), { kind: 'send' });
|
|
86
|
+
apiTool('prepare_lite_notification', 'send-single-lite-message', 'Send one Lite notification by subscriber_id or fcm_token.', deviceInput(
|
|
87
|
+
message, ['title', 'body'],
|
|
88
|
+
), { kind: 'send' });
|
|
89
|
+
apiTool('prepare_group_notification', 'send-group-message', 'Send normal notifications to subscriber IDs, FCM tokens, or a topic, with optional reports.', groupInput(
|
|
90
|
+
{ ...message, ...actions, ...reports, ...webhook, ...audience },
|
|
91
|
+
), { kind: 'send' });
|
|
92
|
+
apiTool('prepare_group_lite_notification', 'send-group-lite-message', 'Send Lite notifications to subscriber IDs, FCM tokens, or a topic.', groupInput(
|
|
93
|
+
{ ...message, ...audience },
|
|
94
|
+
), { kind: 'send' });
|
|
95
|
+
apiTool('prepare_send_via_alias', 'send-via-user-alias-id', 'Send to devices matching the primary alias (external ID).', input({
|
|
96
|
+
alias: text(255, 'Primary alias.'), ...message, ...actions, ...reports, ...aliasAudience,
|
|
97
|
+
}, ['alias', 'title', 'body']), { kind: 'send' });
|
|
98
|
+
apiTool('prepare_send_via_subscriber_id', 'send-via-subscriber-id', 'Send to one or more subscriber IDs and get per-recipient results.', input({
|
|
99
|
+
subscriber_ids: list(profileId), ...message, ...actions, ...reports, ...audience,
|
|
100
|
+
}, ['subscriber_ids', 'title', 'body']), { kind: 'send' });
|
|
101
|
+
apiTool('prepare_send_via_custom_alias', 'send-via-alias', 'Send to subscribers whose custom alias label matches any supplied value.', input({
|
|
102
|
+
label: keyName, values: list(text(191, 'Custom alias value.'), 100), ...message, ...actions, ...reports, ...aliasAudience,
|
|
103
|
+
}, ['label', 'values', 'title', 'body']), { kind: 'send' });
|
|
104
|
+
apiTool('prepare_send_to_topic', 'send-quickly-to-topic', 'Send to a topic with the dedicated topic webservice.', input({
|
|
105
|
+
topic: topicId, ...message, ...actions,
|
|
106
|
+
}, ['topic', 'title', 'body']), { kind: 'send' });
|
|
107
|
+
|
|
108
|
+
apiTool('prepare_set_alias', 'alias/set', 'Set the primary alias for a subscriber.', deviceInput({
|
|
109
|
+
alias: text(191, 'Primary alias.'),
|
|
110
|
+
}), { kind: 'manage' });
|
|
111
|
+
apiTool('prepare_delete_alias', 'alias/delete', 'Delete the primary alias for a subscriber.', deviceInput(), { kind: 'manage' });
|
|
112
|
+
apiTool('prepare_add_custom_aliases', 'aliases/add', 'Add or update a subscriber’s labeled custom aliases.', deviceInput({
|
|
113
|
+
aliases: scalarMap(191),
|
|
114
|
+
}), { kind: 'manage' });
|
|
115
|
+
apiTool('prepare_remove_custom_aliases', 'aliases/remove', 'Remove selected custom alias labels from a subscriber.', deviceInput({
|
|
116
|
+
labels: list(keyName, 50),
|
|
117
|
+
}), { kind: 'manage' });
|
|
118
|
+
apiTool('prepare_add_brackets', 'brackets/add', 'Add or update a subscriber’s personalization properties.', deviceInput({
|
|
119
|
+
brackets: scalarMap(1000),
|
|
120
|
+
}), { kind: 'manage' });
|
|
121
|
+
apiTool('prepare_remove_brackets', 'brackets/remove', 'Remove selected personalization properties from a subscriber.', deviceInput({
|
|
122
|
+
keys: list(keyName, 50),
|
|
123
|
+
}), { kind: 'manage' });
|
|
124
|
+
apiTool('prepare_set_test_user', 'test-user/set', 'Mark a subscriber as a test user.', deviceInput(), { kind: 'manage' });
|
|
125
|
+
apiTool('prepare_unset_test_user', 'test-user/unset', 'Remove a subscriber’s test user flag.', deviceInput(), { kind: 'manage' });
|
|
126
|
+
apiTool('prepare_create_topic', 'topics/create', 'Create a topic and set its optional membership and JavaScript permissions.', input({
|
|
127
|
+
name: text(255, 'Topic name.'),
|
|
128
|
+
send_membership_notification: bool,
|
|
129
|
+
allow_js_register: bool,
|
|
130
|
+
allow_js_unregister: bool,
|
|
131
|
+
allow_js_get: bool,
|
|
132
|
+
}, ['name']), { kind: 'manage' });
|
|
133
|
+
apiTool('prepare_subscribe_to_topic', 'topics/subscribe', 'Subscribe a subscriber to a topic.', deviceInput({ topic_uuid: topicId }), { kind: 'manage' });
|
|
134
|
+
apiTool('prepare_unsubscribe_from_topic', 'topics/unsubscribe', 'Unsubscribe a subscriber from a topic.', deviceInput({ topic_uuid: topicId }), { kind: 'manage' });
|
|
135
|
+
apiTool('prepare_upsert_retenx_profile', 'retention/profiles/upsert', 'Create or update a RetenX profile by subscriber ID, external ID or custom aliases.', {
|
|
136
|
+
...input({ ...profileFields, aliases: { ...profileFields.aliases, minProperties: 1 } }, []),
|
|
137
|
+
anyOf: ['subscriber_id', 'external_id', 'aliases'].map(key => ({ required: [key] })),
|
|
138
|
+
}, { kind: 'manage', raw: result => isObject(result.data), project: result => result.data });
|
|
139
|
+
apiTool('prepare_record_retenx_event', 'retention/events', 'Record a RetenX event. Active campaigns can act on it.', {
|
|
140
|
+
...input({
|
|
141
|
+
...profileFields,
|
|
142
|
+
fcm_token: fcmToken,
|
|
143
|
+
identity_key: keyName,
|
|
144
|
+
identity_value: text(191, 'Custom identity value.'),
|
|
145
|
+
event_name: text(128, 'RetenX event name.'),
|
|
146
|
+
event_time: { ...string, description: 'Optional event timestamp with timezone.' },
|
|
147
|
+
idempotency_key: uuid,
|
|
148
|
+
params: { type: ['object', 'array', 'string'], description: 'Event parameters or a JSON-encoded parameter map.' },
|
|
149
|
+
}, ['event_name']),
|
|
150
|
+
not: { required: ['subscriber_id', 'fcm_token'] },
|
|
151
|
+
}, { kind: 'manage', raw: result => result.status === 'success' });
|
|
152
|
+
|
|
153
|
+
if (enabled.send) {
|
|
154
|
+
tools.push({
|
|
155
|
+
name: 'pushfa_send_notification',
|
|
156
|
+
description: 'Submit an approved send draft. Returns notification IDs and any rejected recipients. Standard Pushfa fees apply. Each draft permits one attempt.',
|
|
157
|
+
inputSchema: input({ draft_id: uuid }),
|
|
158
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false },
|
|
159
|
+
run: ({ draft_id }) => confirmDraft(draft_id, ['send']),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (enabled.manage) {
|
|
164
|
+
tools.push({
|
|
165
|
+
name: 'pushfa_confirm_management',
|
|
166
|
+
description: 'Execute a management draft after the user explicitly approves it. Each draft permits one attempt.',
|
|
167
|
+
inputSchema: input({ draft_id: uuid }),
|
|
168
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false },
|
|
169
|
+
run: ({ draft_id }) => confirmDraft(draft_id, ['manage']),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function apiTool(name, endpoint, description, inputSchema, {
|
|
174
|
+
kind = 'read', raw, project = asToolData,
|
|
175
|
+
} = {}) {
|
|
176
|
+
if (!enabled[kind]) return;
|
|
177
|
+
|
|
178
|
+
const operation = { endpoint, kind, raw, project };
|
|
179
|
+
const preparing = kind !== 'read';
|
|
180
|
+
tools.push({
|
|
181
|
+
name: `pushfa_${name}`,
|
|
182
|
+
description: preparing ? `${description} Preview only. Show the preview and request approval.` : description,
|
|
183
|
+
inputSchema,
|
|
184
|
+
annotations: preparing
|
|
185
|
+
? { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
186
|
+
: { readOnlyHint: true },
|
|
187
|
+
run: preparing
|
|
188
|
+
? args => prepareDraft(operation, inputSchema, args)
|
|
189
|
+
: async args => project(await callApi(endpoint, args)),
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function asToolData(data) {
|
|
194
|
+
return isObject(data) ? data : { data };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export { tools };
|