pushfa-mcp 1.2.0 → 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 +1 -2
- package/package.json +1 -1
- package/pushfa-mcp.mjs +9 -40
- package/src/client.mjs +2 -2
- package/src/config.mjs +0 -1
- package/src/drafts.mjs +63 -63
- package/src/guides.mjs +72 -72
- package/src/index.mjs +1 -1
- package/src/schemas.mjs +1 -1
- package/src/tools.mjs +7 -33
package/README.md
CHANGED
|
@@ -33,11 +33,10 @@ MCP رسمی پوشفا برای خواندن راهنمای نصب وب، ان
|
|
|
33
33
|
| `PUSHFA_API_PRIVATE_KEY` | کلید خصوصی همان سرویس |
|
|
34
34
|
| `PUSHFA_MCP_ENABLE_SEND` | مقدار رشتهای `true` برای فعالکردن ارسال |
|
|
35
35
|
| `PUSHFA_MCP_ENABLE_MANAGEMENT` | مقدار رشتهای `true` برای عملیات مدیریتی |
|
|
36
|
-
| `PUSHFA_MCP_ENABLE_IDENTITY` | مقدار رشتهای `true` برای پوشباکس و Auth Push |
|
|
37
36
|
|
|
38
37
|
با هر دو کلید، ابزارهای استعلامِ وضعیت اعلان و اشتراک، Alias، براکتها و اطلاعات تاپیک فعال میشوند. ابزارهای ارسال به شناسهٔ مخاطب، توکن FCM، Alias، Custom Alias و تاپیک، بسته به نوع اعلان و وبسرویس درخواستی، دسترسی ارسال را میخواهند. ابزارهای مدیریتی شامل تغییر Alias و براکت، عضویت تاپیک، کاربر آزمایشی و ثبت پروفایل و رویداد RetenX هستند.
|
|
39
38
|
|
|
40
|
-
دستیار ابتدا یک پیشنمایش با `pushfa_prepare_*` میگیرد. پس از تأیید شما، `pushfa_send_notification` ارسال را ثبت میکند و `
|
|
39
|
+
دستیار ابتدا یک پیشنمایش با `pushfa_prepare_*` میگیرد. پس از تأیید شما، `pushfa_send_notification` ارسال را ثبت میکند و `pushfa_confirm_management` پیشنمایش مدیریتی را اجرا میکند. شناسهٔ پیشنمایش پنج دقیقه در همان پردازش معتبر است و فقط یک بار میتوان برای اجرای عملیات از آن استفاده کرد. کلید خصوصی را در تنظیمات محلی نگه دارید. امکانات سرویس و هزینهها طبق پلن و تعرفهٔ پوشفا محاسبه میشوند.
|
|
41
40
|
|
|
42
41
|
## نمونه درخواست
|
|
43
42
|
|
package/package.json
CHANGED
package/pushfa-mcp.mjs
CHANGED
|
@@ -12,8 +12,7 @@ var serviceConfigured = Boolean(publicKey && privateKey);
|
|
|
12
12
|
var enabled = {
|
|
13
13
|
read: serviceConfigured,
|
|
14
14
|
send: serviceConfigured && process.env.PUSHFA_MCP_ENABLE_SEND === "true",
|
|
15
|
-
manage: serviceConfigured && process.env.PUSHFA_MCP_ENABLE_MANAGEMENT === "true"
|
|
16
|
-
identity: serviceConfigured && process.env.PUSHFA_MCP_ENABLE_IDENTITY === "true"
|
|
15
|
+
manage: serviceConfigured && process.env.PUSHFA_MCP_ENABLE_MANAGEMENT === "true"
|
|
17
16
|
};
|
|
18
17
|
|
|
19
18
|
// src/schemas.mjs
|
|
@@ -186,12 +185,12 @@ function unexpectedResponse(kind = "read", httpStatus) {
|
|
|
186
185
|
}
|
|
187
186
|
return new ToolError("MCP_API_UNAVAILABLE", "Could not obtain a valid response from Pushfa.", details);
|
|
188
187
|
}
|
|
189
|
-
async function callApi(endpoint, payload, {
|
|
188
|
+
async function callApi(endpoint, payload, { kind = "read", raw } = {}) {
|
|
190
189
|
let response;
|
|
191
190
|
let result;
|
|
192
191
|
try {
|
|
193
192
|
response = await fetch(apiUrl + endpoint, {
|
|
194
|
-
method,
|
|
193
|
+
method: "POST",
|
|
195
194
|
headers: { Accept: "application/json", "Content-Type": "application/json" },
|
|
196
195
|
body: JSON.stringify({ ...payload, api_public_key: publicKey, api_private_key: privateKey }),
|
|
197
196
|
redirect: "error",
|
|
@@ -501,35 +500,6 @@ apiTool("prepare_record_retenx_event", "retention/events", "Record a RetenX even
|
|
|
501
500
|
}, ["event_name"]),
|
|
502
501
|
not: { required: ["subscriber_id", "fcm_token"] }
|
|
503
502
|
}, { kind: "manage", raw: (result) => result.status === "success" });
|
|
504
|
-
apiTool("prepare_upsert_consumer_binding", "consumer-bindings/upsert", "Link a subscriber to a mobile number in Push Box.", input({
|
|
505
|
-
subscriber_id: profileId,
|
|
506
|
-
mobile: string
|
|
507
|
-
}), { kind: "identity", raw: (result) => Number.isInteger(result.binding_id) && typeof result.consumer_uuid === "string" });
|
|
508
|
-
apiTool("prepare_delete_consumer_binding", "consumer-bindings", "Revoke a Push Box binding by subscriber ID or all service bindings for one mobile number.", exactlyOne(input({
|
|
509
|
-
subscriber_id: profileId,
|
|
510
|
-
mobile: string
|
|
511
|
-
}, []), "subscriber_id", "mobile"), { kind: "identity", method: "DELETE", raw: (result) => result.ok === true });
|
|
512
|
-
apiTool("prepare_auth_push_bind", "auth-push/bind", "Bind a trusted subscriber device to an Auth Push identity.", input({
|
|
513
|
-
subscriber_id: uuid,
|
|
514
|
-
auth_identity: text(191, "Auth Push identity."),
|
|
515
|
-
expires_at: string
|
|
516
|
-
}, ["subscriber_id", "auth_identity"]), { kind: "identity" });
|
|
517
|
-
apiTool("prepare_auth_push_unbind", "auth-push/unbind", "Remove a subscriber’s trusted Auth Push binding.", input({
|
|
518
|
-
subscriber_id: uuid
|
|
519
|
-
}), { kind: "identity" });
|
|
520
|
-
apiTool("prepare_auth_push_challenge", "auth-push/challenges", "Create an approval or OTP challenge for an Auth Push identity. The client token is intended for the requesting device.", input({
|
|
521
|
-
auth_identity: text(191, "Auth Push identity."),
|
|
522
|
-
requester_subscriber_id: uuid,
|
|
523
|
-
mode: choice("approval", "otp"),
|
|
524
|
-
expires_in: integer(60, 300),
|
|
525
|
-
reference: text(191, "Application reference."),
|
|
526
|
-
context: input({ ip: string, device: text(191, "Device."), location: text(191, "Location.") }, [])
|
|
527
|
-
}, ["auth_identity", "requester_subscriber_id"]), { kind: "identity" });
|
|
528
|
-
apiTool("prepare_auth_push_consume_grant", "auth-push/grants/consume", "Consume a verified Auth Push grant once.", input({
|
|
529
|
-
challenge_id: uuid,
|
|
530
|
-
grant: { type: "string", pattern: "^[a-zA-Z0-9]{64}$" },
|
|
531
|
-
auth_identity: text(191, "Auth Push identity.")
|
|
532
|
-
}), { kind: "identity" });
|
|
533
503
|
if (enabled.send) {
|
|
534
504
|
tools.push({
|
|
535
505
|
name: "pushfa_send_notification",
|
|
@@ -539,23 +509,22 @@ if (enabled.send) {
|
|
|
539
509
|
run: ({ draft_id }) => confirmDraft(draft_id, ["send"])
|
|
540
510
|
});
|
|
541
511
|
}
|
|
542
|
-
if (enabled.manage
|
|
512
|
+
if (enabled.manage) {
|
|
543
513
|
tools.push({
|
|
544
|
-
name: "
|
|
545
|
-
description: "Execute a management
|
|
514
|
+
name: "pushfa_confirm_management",
|
|
515
|
+
description: "Execute a management draft after the user explicitly approves it. Each draft permits one attempt.",
|
|
546
516
|
inputSchema: input({ draft_id: uuid }),
|
|
547
517
|
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false },
|
|
548
|
-
run: ({ draft_id }) => confirmDraft(draft_id, ["manage"
|
|
518
|
+
run: ({ draft_id }) => confirmDraft(draft_id, ["manage"])
|
|
549
519
|
});
|
|
550
520
|
}
|
|
551
521
|
function apiTool(name, endpoint, description, inputSchema, {
|
|
552
522
|
kind = "read",
|
|
553
|
-
method = "POST",
|
|
554
523
|
raw,
|
|
555
524
|
project = asToolData
|
|
556
525
|
} = {}) {
|
|
557
526
|
if (!enabled[kind]) return;
|
|
558
|
-
const operation = { endpoint, kind,
|
|
527
|
+
const operation = { endpoint, kind, raw, project };
|
|
559
528
|
const preparing = kind !== "read";
|
|
560
529
|
tools.push({
|
|
561
530
|
name: `pushfa_${name}`,
|
|
@@ -572,7 +541,7 @@ function asToolData(data) {
|
|
|
572
541
|
// src/index.mjs
|
|
573
542
|
var modernVersion = "2026-07-28";
|
|
574
543
|
var legacyVersions = ["2025-11-25", "2025-06-18", "2025-03-26"];
|
|
575
|
-
var serverInfo = { name: "pushfa", title: "Pushfa", version: "
|
|
544
|
+
var serverInfo = { name: "pushfa", title: "Pushfa", version: "2.0.0" };
|
|
576
545
|
var capabilities = { tools: {} };
|
|
577
546
|
var instructions = [
|
|
578
547
|
"For a Pushfa installation or SDK upgrade, inspect the project and use pushfa_read_installation_guide to read the current guide for its platform before changing files. Read the relevant sections and adapt them to the existing integration. Keep private API keys, Firebase service accounts and APNs private keys out of client code.",
|
package/src/client.mjs
CHANGED
|
@@ -12,12 +12,12 @@ function unexpectedResponse(kind = 'read', httpStatus) {
|
|
|
12
12
|
return new ToolError('MCP_API_UNAVAILABLE', 'Could not obtain a valid response from Pushfa.', details);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
async function callApi(endpoint, payload, {
|
|
15
|
+
async function callApi(endpoint, payload, { kind = 'read', raw } = {}) {
|
|
16
16
|
let response;
|
|
17
17
|
let result;
|
|
18
18
|
try {
|
|
19
19
|
response = await fetch(apiUrl + endpoint, {
|
|
20
|
-
method,
|
|
20
|
+
method: 'POST',
|
|
21
21
|
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
|
|
22
22
|
body: JSON.stringify({ ...payload, api_public_key: publicKey, api_private_key: privateKey }),
|
|
23
23
|
redirect: 'error',
|
package/src/config.mjs
CHANGED
|
@@ -6,7 +6,6 @@ const enabled = {
|
|
|
6
6
|
read: serviceConfigured,
|
|
7
7
|
send: serviceConfigured && process.env.PUSHFA_MCP_ENABLE_SEND === 'true',
|
|
8
8
|
manage: serviceConfigured && process.env.PUSHFA_MCP_ENABLE_MANAGEMENT === 'true',
|
|
9
|
-
identity: serviceConfigured && process.env.PUSHFA_MCP_ENABLE_IDENTITY === 'true',
|
|
10
9
|
};
|
|
11
10
|
|
|
12
11
|
export { apiUrl, publicKey, privateKey, enabled };
|
package/src/drafts.mjs
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
|
|
3
|
-
import { callApi, unexpectedResponse } from './client.mjs';
|
|
4
|
-
import { invalidArgument, reports, ToolError, uuidPattern } from './schemas.mjs';
|
|
5
|
-
|
|
6
|
-
const draftLifetimeMs = 5 * 60 * 1000;
|
|
7
|
-
const drafts = new Map();
|
|
8
|
-
|
|
9
|
-
function prepareDraft(operation, schema, args) {
|
|
10
|
-
const payload = { ...args };
|
|
11
|
-
if (operation.kind === 'send') {
|
|
12
|
-
payload.title = args.title.trim();
|
|
13
|
-
payload.body = args.body.trim();
|
|
14
|
-
if (payload.topic !== undefined) payload.topic = payload.topic.trim();
|
|
15
|
-
if (payload.subscriber_id !== undefined) payload.subscriber_id = payload.subscriber_id.toLowerCase();
|
|
16
|
-
payload.send_time ??= 'current';
|
|
17
|
-
if ((payload.send_time === 'delay') !== (payload.time !== undefined)) {
|
|
18
|
-
throw invalidArgument('Provide time exactly when send_time is delay.');
|
|
19
|
-
}
|
|
20
|
-
for (const field of Object.keys(reports)) {
|
|
21
|
-
if (Object.hasOwn(schema.properties, field)) payload[field] ??= false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const now = Date.now();
|
|
26
|
-
for (const [id, draft] of drafts) {
|
|
27
|
-
if (draft.expiresAt <= now) drafts.delete(id);
|
|
28
|
-
}
|
|
29
|
-
if (drafts.size >= 20) {
|
|
30
|
-
throw new ToolError('MCP_DRAFT_LIMIT', 'There are 20 pending previews. Use an approved draft or wait for it to expire.');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const id = randomUUID();
|
|
34
|
-
const expiresAt = now + draftLifetimeMs;
|
|
35
|
-
drafts.set(id, { operation, payload, expiresAt });
|
|
36
|
-
const preview = Object.hasOwn(payload, 'grant') ? { ...payload, grant: '[redacted]' } : payload;
|
|
37
|
-
return { draft_id: id, expires_at: new Date(expiresAt).toISOString(), operation: operation.endpoint, preview };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function confirmDraft(draftId, kinds) {
|
|
41
|
-
const id = draftId.toLowerCase();
|
|
42
|
-
const draft = drafts.get(id);
|
|
43
|
-
if (!draft || draft.expiresAt <= Date.now()) {
|
|
44
|
-
drafts.delete(id);
|
|
45
|
-
throw new ToolError('MCP_DRAFT_UNAVAILABLE', 'This preview has expired, was already used, or belongs to a different MCP process.');
|
|
46
|
-
}
|
|
47
|
-
const { operation, payload } = draft;
|
|
48
|
-
if (!kinds.includes(operation.kind)) {
|
|
49
|
-
throw invalidArgument('Use the confirmation tool for this draft’s operation type.');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Consume before the network request, even if the outcome is unknown.
|
|
53
|
-
drafts.delete(id);
|
|
54
|
-
const data = await callApi(operation.endpoint, payload, operation);
|
|
55
|
-
if (operation.kind === 'send') {
|
|
56
|
-
const singleId = typeof data?.notification_id === 'string' && uuidPattern.test(data.notification_id);
|
|
57
|
-
if (!singleId && !Array.isArray(data?.notification_ids)) throw unexpectedResponse('send');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return { ...operation.project(data), accepted: true };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export { prepareDraft, confirmDraft };
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
import { callApi, unexpectedResponse } from './client.mjs';
|
|
4
|
+
import { invalidArgument, reports, ToolError, uuidPattern } from './schemas.mjs';
|
|
5
|
+
|
|
6
|
+
const draftLifetimeMs = 5 * 60 * 1000;
|
|
7
|
+
const drafts = new Map();
|
|
8
|
+
|
|
9
|
+
function prepareDraft(operation, schema, args) {
|
|
10
|
+
const payload = { ...args };
|
|
11
|
+
if (operation.kind === 'send') {
|
|
12
|
+
payload.title = args.title.trim();
|
|
13
|
+
payload.body = args.body.trim();
|
|
14
|
+
if (payload.topic !== undefined) payload.topic = payload.topic.trim();
|
|
15
|
+
if (payload.subscriber_id !== undefined) payload.subscriber_id = payload.subscriber_id.toLowerCase();
|
|
16
|
+
payload.send_time ??= 'current';
|
|
17
|
+
if ((payload.send_time === 'delay') !== (payload.time !== undefined)) {
|
|
18
|
+
throw invalidArgument('Provide time exactly when send_time is delay.');
|
|
19
|
+
}
|
|
20
|
+
for (const field of Object.keys(reports)) {
|
|
21
|
+
if (Object.hasOwn(schema.properties, field)) payload[field] ??= false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const now = Date.now();
|
|
26
|
+
for (const [id, draft] of drafts) {
|
|
27
|
+
if (draft.expiresAt <= now) drafts.delete(id);
|
|
28
|
+
}
|
|
29
|
+
if (drafts.size >= 20) {
|
|
30
|
+
throw new ToolError('MCP_DRAFT_LIMIT', 'There are 20 pending previews. Use an approved draft or wait for it to expire.');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const id = randomUUID();
|
|
34
|
+
const expiresAt = now + draftLifetimeMs;
|
|
35
|
+
drafts.set(id, { operation, payload, expiresAt });
|
|
36
|
+
const preview = Object.hasOwn(payload, 'grant') ? { ...payload, grant: '[redacted]' } : payload;
|
|
37
|
+
return { draft_id: id, expires_at: new Date(expiresAt).toISOString(), operation: operation.endpoint, preview };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function confirmDraft(draftId, kinds) {
|
|
41
|
+
const id = draftId.toLowerCase();
|
|
42
|
+
const draft = drafts.get(id);
|
|
43
|
+
if (!draft || draft.expiresAt <= Date.now()) {
|
|
44
|
+
drafts.delete(id);
|
|
45
|
+
throw new ToolError('MCP_DRAFT_UNAVAILABLE', 'This preview has expired, was already used, or belongs to a different MCP process.');
|
|
46
|
+
}
|
|
47
|
+
const { operation, payload } = draft;
|
|
48
|
+
if (!kinds.includes(operation.kind)) {
|
|
49
|
+
throw invalidArgument('Use the confirmation tool for this draft’s operation type.');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Consume before the network request, even if the outcome is unknown.
|
|
53
|
+
drafts.delete(id);
|
|
54
|
+
const data = await callApi(operation.endpoint, payload, operation);
|
|
55
|
+
if (operation.kind === 'send') {
|
|
56
|
+
const singleId = typeof data?.notification_id === 'string' && uuidPattern.test(data.notification_id);
|
|
57
|
+
if (!singleId && !Array.isArray(data?.notification_ids)) throw unexpectedResponse('send');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return { ...operation.project(data), accepted: true };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { prepareDraft, confirmDraft };
|
package/src/guides.mjs
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
|
|
3
|
-
import { invalidArgument, ToolError } from './schemas.mjs';
|
|
4
|
-
|
|
5
|
-
const guideUrls = {
|
|
6
|
-
web: 'https://pushfa.com/index/doc/download/pushfa-web-push-complete-guide-fa.md',
|
|
7
|
-
android: 'https://pushfa.com/index/doc/download/pushfa-android-push-complete-guide-fa.md',
|
|
8
|
-
ios: 'https://pushfa.com/index/doc/download/pushfa-ios-push-complete-guide-fa.md',
|
|
9
|
-
};
|
|
10
|
-
const guidePageSize = 4000;
|
|
11
|
-
|
|
12
|
-
async function fetchGuide(url) {
|
|
13
|
-
let response;
|
|
14
|
-
try {
|
|
15
|
-
response = await fetch(url, {
|
|
16
|
-
headers: { Accept: 'text/markdown' },
|
|
17
|
-
cache: 'no-store',
|
|
18
|
-
redirect: 'error',
|
|
19
|
-
signal: AbortSignal.timeout(20_000),
|
|
20
|
-
});
|
|
21
|
-
const contentType = response.headers.get('content-type')?.split(';', 1)[0].trim().toLowerCase();
|
|
22
|
-
if (response.ok && contentType === 'text/markdown') {
|
|
23
|
-
const markdown = await response.text();
|
|
24
|
-
if (markdown.trim()) return markdown;
|
|
25
|
-
} else {
|
|
26
|
-
await response.body?.cancel();
|
|
27
|
-
}
|
|
28
|
-
} catch {
|
|
29
|
-
// Report the official source even when the download fails.
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
throw new ToolError('MCP_GUIDE_UNAVAILABLE', 'Could not read the current Pushfa guide from its official URL.', {
|
|
33
|
-
url, http_status: response?.status,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function readInstallationGuide({ platform, offset = 0, revision }) {
|
|
38
|
-
if (offset > 0 && revision === undefined) {
|
|
39
|
-
throw invalidArgument('Use the returned revision when requesting a guide page or section.');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const url = guideUrls[platform];
|
|
43
|
-
const markdown = await fetchGuide(url);
|
|
44
|
-
const currentRevision = createHash('sha256').update(markdown).digest('hex');
|
|
45
|
-
if (revision !== undefined && revision !== currentRevision) {
|
|
46
|
-
throw new ToolError('MCP_GUIDE_CHANGED', 'The guide changed. Restart reading with the platform only to get the updated sections.', { url });
|
|
47
|
-
}
|
|
48
|
-
if (offset >= markdown.length) throw invalidArgument('The guide offset is out of range.');
|
|
49
|
-
|
|
50
|
-
let end = Math.min(offset + guidePageSize, markdown.length);
|
|
51
|
-
if (end < markdown.length) {
|
|
52
|
-
const newline = markdown.lastIndexOf('\n', end - 1);
|
|
53
|
-
if (newline >= offset) end = newline + 1;
|
|
54
|
-
else if (markdown.codePointAt(end - 1) > 0xffff) end--;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const page = {
|
|
58
|
-
platform,
|
|
59
|
-
url,
|
|
60
|
-
revision: currentRevision,
|
|
61
|
-
markdown: markdown.slice(offset, end),
|
|
62
|
-
next_offset: end < markdown.length ? end : null,
|
|
63
|
-
};
|
|
64
|
-
if (offset === 0) {
|
|
65
|
-
page.sections = Array.from(markdown.matchAll(/^##[ \t]+(.+)$/gm), heading => ({
|
|
66
|
-
title: heading[1].trim(), offset: heading.index,
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
69
|
-
return page;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export { guideUrls, readInstallationGuide };
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
import { invalidArgument, ToolError } from './schemas.mjs';
|
|
4
|
+
|
|
5
|
+
const guideUrls = {
|
|
6
|
+
web: 'https://pushfa.com/index/doc/download/pushfa-web-push-complete-guide-fa.md',
|
|
7
|
+
android: 'https://pushfa.com/index/doc/download/pushfa-android-push-complete-guide-fa.md',
|
|
8
|
+
ios: 'https://pushfa.com/index/doc/download/pushfa-ios-push-complete-guide-fa.md',
|
|
9
|
+
};
|
|
10
|
+
const guidePageSize = 4000;
|
|
11
|
+
|
|
12
|
+
async function fetchGuide(url) {
|
|
13
|
+
let response;
|
|
14
|
+
try {
|
|
15
|
+
response = await fetch(url, {
|
|
16
|
+
headers: { Accept: 'text/markdown' },
|
|
17
|
+
cache: 'no-store',
|
|
18
|
+
redirect: 'error',
|
|
19
|
+
signal: AbortSignal.timeout(20_000),
|
|
20
|
+
});
|
|
21
|
+
const contentType = response.headers.get('content-type')?.split(';', 1)[0].trim().toLowerCase();
|
|
22
|
+
if (response.ok && contentType === 'text/markdown') {
|
|
23
|
+
const markdown = await response.text();
|
|
24
|
+
if (markdown.trim()) return markdown;
|
|
25
|
+
} else {
|
|
26
|
+
await response.body?.cancel();
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
// Report the official source even when the download fails.
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
throw new ToolError('MCP_GUIDE_UNAVAILABLE', 'Could not read the current Pushfa guide from its official URL.', {
|
|
33
|
+
url, http_status: response?.status,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function readInstallationGuide({ platform, offset = 0, revision }) {
|
|
38
|
+
if (offset > 0 && revision === undefined) {
|
|
39
|
+
throw invalidArgument('Use the returned revision when requesting a guide page or section.');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const url = guideUrls[platform];
|
|
43
|
+
const markdown = await fetchGuide(url);
|
|
44
|
+
const currentRevision = createHash('sha256').update(markdown).digest('hex');
|
|
45
|
+
if (revision !== undefined && revision !== currentRevision) {
|
|
46
|
+
throw new ToolError('MCP_GUIDE_CHANGED', 'The guide changed. Restart reading with the platform only to get the updated sections.', { url });
|
|
47
|
+
}
|
|
48
|
+
if (offset >= markdown.length) throw invalidArgument('The guide offset is out of range.');
|
|
49
|
+
|
|
50
|
+
let end = Math.min(offset + guidePageSize, markdown.length);
|
|
51
|
+
if (end < markdown.length) {
|
|
52
|
+
const newline = markdown.lastIndexOf('\n', end - 1);
|
|
53
|
+
if (newline >= offset) end = newline + 1;
|
|
54
|
+
else if (markdown.codePointAt(end - 1) > 0xffff) end--;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const page = {
|
|
58
|
+
platform,
|
|
59
|
+
url,
|
|
60
|
+
revision: currentRevision,
|
|
61
|
+
markdown: markdown.slice(offset, end),
|
|
62
|
+
next_offset: end < markdown.length ? end : null,
|
|
63
|
+
};
|
|
64
|
+
if (offset === 0) {
|
|
65
|
+
page.sections = Array.from(markdown.matchAll(/^##[ \t]+(.+)$/gm), heading => ({
|
|
66
|
+
title: heading[1].trim(), offset: heading.index,
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
return page;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { guideUrls, readInstallationGuide };
|
package/src/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { tools } from './tools.mjs';
|
|
|
8
8
|
|
|
9
9
|
const modernVersion = '2026-07-28';
|
|
10
10
|
const legacyVersions = ['2025-11-25', '2025-06-18', '2025-03-26'];
|
|
11
|
-
const serverInfo = { name: 'pushfa', title: 'Pushfa', version: '
|
|
11
|
+
const serverInfo = { name: 'pushfa', title: 'Pushfa', version: '2.0.0' };
|
|
12
12
|
const capabilities = { tools: {} };
|
|
13
13
|
const instructions = [
|
|
14
14
|
'For a Pushfa installation or SDK upgrade, inspect the project and use pushfa_read_installation_guide to read the current guide for its platform before changing files. Read the relevant sections and adapt them to the existing integration. Keep private API keys, Firebase service accounts and APNs private keys out of client code.',
|
package/src/schemas.mjs
CHANGED
|
@@ -154,7 +154,7 @@ function validateObject(value, schema, field) {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
export {
|
|
157
|
-
isObject, uuidPattern, uuid, text, list, input,
|
|
157
|
+
isObject, uuidPattern, uuid, text, list, input, string, bool, choice, integer, fcmToken,
|
|
158
158
|
deviceInput, topicId, groupInput, message, actions, reports, webhook, audience, aliasAudience,
|
|
159
159
|
profileId, keyName, scalarMap, profileFields, ToolError, invalidArgument, validate,
|
|
160
160
|
};
|
package/src/tools.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { enabled } from './config.mjs';
|
|
|
3
3
|
import { confirmDraft, prepareDraft } from './drafts.mjs';
|
|
4
4
|
import { guideUrls, readInstallationGuide } from './guides.mjs';
|
|
5
5
|
import {
|
|
6
|
-
actions, aliasAudience, audience, bool, choice, deviceInput,
|
|
6
|
+
actions, aliasAudience, audience, bool, choice, deviceInput, fcmToken, groupInput, input,
|
|
7
7
|
integer, isObject, keyName, list, message, profileFields, profileId, reports, scalarMap, string, text,
|
|
8
8
|
topicId, uuid, uuidPattern, webhook,
|
|
9
9
|
} from './schemas.mjs';
|
|
@@ -150,32 +150,6 @@ apiTool('prepare_record_retenx_event', 'retention/events', 'Record a RetenX even
|
|
|
150
150
|
not: { required: ['subscriber_id', 'fcm_token'] },
|
|
151
151
|
}, { kind: 'manage', raw: result => result.status === 'success' });
|
|
152
152
|
|
|
153
|
-
apiTool('prepare_upsert_consumer_binding', 'consumer-bindings/upsert', 'Link a subscriber to a mobile number in Push Box.', input({
|
|
154
|
-
subscriber_id: profileId, mobile: string,
|
|
155
|
-
}), { kind: 'identity', raw: result => Number.isInteger(result.binding_id) && typeof result.consumer_uuid === 'string' });
|
|
156
|
-
apiTool('prepare_delete_consumer_binding', 'consumer-bindings', 'Revoke a Push Box binding by subscriber ID or all service bindings for one mobile number.', exactlyOne(input({
|
|
157
|
-
subscriber_id: profileId, mobile: string,
|
|
158
|
-
}, []), 'subscriber_id', 'mobile'), { kind: 'identity', method: 'DELETE', raw: result => result.ok === true });
|
|
159
|
-
apiTool('prepare_auth_push_bind', 'auth-push/bind', 'Bind a trusted subscriber device to an Auth Push identity.', input({
|
|
160
|
-
subscriber_id: uuid, auth_identity: text(191, 'Auth Push identity.'), expires_at: string,
|
|
161
|
-
}, ['subscriber_id', 'auth_identity']), { kind: 'identity' });
|
|
162
|
-
apiTool('prepare_auth_push_unbind', 'auth-push/unbind', 'Remove a subscriber’s trusted Auth Push binding.', input({
|
|
163
|
-
subscriber_id: uuid,
|
|
164
|
-
}), { kind: 'identity' });
|
|
165
|
-
apiTool('prepare_auth_push_challenge', 'auth-push/challenges', 'Create an approval or OTP challenge for an Auth Push identity. The client token is intended for the requesting device.', input({
|
|
166
|
-
auth_identity: text(191, 'Auth Push identity.'),
|
|
167
|
-
requester_subscriber_id: uuid,
|
|
168
|
-
mode: choice('approval', 'otp'),
|
|
169
|
-
expires_in: integer(60, 300),
|
|
170
|
-
reference: text(191, 'Application reference.'),
|
|
171
|
-
context: input({ ip: string, device: text(191, 'Device.'), location: text(191, 'Location.') }, []),
|
|
172
|
-
}, ['auth_identity', 'requester_subscriber_id']), { kind: 'identity' });
|
|
173
|
-
apiTool('prepare_auth_push_consume_grant', 'auth-push/grants/consume', 'Consume a verified Auth Push grant once.', input({
|
|
174
|
-
challenge_id: uuid,
|
|
175
|
-
grant: { type: 'string', pattern: '^[a-zA-Z0-9]{64}$' },
|
|
176
|
-
auth_identity: text(191, 'Auth Push identity.'),
|
|
177
|
-
}), { kind: 'identity' });
|
|
178
|
-
|
|
179
153
|
if (enabled.send) {
|
|
180
154
|
tools.push({
|
|
181
155
|
name: 'pushfa_send_notification',
|
|
@@ -186,22 +160,22 @@ if (enabled.send) {
|
|
|
186
160
|
});
|
|
187
161
|
}
|
|
188
162
|
|
|
189
|
-
if (enabled.manage
|
|
163
|
+
if (enabled.manage) {
|
|
190
164
|
tools.push({
|
|
191
|
-
name: '
|
|
192
|
-
description: 'Execute a management
|
|
165
|
+
name: 'pushfa_confirm_management',
|
|
166
|
+
description: 'Execute a management draft after the user explicitly approves it. Each draft permits one attempt.',
|
|
193
167
|
inputSchema: input({ draft_id: uuid }),
|
|
194
168
|
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false },
|
|
195
|
-
run: ({ draft_id }) => confirmDraft(draft_id, ['manage'
|
|
169
|
+
run: ({ draft_id }) => confirmDraft(draft_id, ['manage']),
|
|
196
170
|
});
|
|
197
171
|
}
|
|
198
172
|
|
|
199
173
|
function apiTool(name, endpoint, description, inputSchema, {
|
|
200
|
-
kind = 'read',
|
|
174
|
+
kind = 'read', raw, project = asToolData,
|
|
201
175
|
} = {}) {
|
|
202
176
|
if (!enabled[kind]) return;
|
|
203
177
|
|
|
204
|
-
const operation = { endpoint, kind,
|
|
178
|
+
const operation = { endpoint, kind, raw, project };
|
|
205
179
|
const preparing = kind !== 'read';
|
|
206
180
|
tools.push({
|
|
207
181
|
name: `pushfa_${name}`,
|