socialcrawl-mcp 2.0.1 → 2.0.2
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/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/data/docs-handwritten.js +3 -2
- package/dist/data/endpoints.js +40 -11
- package/dist/data/guide.d.ts +1 -1
- package/dist/data/guide.js +1 -1
- package/dist/data/outputs.js +10 -9
- package/dist/data/platforms.js +1 -1
- package/dist/data/recipes.js +1 -1
- package/dist/data/registry-meta.d.ts +4 -4
- package/dist/data/registry-meta.js +4 -4
- package/dist/oauth/jwt-verifier.js +7 -0
- package/dist/oauth/resource-server.d.ts +3 -1
- package/dist/oauth/resource-server.js +12 -2
- package/dist/oauth/scopes.d.ts +13 -0
- package/dist/oauth/scopes.js +33 -0
- package/dist/server.js +1 -1
- package/dist/tools/endpoint.js +1 -1
- package/dist/tools/find.d.ts +3 -0
- package/dist/tools/find.js +111 -7
- package/dist/types.d.ts +9 -4
- package/package.json +1 -1
package/dist/oauth/scopes.d.ts
CHANGED
|
@@ -18,6 +18,19 @@ export declare const SCOPES_SUPPORTED: string[];
|
|
|
18
18
|
* first, then the 1.x names `SOCIALCRAWL_LEGACY_TOOLS=1` brings back.
|
|
19
19
|
*/
|
|
20
20
|
export declare const TOOL_SCOPES: Record<string, readonly string[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Tools that work with no API key at all (free, local discovery). With OAuth
|
|
23
|
+
* on, an anonymous caller may use these, initialize and tools/list; anything
|
|
24
|
+
* else gets the 401 challenge that starts sign-in (lazy authentication).
|
|
25
|
+
*/
|
|
26
|
+
export declare const ANONYMOUS_TOOLS: ReadonlySet<string>;
|
|
27
|
+
/**
|
|
28
|
+
* True when an anonymous JSON-RPC body (single message or batch) contains a
|
|
29
|
+
* tools/call that needs an API key. Fails closed like missingScopesForBody: a
|
|
30
|
+
* body that is not a parsed JSON-RPC object, a nameless call or an unknown
|
|
31
|
+
* tool all need sign-in.
|
|
32
|
+
*/
|
|
33
|
+
export declare function needsSignIn(body: unknown): boolean;
|
|
21
34
|
/** Scopes a tool needs. Unknown tools fail closed and need every scope. */
|
|
22
35
|
export declare function requiredScopesForTool(name: string): readonly string[];
|
|
23
36
|
/**
|
package/dist/oauth/scopes.js
CHANGED
|
@@ -36,6 +36,39 @@ export const TOOL_SCOPES = {
|
|
|
36
36
|
socialcrawl_monitors: [SCOPES.spend, SCOPES.manage],
|
|
37
37
|
socialcrawl_cohorts: [SCOPES.spend, SCOPES.manage],
|
|
38
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Tools that work with no API key at all (free, local discovery). With OAuth
|
|
41
|
+
* on, an anonymous caller may use these, initialize and tools/list; anything
|
|
42
|
+
* else gets the 401 challenge that starts sign-in (lazy authentication).
|
|
43
|
+
*/
|
|
44
|
+
export const ANONYMOUS_TOOLS = new Set([
|
|
45
|
+
"socialcrawl_find",
|
|
46
|
+
"socialcrawl_endpoint",
|
|
47
|
+
"socialcrawl_estimate",
|
|
48
|
+
// 1.x names (legacy flag).
|
|
49
|
+
"socialcrawl_list_platforms",
|
|
50
|
+
"socialcrawl_list_endpoints",
|
|
51
|
+
"socialcrawl_pricing",
|
|
52
|
+
"socialcrawl_discover",
|
|
53
|
+
"socialcrawl_get_docs",
|
|
54
|
+
]);
|
|
55
|
+
/**
|
|
56
|
+
* True when an anonymous JSON-RPC body (single message or batch) contains a
|
|
57
|
+
* tools/call that needs an API key. Fails closed like missingScopesForBody: a
|
|
58
|
+
* body that is not a parsed JSON-RPC object, a nameless call or an unknown
|
|
59
|
+
* tool all need sign-in.
|
|
60
|
+
*/
|
|
61
|
+
export function needsSignIn(body) {
|
|
62
|
+
const messages = Array.isArray(body) ? body : [body];
|
|
63
|
+
return messages.some((message) => {
|
|
64
|
+
if (typeof message !== "object" || message === null || Array.isArray(message))
|
|
65
|
+
return true;
|
|
66
|
+
if (message.method !== "tools/call")
|
|
67
|
+
return false;
|
|
68
|
+
const name = message.params?.name;
|
|
69
|
+
return typeof name !== "string" || !ANONYMOUS_TOOLS.has(name);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
39
72
|
/** Scopes a tool needs. Unknown tools fail closed and need every scope. */
|
|
40
73
|
export function requiredScopesForTool(name) {
|
|
41
74
|
return Object.hasOwn(TOOL_SCOPES, name) ? TOOL_SCOPES[name] : SCOPES_SUPPORTED;
|
package/dist/server.js
CHANGED
|
@@ -176,7 +176,7 @@ export function createServer(baseCtx, options = {}) {
|
|
|
176
176
|
});
|
|
177
177
|
server.registerTool("socialcrawl_manage", {
|
|
178
178
|
title: "Manage Monitors, Cohorts, Web and Jobs",
|
|
179
|
-
description: "Stateful work by area + action: monitors (scheduled recipes, webhooks, alerts), cohorts (mention search over your own panel of accounts), web (scrape, search, crawl and agent jobs, change monitors, browser sessions) and jobs (Prism background jobs). A wrong field is refused free with the rules. Managing is free; scrapes, jobs, queries and monitor runs bill credits.\ndry_run: true validates and quotes a create/update and never creates it.",
|
|
179
|
+
description: "Stateful work by area + action: monitors (scheduled recipes, webhooks, alerts), cohorts (mention search over your own panel of accounts), web (scrape, search, crawl and agent jobs, change monitors, browser sessions) and jobs (Prism background jobs). A wrong field is refused free with the rules. Managing is free; scrapes, jobs, queries and monitor runs bill credits.\ndry_run: true validates and quotes a create/update and never creates it. rows_new alerts need track (id=monitors).",
|
|
180
180
|
inputSchema: withNormalizedArgs(ManageInputSchema, "manage"),
|
|
181
181
|
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true },
|
|
182
182
|
}, async (params) => {
|
package/dist/tools/endpoint.js
CHANGED
|
@@ -150,7 +150,7 @@ function cleanNext(raw) {
|
|
|
150
150
|
export function contractFor(e) {
|
|
151
151
|
const out = outputsFor(e);
|
|
152
152
|
const contract = {
|
|
153
|
-
purpose: e.purpose ?? { summary: e.summary },
|
|
153
|
+
purpose: e.purpose ? { ...e.purpose, summary: e.purpose.summary ?? e.summary } : { summary: e.summary },
|
|
154
154
|
params: {
|
|
155
155
|
required: e.params.map((p) => ({ name: p.name, description: p.description, example: p.example })),
|
|
156
156
|
one_of: e.oneOfGroups,
|
package/dist/tools/find.d.ts
CHANGED
|
@@ -28,8 +28,11 @@ interface TaskFacts {
|
|
|
28
28
|
/** The task with URLs and handles taken out, plus the URLs' platform names, for the ranker. */
|
|
29
29
|
rankQuery: string;
|
|
30
30
|
urlPlatforms: string[];
|
|
31
|
+
/** The task with URLs and handles taken out (intent words are read here, never inside a URL). */
|
|
32
|
+
text: string;
|
|
31
33
|
}
|
|
32
34
|
export declare function readTask(task: string): TaskFacts;
|
|
33
35
|
export declare function findStructured(ctx: ApiContext, params: FindParams): Promise<ToolOutput>;
|
|
36
|
+
/** Read on the task's words only: URLs and handles are taken out first (a YouTube `watch?v=` is not intent). */
|
|
34
37
|
export declare const wantsMonitor: (task: string) => boolean;
|
|
35
38
|
export {};
|
package/dist/tools/find.js
CHANGED
|
@@ -15,6 +15,7 @@ import { JOB_ACTION_RESOURCES } from "./manage.js";
|
|
|
15
15
|
import { normalizeEndpointId } from "./discover.js";
|
|
16
16
|
import { resolveEndpoint } from "./request.js";
|
|
17
17
|
import { WEB_ACTION_RESOURCES } from "./web.js";
|
|
18
|
+
import { pageSizeOf } from "../walk-quote.js";
|
|
18
19
|
const DEFAULT_LIMIT = 3;
|
|
19
20
|
/** Candidates ranked before the resolve reorder and the limit cut. */
|
|
20
21
|
const POOL = 20;
|
|
@@ -72,6 +73,7 @@ export function readTask(task) {
|
|
|
72
73
|
quoted: q ? (q[1] ?? q[2]) : undefined,
|
|
73
74
|
rankQuery: [rest, ...names].join(" ").replace(/\s+/g, " ").trim(),
|
|
74
75
|
urlPlatforms,
|
|
76
|
+
text: rest.replace(/\s+/g, " ").trim(),
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
79
|
const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -223,7 +225,7 @@ function fill(e, facts, resolved) {
|
|
|
223
225
|
const lane = r.endpoints.find((x) => x.id === id);
|
|
224
226
|
if (lane) {
|
|
225
227
|
const value = r.canonical[lane.param] ?? (lane.param === "url" ? r.canonical.url ?? r.input : undefined) ?? r.input;
|
|
226
|
-
return { [lane.param]: value };
|
|
228
|
+
return { [lane.param]: value, ...(e.method === "POST" ? batchFill(e, facts) : {}), ...recencyFill(e, facts) };
|
|
227
229
|
}
|
|
228
230
|
}
|
|
229
231
|
const names = new Set(paramNames(e));
|
|
@@ -246,8 +248,101 @@ function fill(e, facts, resolved) {
|
|
|
246
248
|
if (textParam)
|
|
247
249
|
out[textParam] = facts.quoted;
|
|
248
250
|
}
|
|
251
|
+
if (e.method === "POST")
|
|
252
|
+
Object.assign(out, batchFill(e, facts));
|
|
253
|
+
Object.assign(out, recencyFill(e, facts));
|
|
249
254
|
return out;
|
|
250
255
|
}
|
|
256
|
+
/** The platforms a task names in words ("on tiktok", "Instagram"). */
|
|
257
|
+
function namedPlatforms(text) {
|
|
258
|
+
const t = ` ${text.toLowerCase()} `;
|
|
259
|
+
return PLATFORMS.filter((p) => new RegExp(`[^a-z0-9_](${p.slug}|${p.name.toLowerCase().replace(/[^a-z0-9]+/g, "\\W?")})[^a-z0-9_]`).test(t)).map((p) => p.slug);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* A batch POST endpoint's list param, from every URL and @handle in the task,
|
|
263
|
+
* shaped like the param's own registry example: a list of URLs (`urls`), of
|
|
264
|
+
* handles (`handles`), or of objects keyed like the example's first item
|
|
265
|
+
* (`{ <..._url>: url }`, `{ platform, handle }`). JSON-encoded here; the
|
|
266
|
+
* suggested call carries it as a real array.
|
|
267
|
+
*/
|
|
268
|
+
function batchFill(e, facts) {
|
|
269
|
+
const out = {};
|
|
270
|
+
for (const p of [...e.params, ...e.optionalParams]) {
|
|
271
|
+
let example;
|
|
272
|
+
try {
|
|
273
|
+
example = JSON.parse(p.example ?? "");
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
if (!Array.isArray(example) || example.length === 0)
|
|
279
|
+
continue;
|
|
280
|
+
const first = example[0];
|
|
281
|
+
let list = [];
|
|
282
|
+
if (typeof first === "string") {
|
|
283
|
+
if (/urls?$/i.test(p.name))
|
|
284
|
+
list = facts.urls;
|
|
285
|
+
else if (/handles?$/i.test(p.name))
|
|
286
|
+
list = facts.handles;
|
|
287
|
+
}
|
|
288
|
+
else if (isObj(first)) {
|
|
289
|
+
const keys = Object.keys(first);
|
|
290
|
+
const urlKey = keys.find((k) => /url$/i.test(k));
|
|
291
|
+
if (urlKey && facts.urls.length > 0)
|
|
292
|
+
list = facts.urls.map((u) => ({ [urlKey]: u }));
|
|
293
|
+
else if (keys.includes("platform") && keys.includes("handle") && facts.handles.length > 0) {
|
|
294
|
+
const platforms = namedPlatforms(facts.text);
|
|
295
|
+
list = platforms.flatMap((platform) => facts.handles.map((handle) => ({ platform, handle })));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (list.length > 0)
|
|
299
|
+
out[p.name] = JSON.stringify(list);
|
|
300
|
+
}
|
|
301
|
+
return out;
|
|
302
|
+
}
|
|
303
|
+
/** Sort values that mean newest first, best first. */
|
|
304
|
+
const RECENCY_VALUES = [/^recent$/i, /^most[_-]?recent$/i, /^newest$/i, /^latest$/i, /^new$/i, /^recency$/i, /^date[_-]?posted$/i, /^date$/i, /^chronological$/i, /^created$/i, /^creation_time_descend$/i, /^time$/i, /^pub_date$/i, /^newly_listed$/i];
|
|
305
|
+
const SORT_PARAMS = new Set(["sort", "sort_by", "sortBy", "order", "order_by", "sort_order"]);
|
|
306
|
+
/**
|
|
307
|
+
* "Newest", "most recent", "latest": the endpoint's own newest-first sort
|
|
308
|
+
* value (read from its enum), and, when it can read several pages before
|
|
309
|
+
* sorting (`scan_pages`), enough pages for the count the task asks for.
|
|
310
|
+
*/
|
|
311
|
+
function recencyFill(e, facts) {
|
|
312
|
+
if (!/\b(newest|most\s+recent|latest|recent|new(?:er)?\s+first)\b/i.test(facts.text))
|
|
313
|
+
return {};
|
|
314
|
+
const out = {};
|
|
315
|
+
for (const o of e.optionalParams) {
|
|
316
|
+
if (!SORT_PARAMS.has(o.name) || !o.enumValues)
|
|
317
|
+
continue;
|
|
318
|
+
const value = RECENCY_VALUES.map((re) => o.enumValues.find((v) => re.test(v))).find((v) => v !== undefined);
|
|
319
|
+
if (value) {
|
|
320
|
+
out[o.name] = value;
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (Object.keys(out).length === 0)
|
|
325
|
+
return {};
|
|
326
|
+
const scan = e.optionalParams.find((o) => o.name === "scan_pages");
|
|
327
|
+
const count = Number(/\b(\d{1,5})\b/.exec(facts.text)?.[1]);
|
|
328
|
+
const size = pageSizeOf(e);
|
|
329
|
+
if (scan && Number.isFinite(count) && count > 0 && size) {
|
|
330
|
+
const pages = Math.min(scan.maximum ?? Number.POSITIVE_INFINITY, Math.max(scan.minimum ?? 1, Math.ceil(count / size)));
|
|
331
|
+
out.scan_pages = String(pages);
|
|
332
|
+
}
|
|
333
|
+
return out;
|
|
334
|
+
}
|
|
335
|
+
/** A JSON-encoded list (from batchFill) back as the array the API takes. */
|
|
336
|
+
const asSent = (v) => {
|
|
337
|
+
if (!v.startsWith("["))
|
|
338
|
+
return v;
|
|
339
|
+
try {
|
|
340
|
+
return JSON.parse(v);
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
return v;
|
|
344
|
+
}
|
|
345
|
+
};
|
|
251
346
|
function missing(e, filled) {
|
|
252
347
|
const out = e.params.filter((p) => p.required && filled[p.name] === undefined).map((p) => p.name);
|
|
253
348
|
for (const group of e.oneOfGroups) {
|
|
@@ -290,7 +385,7 @@ function splitForMethod(e, filled) {
|
|
|
290
385
|
if (e.optionalParams.find((o) => o.name === k)?.in === "query")
|
|
291
386
|
params[k] = v;
|
|
292
387
|
else
|
|
293
|
-
body[k] = v;
|
|
388
|
+
body[k] = asSent(v);
|
|
294
389
|
}
|
|
295
390
|
return { ...(Object.keys(params).length > 0 ? { params } : {}), body };
|
|
296
391
|
}
|
|
@@ -406,8 +501,13 @@ export async function findStructured(ctx, params) {
|
|
|
406
501
|
if (!e) {
|
|
407
502
|
return { id: c.id, summary: c.summary ?? c.why ?? "", params_filled: c.filled ?? {}, params_missing: [], bundled: false, ...c.meta };
|
|
408
503
|
}
|
|
409
|
-
// The API's params_filled wins over what was read locally from the task
|
|
410
|
-
|
|
504
|
+
// The API's params_filled wins over what was read locally from the task,
|
|
505
|
+
// except a whole list built from every URL / handle in it (the API fills one).
|
|
506
|
+
const local = fill(e, facts, resolved);
|
|
507
|
+
const filled = { ...local, ...(c.filled ?? {}) };
|
|
508
|
+
for (const [k, v] of Object.entries(local))
|
|
509
|
+
if (v.startsWith("["))
|
|
510
|
+
filled[k] = v;
|
|
411
511
|
const miss = missing(e, filled);
|
|
412
512
|
return {
|
|
413
513
|
id: c.id,
|
|
@@ -438,8 +538,9 @@ export async function findStructured(ctx, params) {
|
|
|
438
538
|
* rather than one read now: alert, notify, monitor, watch, every day/week,
|
|
439
539
|
* schedule, "when ... posts/changes".
|
|
440
540
|
*/
|
|
441
|
-
const MONITOR_INTENT = /\b(alerts?|notify|notifications?|monitor(?:ing)?|watch(?:ing)?|schedul(?:e|ed|ing)|recurring|daily|weekly|hourly|nightly|every\s+(?:day|week|hour|morning|evening|night|month|monday|tuesday|wednesday|thursday|friday|saturday|sunday))\b|\bwhen\b
|
|
442
|
-
|
|
541
|
+
const MONITOR_INTENT = /\b(alerts?|alerting|notify|notifications?|monitor(?:s|ing)?|watch(?:ing)?|schedul(?:e|ed|ing)|recurring|daily|weekly|hourly|nightly|whenever|every\s+(?:day|week|hour|morning|evening|night|month|monday|tuesday|wednesday|thursday|friday|saturday|sunday))\b|\btrack\w*\b[^.?!]{0,60}\bover\s+time\b|\bwhen\b[^.?!]{0,60}\b(posts?|posted|uploads?|changes?|changed|updates?|updated|publish(?:es)?|goes\s+live|drops?)\b/i;
|
|
542
|
+
/** Read on the task's words only: URLs and handles are taken out first (a YouTube `watch?v=` is not intent). */
|
|
543
|
+
export const wantsMonitor = (task) => MONITOR_INTENT.test(readTask(task).text);
|
|
443
544
|
/** The cadence a task asks for: hourly, weekly, else daily. */
|
|
444
545
|
function cadenceOf(task) {
|
|
445
546
|
if (/\b(hourly|every\s+hour)\b/i.test(task))
|
|
@@ -616,7 +717,10 @@ function render(task, source, results, meta = {}) {
|
|
|
616
717
|
if (r.actions)
|
|
617
718
|
lines.push(` Actions: ${r.actions.join(", ")}. Read first: socialcrawl_endpoint with id "${r.id}".`);
|
|
618
719
|
else {
|
|
619
|
-
const needs = r.params_missing.length > 0 ? `
|
|
720
|
+
const needs = r.params_missing.length > 0 ? ` Replace or add ${r.params_missing.join(", ")} in input.` : "";
|
|
721
|
+
const input = (r.call?.arguments?.input ?? {});
|
|
722
|
+
if (input.track && input.alert_rules)
|
|
723
|
+
lines.push(" Keep track and alert_rules together: the rows_new alert needs track.");
|
|
620
724
|
lines.push(` To run it on a schedule:${needs} dry_run: true validates and quotes it without creating anything; repeat without dry_run to create it.`);
|
|
621
725
|
}
|
|
622
726
|
if (r.call)
|
package/dist/types.d.ts
CHANGED
|
@@ -334,16 +334,21 @@ export interface Endpoint {
|
|
|
334
334
|
/** Measured latency over recent calls, in milliseconds (dump v4), when sampled. */
|
|
335
335
|
latency_ms?: LatencyStats;
|
|
336
336
|
}
|
|
337
|
-
/**
|
|
337
|
+
/**
|
|
338
|
+
* Registry `purpose` block: one line each, generated from the same source as the skill.
|
|
339
|
+
* Every field is nullable: an endpoint can reach the dump before its copy is written,
|
|
340
|
+
* and consumers fall back to `Endpoint.summary` (or skip the line).
|
|
341
|
+
*/
|
|
338
342
|
export interface EndpointPurpose {
|
|
339
|
-
summary: string;
|
|
343
|
+
summary: string | null;
|
|
340
344
|
returns: string | null;
|
|
341
345
|
use_when: string | null;
|
|
342
346
|
not_for: string | null;
|
|
343
347
|
}
|
|
348
|
+
/** Job taxonomy; null while an endpoint is not classified yet. */
|
|
344
349
|
export interface EndpointTaxonomy {
|
|
345
|
-
purpose: string;
|
|
346
|
-
job_family: string;
|
|
350
|
+
purpose: string | null;
|
|
351
|
+
job_family: string | null;
|
|
347
352
|
takes_item_id_from_another_endpoint?: boolean;
|
|
348
353
|
}
|
|
349
354
|
export interface LatencyStats {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "socialcrawl-mcp",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "One unified API for social and web data — social media (incl. Douyin, Xiaohongshu, Telegram, Quora, Bluesky, Apple Music, Product Hunt), commerce, marketplaces & product reviews, retail (Amazon, Walmart, Target, Home Depot, eBay, Klarna, AliExpress, Etsy, Sephora, H&M, Kohl's, Wayfair, Gumtree, Google Shopping), app stores (Google Play, App Store), places, travel & local (Tripadvisor, Yelp, Google Business/Hotels), business & software reputation (Trustpilot, G2), jobs & salaries (LinkedIn, Indeed, Bing, Xing), markets & finance, US congressional trading disclosures, on-page SEO audits, web research (Tavily, Perplexity), full web scraping & browser automation (scrape, crawl, agent, monitors, sessions), audience-filtered mention search over a panel you supply (cohorts), Korean search (Naver + Data Lab), content/sentiment analysis, Google News/Trends, GitHub, Hacker News, Polymarket, AI X-search via Grok, cross-platform Prism composites, and a universal /search/everywhere meta-search — with exact per-endpoint credit pricing (ladder, flat, and metered bands), free default row judgments with metered label/relevance quotes, and itemised per-call and per-job cost quotes for every one.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|