@aisocialautomate/mcp 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +87 -2
- package/catalog/endpoints.json +5555 -0
- package/dist/api.js +83 -0
- package/dist/catalog.js +60 -0
- package/dist/config.js +24 -0
- package/dist/http-app.js +292 -0
- package/dist/http.js +13 -0
- package/dist/net-guard.js +155 -0
- package/dist/oauth.js +339 -0
- package/dist/publishing.js +479 -0
- package/dist/server.js +494 -0
- package/dist/slim.js +69 -0
- package/dist/stdio.js +12 -0
- package/dist/time.js +56 -0
- package/dist/toolsets.js +68 -0
- package/dist/usage.js +130 -0
- package/package.json +54 -4
package/dist/toolsets.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Which group each tool belongs to. Used to switch groups on or off (SOCIAL_AUTOMATE_TOOLSETS) and to build the docs. */
|
|
2
|
+
export const TOOLSETS = ['discover', 'research', 'leads', 'publishing'];
|
|
3
|
+
export const TOOL_TOOLSET = {
|
|
4
|
+
whoami: 'discover', get_credit_balance: 'discover', get_pricing: 'discover', list_connected_accounts: 'discover', connect_account: 'discover', list_brands: 'discover', usage_status: 'discover',
|
|
5
|
+
list_platforms: 'research', search_endpoints: 'research', describe_endpoint: 'research',
|
|
6
|
+
scrape: 'research', start_bulk_scrape: 'research', get_run: 'research', list_runs: 'research', cancel_run: 'research',
|
|
7
|
+
start_lead_job: 'leads', get_lead_job: 'leads', list_lead_jobs: 'leads', cancel_lead_job: 'leads', search_leads: 'leads', export_leads: 'leads', list_lead_lists: 'leads', create_lead_list: 'leads', add_leads_to_list: 'leads',
|
|
8
|
+
list_posts: 'publishing', get_post: 'publishing', get_post_analytics: 'publishing', list_templates: 'publishing', get_tiktok_creator_info: 'publishing', search_instagram_music: 'publishing', upload_media: 'publishing', create_draft: 'publishing', schedule_post: 'publishing', publish_now: 'publishing', update_post: 'publishing', cancel_post: 'publishing', restore_post: 'publishing', duplicate_post: 'publishing', delete_post: 'publishing',
|
|
9
|
+
};
|
|
10
|
+
/** Descriptions for parameters, applied when a tool is registered (a schema's own .describe() wins). A "tool.param" key overrides the plain name. */
|
|
11
|
+
export const PARAM_DOCS = {
|
|
12
|
+
platform: 'The platform: instagram, facebook, linkedin, tiktok, twitter (X) or youtube.',
|
|
13
|
+
'search_endpoints.platform': 'Only search this platform. Omit to search all of them.',
|
|
14
|
+
'list_runs.platform': 'Only runs on this platform.',
|
|
15
|
+
'search_leads.platform': 'Only leads from this platform.',
|
|
16
|
+
endpoint_key: 'The endpoint key, for example tt_user_followers. Find it with search_endpoints.',
|
|
17
|
+
params: 'The endpoint\'s parameters, as listed by describe_endpoint.',
|
|
18
|
+
limit: 'How many items to return.',
|
|
19
|
+
'search_endpoints.limit': 'Maximum matches to return (default 12).',
|
|
20
|
+
'get_run.limit': 'Items to return per page (default 20, max 100).',
|
|
21
|
+
'list_runs.limit': 'Runs to return (default 20).',
|
|
22
|
+
'search_leads.limit': 'Leads to return (default 25, max 100).',
|
|
23
|
+
'list_lead_jobs.limit': 'Jobs to return (default 20).',
|
|
24
|
+
'list_posts.limit': 'Posts to return (default 20, max 100).',
|
|
25
|
+
offset: 'Skip this many items, to page through a large result.',
|
|
26
|
+
'get_run.fields': 'Only these fields per item, as dotted paths, e.g. ["unique_id","stats.followerCount"].',
|
|
27
|
+
dry_run: 'Only show the cost estimate and warnings. Nothing is spent or started.',
|
|
28
|
+
'update_post.dry_run': 'Only show which fields would change. Nothing is saved.',
|
|
29
|
+
confirm: 'Set true only after the user has seen the estimate or preview and agreed.',
|
|
30
|
+
run_id: 'The run id returned by start_bulk_scrape (or listed by list_runs).',
|
|
31
|
+
search_type: 'What to search by. The valid values depend on the platform (see the list above).',
|
|
32
|
+
min_followers: 'Only leads with at least this many followers.',
|
|
33
|
+
max_followers: 'Only leads with at most this many followers.',
|
|
34
|
+
advanced_filters: 'Platform-specific advanced filters, as an object.',
|
|
35
|
+
ai_quality_filter: 'Run profiles through AI profile validation.',
|
|
36
|
+
email_validation: 'Validate discovered email addresses (adds a small cost per 1,000 profiles).',
|
|
37
|
+
deduplicate: 'Skip leads that were gathered before (default true).',
|
|
38
|
+
job_id: 'The lead job id.',
|
|
39
|
+
'search_leads.job_id': 'Only leads gathered by this job.',
|
|
40
|
+
has_email: 'true: only leads with an email address. false: only leads without one.',
|
|
41
|
+
verified_only: 'Only verified accounts.',
|
|
42
|
+
cursor: 'The next_cursor from the previous page of results.',
|
|
43
|
+
'list_lead_jobs.status': 'Only jobs with this status.',
|
|
44
|
+
'list_posts.status': 'Only posts with this status.',
|
|
45
|
+
'update_post.status': '"draft" or "scheduled". "scheduled" puts a draft on the schedule and needs the user\'s confirmation.',
|
|
46
|
+
archived: 'true to list archived lists instead of active ones.',
|
|
47
|
+
name: 'Name of the list (up to 200 characters).',
|
|
48
|
+
list_id: 'The lead list id, from list_lead_lists.',
|
|
49
|
+
lead_ids: 'Lead ids as returned by search_leads (up to 500).',
|
|
50
|
+
post_id: 'The post id, from list_posts or a create tool.',
|
|
51
|
+
query: 'Search text, such as a song or artist. Leave empty for trending audio.',
|
|
52
|
+
type: '"music" or "original_sound".',
|
|
53
|
+
social_account_id: 'Account id from list_connected_accounts. Omit to use the connected account.',
|
|
54
|
+
brand_id: 'A brand id from list_brands. Omit for all brands (lists) or the targeted accounts\' brand (create_draft, schedule_post, publish_now).',
|
|
55
|
+
file_path: 'A file on this computer (local mode only).',
|
|
56
|
+
url: 'A public http(s) link to the image or video.',
|
|
57
|
+
filename: 'Name to store the file under. Its extension decides the type.',
|
|
58
|
+
mode: '"draft" saves a draft. "schedule" publishes at scheduled_at and "now" publishes immediately; both always need the user\'s confirmation.',
|
|
59
|
+
targets: 'Accounts to post to, as [{ platform, social_account_id?, format?, options? }]. Up to 10.',
|
|
60
|
+
caption: 'The post text.',
|
|
61
|
+
hashtags: 'Hashtags such as ["#launch"]; they are added to the caption.',
|
|
62
|
+
mention_accounts: 'Handles to mention.',
|
|
63
|
+
first_comment: 'A comment posted on the post right after it publishes.',
|
|
64
|
+
location: 'A place tag, for example { "id": "<place id>", "name": "..." }.',
|
|
65
|
+
media: 'Media items from upload_media (type, object_path, url, mime_type). Instagram and Facebook posts need at least one.',
|
|
66
|
+
'update_post.scheduled_at': 'The new publish time, ISO 8601, at least 5 minutes ahead. Send it with timezone, or include an offset/Z.',
|
|
67
|
+
post_now: 'Publish immediately. Needs the user\'s confirmation.',
|
|
68
|
+
};
|
package/dist/usage.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { DEFAULT_PAGE_SIZE, FALLBACK_CALL_COST } from './catalog.js';
|
|
2
|
+
const round = (n) => Math.round(n * 100) / 100;
|
|
3
|
+
/** Credits spent through this MCP session, the spending cap, and the warnings that tell the user when usage will be high. */
|
|
4
|
+
export class Usage {
|
|
5
|
+
cfg;
|
|
6
|
+
spent = 0;
|
|
7
|
+
calls = 0;
|
|
8
|
+
livePosts = 0;
|
|
9
|
+
holds = new Map();
|
|
10
|
+
constructor(cfg) {
|
|
11
|
+
this.cfg = cfg;
|
|
12
|
+
}
|
|
13
|
+
record(credits) { if (credits > 0) {
|
|
14
|
+
this.spent = round(this.spent + credits);
|
|
15
|
+
} this.calls++; }
|
|
16
|
+
/** A lead job holds credits up front; settle() swaps the hold for what it really cost. */
|
|
17
|
+
hold(id, credits) { this.holds.set(id, credits); this.record(credits); }
|
|
18
|
+
settle(id, charged) {
|
|
19
|
+
const held = this.holds.get(id);
|
|
20
|
+
if (held === undefined)
|
|
21
|
+
return;
|
|
22
|
+
this.holds.delete(id);
|
|
23
|
+
this.spent = Math.max(0, round(this.spent - held + charged));
|
|
24
|
+
}
|
|
25
|
+
snapshot(balance) {
|
|
26
|
+
const left = round(Math.max(0, this.cfg.sessionCap - this.spent));
|
|
27
|
+
return {
|
|
28
|
+
credits_spent_this_session: this.spent,
|
|
29
|
+
session_cap: this.cfg.sessionCap,
|
|
30
|
+
cap_remaining: left,
|
|
31
|
+
confirm_above: this.cfg.confirmAbove,
|
|
32
|
+
balance_credits: balance ?? null,
|
|
33
|
+
posts_scheduled_or_published_this_session: this.livePosts,
|
|
34
|
+
post_cap: this.cfg.maxLivePosts,
|
|
35
|
+
warnings: this.standingWarnings(balance ?? null),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
standingWarnings(balance) {
|
|
39
|
+
const w = [];
|
|
40
|
+
if (this.cfg.sessionCap > 0 && this.spent >= this.cfg.sessionCap * 0.8)
|
|
41
|
+
w.push(`Session spending is at ${Math.round((this.spent / this.cfg.sessionCap) * 100)}% of its ${this.cfg.sessionCap}-credit cap.`);
|
|
42
|
+
if (balance !== null && balance < this.cfg.lowBalance)
|
|
43
|
+
w.push(`Credit balance is low: ${round(balance)} credits left.`);
|
|
44
|
+
return w;
|
|
45
|
+
}
|
|
46
|
+
/** Decide whether an action costing `est` may run now. Cheap actions pass silently; big ones need the user's yes. */
|
|
47
|
+
guard(est, opts) {
|
|
48
|
+
const warnings = [];
|
|
49
|
+
if (est.credits <= 0)
|
|
50
|
+
return { allowed: true, warnings };
|
|
51
|
+
const { sessionCap, confirmAbove, lowBalance } = this.cfg;
|
|
52
|
+
const after = round(this.spent + est.credits);
|
|
53
|
+
if (after > sessionCap) {
|
|
54
|
+
return {
|
|
55
|
+
allowed: false, blocked: 'CAP_EXCEEDED', warnings,
|
|
56
|
+
message: `This would bring the session's spending to ${after} credits, over the ${sessionCap}-credit cap (already spent ${this.spent}). The cap protects the account and cannot be raised from here: ask the user to increase SOCIAL_AUTOMATE_SESSION_CAP in the MCP settings if they really want this, or reduce the request.`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
let needsConfirm = false;
|
|
60
|
+
if (est.credits > confirmAbove) {
|
|
61
|
+
needsConfirm = true;
|
|
62
|
+
warnings.push(`This is a large action: about ${est.credits} credits (anything above ${confirmAbove} needs confirmation).`);
|
|
63
|
+
}
|
|
64
|
+
const bal = opts.balance ?? null;
|
|
65
|
+
if (bal !== null && bal > 0) {
|
|
66
|
+
const share = est.credits / bal;
|
|
67
|
+
if (share >= 0.25) {
|
|
68
|
+
needsConfirm = true;
|
|
69
|
+
warnings.push(`This would use about ${Math.round(share * 100)}% of the current balance (${round(bal)} credits).`);
|
|
70
|
+
}
|
|
71
|
+
if (bal - est.credits < lowBalance) {
|
|
72
|
+
needsConfirm = true;
|
|
73
|
+
warnings.push(`This would leave only about ${round(Math.max(0, bal - est.credits))} credits.`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (after >= sessionCap * 0.8)
|
|
77
|
+
warnings.push(`Session spending would reach ${Math.round((after / sessionCap) * 100)}% of its ${sessionCap}-credit cap.`);
|
|
78
|
+
if (est.approximate)
|
|
79
|
+
warnings.push('The estimate is approximate; the real charge is usually the same or lower and never more than the hold.');
|
|
80
|
+
if (needsConfirm && !opts.confirm) {
|
|
81
|
+
return {
|
|
82
|
+
allowed: false, blocked: 'NEEDS_CONFIRMATION', warnings,
|
|
83
|
+
message: 'Not started. Tell the user the estimate and the warnings above in plain words and ask whether to go ahead. Only after they say yes, call this tool again with confirm: true.',
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return { allowed: true, warnings };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Per-call prices from the public rate card (`scrape_call_<platform>`), with the documented defaults as a fallback. */
|
|
90
|
+
export function parseRateCard(rows) {
|
|
91
|
+
const card = { ...FALLBACK_CALL_COST };
|
|
92
|
+
if (Array.isArray(rows))
|
|
93
|
+
for (const r of rows) {
|
|
94
|
+
const m = /^scrape_call_(\w+)$/.exec(r?.action ?? '');
|
|
95
|
+
const price = Number(r?.credits_per_unit);
|
|
96
|
+
if (m && Number.isFinite(price))
|
|
97
|
+
card[m[1]] = price;
|
|
98
|
+
}
|
|
99
|
+
return card;
|
|
100
|
+
}
|
|
101
|
+
export function estimateScrape(platform, card) {
|
|
102
|
+
const price = card[platform] ?? 0;
|
|
103
|
+
return { credits: price, basis: `1 call × ${price} credits (${platform}); empty results are refunded`, approximate: false };
|
|
104
|
+
}
|
|
105
|
+
export function estimateBulk(platform, card, target, pageSize) {
|
|
106
|
+
const price = card[platform] ?? 0;
|
|
107
|
+
const size = pageSize ?? DEFAULT_PAGE_SIZE;
|
|
108
|
+
const pages = Math.max(1, Math.ceil(target / size));
|
|
109
|
+
return { credits: round(pages * price), basis: `up to ${pages} pages × ${price} credits (${pageSize ? `${size} items per page` : `about ${size} items per page assumed`}); billed per page actually fetched`, approximate: pageSize === null };
|
|
110
|
+
}
|
|
111
|
+
const LINKEDIN_PER_PROFILE = 4, LINKEDIN_PER_PROFILE_EMAIL = 14, LINKEDIN_MIN_SEARCH = 100, EMAIL_VALIDATION_PER_1000 = 5;
|
|
112
|
+
const LINKEDIN_MIN_TYPES = new Set(['keyword', 'competitor', 'location']);
|
|
113
|
+
export function estimateLeadJob(platform, card, count, searchType, emailValidation) {
|
|
114
|
+
if (platform === 'linkedin') {
|
|
115
|
+
const per = emailValidation ? LINKEDIN_PER_PROFILE_EMAIL : LINKEDIN_PER_PROFILE;
|
|
116
|
+
let credits = count * per;
|
|
117
|
+
if (LINKEDIN_MIN_TYPES.has(searchType))
|
|
118
|
+
credits = Math.max(credits, LINKEDIN_MIN_SEARCH);
|
|
119
|
+
return { credits, basis: `${count} profiles × ${per} credits${LINKEDIN_MIN_TYPES.has(searchType) ? ` (minimum ${LINKEDIN_MIN_SEARCH})` : ''}; charged only for profiles returned`, approximate: true };
|
|
120
|
+
}
|
|
121
|
+
const price = card[platform] ?? 0;
|
|
122
|
+
const requests = Math.ceil(count / DEFAULT_PAGE_SIZE);
|
|
123
|
+
const email = emailValidation ? (count / 1000) * EMAIL_VALIDATION_PER_1000 : 0;
|
|
124
|
+
return { credits: round(requests * price * 1.05 + email), basis: `about ${requests} provider requests × ${price} credits${emailValidation ? ` + email validation (${EMAIL_VALIDATION_PER_1000}/1,000)` : ''}; only requests actually made are charged`, approximate: true };
|
|
125
|
+
}
|
|
126
|
+
/** Balance as a number, from the credits endpoint's `total_available`. */
|
|
127
|
+
export function balanceOf(b) {
|
|
128
|
+
const n = Number(b?.total_available ?? b?.balance);
|
|
129
|
+
return Number.isFinite(n) ? n : null;
|
|
130
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aisocialautomate/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "MCP server for AI Social Automate: draft, schedule and publish posts to Instagram, Facebook, LinkedIn, TikTok and YouTube, and find leads and research content, from Claude, ChatGPT, Codex or any MCP client.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"aisocialautomate-mcp": "dist/stdio.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/server.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"!dist/test",
|
|
13
|
+
"catalog",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"mcp",
|
|
19
|
+
"model-context-protocol",
|
|
20
|
+
"claude",
|
|
21
|
+
"social-media",
|
|
22
|
+
"lead-generation",
|
|
23
|
+
"instagram",
|
|
24
|
+
"linkedin",
|
|
25
|
+
"tiktok"
|
|
26
|
+
],
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/Relu-Consultancy/AiSocialAutomate-BE.git",
|
|
30
|
+
"directory": "mcp-server"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://aisocialautomate.com",
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=20"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"catalog": "node scripts/build-catalog.mjs",
|
|
41
|
+
"build": "tsc -p tsconfig.json",
|
|
42
|
+
"test": "npm run build && node scripts/run-tests.mjs",
|
|
43
|
+
"prepublishOnly": "npm test",
|
|
44
|
+
"start": "node dist/stdio.js",
|
|
45
|
+
"start:http": "node dist/http.js"
|
|
46
|
+
},
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
50
|
+
"zod": "^3.25.76"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^22.20.7",
|
|
54
|
+
"typescript": "^5.9.3"
|
|
55
|
+
}
|
|
56
|
+
}
|