desearch-mcp-server 0.5.0 → 0.7.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,188 @@
1
+ import type { DesearchApi } from "./desearch-api.js";
2
+ /**
3
+ * TikTok, Facebook, and Instagram on the Desearch API (`/desearch/{platform}/*`).
4
+ *
5
+ * desearch-js 1.5 has no social methods, so the `tiktok`, `facebook`, and
6
+ * `instagram` tools call these routes through `desearch-api.ts`. Each tool takes an
7
+ * `action` that picks one route; the table below says which arguments each route
8
+ * needs and accepts, and the request is refused before it is sent when they do not match.
9
+ *
10
+ * Paging (desearch-public-api docs/social-pagination.md): a list route answers with a
11
+ * JSON array and, when there is another page, an `x-desearch-next-cursor` header.
12
+ * The caller sends that value back unchanged as `cursor`, on the same route with the
13
+ * same target. The header is absent on the last page. A cursor is opaque and lasts
14
+ * 24 hours; this module never builds or changes one.
15
+ */
16
+ export declare const SOCIAL_PLATFORMS: readonly ["tiktok", "facebook", "instagram"];
17
+ export type SocialPlatform = (typeof SOCIAL_PLATFORMS)[number];
18
+ export declare const NEXT_CURSOR_HEADER = "x-desearch-next-cursor";
19
+ export interface SocialActionSpec {
20
+ method: "GET" | "POST";
21
+ /** Route, with `{name}` for each path argument. */
22
+ path: string;
23
+ /** Arguments the route needs. */
24
+ required: readonly string[];
25
+ /** Other arguments the route accepts. `cursor` here means the route pages. */
26
+ optional: readonly string[];
27
+ /** The route answers with a list of items. */
28
+ list?: true;
29
+ }
30
+ export declare const SOCIAL_ACTIONS: {
31
+ readonly tiktok: {
32
+ readonly search: {
33
+ readonly method: "POST";
34
+ readonly path: "/desearch/tiktok/search";
35
+ readonly required: readonly ["query"];
36
+ readonly optional: readonly ["count", "sort", "cursor"];
37
+ readonly list: true;
38
+ };
39
+ readonly post: {
40
+ readonly method: "GET";
41
+ readonly path: "/desearch/tiktok/post/{id}";
42
+ readonly required: readonly ["id"];
43
+ readonly optional: readonly [];
44
+ };
45
+ readonly profile: {
46
+ readonly method: "GET";
47
+ readonly path: "/desearch/tiktok/profile/{username}";
48
+ readonly required: readonly ["username"];
49
+ readonly optional: readonly [];
50
+ };
51
+ readonly profile_posts: {
52
+ readonly method: "GET";
53
+ readonly path: "/desearch/tiktok/profile/{username}/posts";
54
+ readonly required: readonly ["username"];
55
+ readonly optional: readonly ["count", "cursor"];
56
+ readonly list: true;
57
+ };
58
+ readonly comments: {
59
+ readonly method: "GET";
60
+ readonly path: "/desearch/tiktok/comments/{video_id}";
61
+ readonly required: readonly ["video_id"];
62
+ readonly optional: readonly ["count", "cursor"];
63
+ readonly list: true;
64
+ };
65
+ readonly hashtag: {
66
+ readonly method: "GET";
67
+ readonly path: "/desearch/tiktok/hashtag/{tag}";
68
+ readonly required: readonly ["tag"];
69
+ readonly optional: readonly ["count", "cursor"];
70
+ readonly list: true;
71
+ };
72
+ readonly trending: {
73
+ readonly method: "GET";
74
+ readonly path: "/desearch/tiktok/trending";
75
+ readonly required: readonly [];
76
+ readonly optional: readonly ["region", "count"];
77
+ readonly list: true;
78
+ };
79
+ };
80
+ readonly facebook: {
81
+ readonly search: {
82
+ readonly method: "POST";
83
+ readonly path: "/desearch/facebook/search";
84
+ readonly required: readonly ["query"];
85
+ readonly optional: readonly ["count", "cursor"];
86
+ readonly list: true;
87
+ };
88
+ readonly post: {
89
+ readonly method: "GET";
90
+ readonly path: "/desearch/facebook/post/{id}";
91
+ readonly required: readonly ["id"];
92
+ readonly optional: readonly [];
93
+ };
94
+ readonly profile: {
95
+ readonly method: "GET";
96
+ readonly path: "/desearch/facebook/profile/{profile_id}";
97
+ readonly required: readonly ["profile_id"];
98
+ readonly optional: readonly [];
99
+ };
100
+ readonly profile_posts: {
101
+ readonly method: "GET";
102
+ readonly path: "/desearch/facebook/profile/{profile_id}/posts";
103
+ readonly required: readonly ["profile_id"];
104
+ readonly optional: readonly ["count", "cursor"];
105
+ readonly list: true;
106
+ };
107
+ readonly comments: {
108
+ readonly method: "GET";
109
+ readonly path: "/desearch/facebook/comments/{post_id}";
110
+ readonly required: readonly ["post_id"];
111
+ readonly optional: readonly ["count", "cursor"];
112
+ readonly list: true;
113
+ };
114
+ readonly hashtag: {
115
+ readonly method: "GET";
116
+ readonly path: "/desearch/facebook/hashtag/{tag}";
117
+ readonly required: readonly ["tag"];
118
+ readonly optional: readonly ["count", "cursor"];
119
+ readonly list: true;
120
+ };
121
+ };
122
+ readonly instagram: {
123
+ readonly search: {
124
+ readonly method: "POST";
125
+ readonly path: "/desearch/instagram/search";
126
+ readonly required: readonly ["query"];
127
+ readonly optional: readonly ["count"];
128
+ readonly list: true;
129
+ };
130
+ readonly media: {
131
+ readonly method: "GET";
132
+ readonly path: "/desearch/instagram/media/{id}";
133
+ readonly required: readonly ["id"];
134
+ readonly optional: readonly [];
135
+ };
136
+ readonly profile: {
137
+ readonly method: "GET";
138
+ readonly path: "/desearch/instagram/profile/{username}";
139
+ readonly required: readonly ["username"];
140
+ readonly optional: readonly [];
141
+ };
142
+ readonly profile_posts: {
143
+ readonly method: "GET";
144
+ readonly path: "/desearch/instagram/profile/{username}/posts";
145
+ readonly required: readonly ["username"];
146
+ readonly optional: readonly ["count", "cursor"];
147
+ readonly list: true;
148
+ };
149
+ readonly comments: {
150
+ readonly method: "GET";
151
+ readonly path: "/desearch/instagram/comments/{shortcode}";
152
+ readonly required: readonly ["shortcode"];
153
+ readonly optional: readonly ["count", "cursor"];
154
+ readonly list: true;
155
+ };
156
+ readonly hashtag: {
157
+ readonly method: "GET";
158
+ readonly path: "/desearch/instagram/hashtag/{tag}";
159
+ readonly required: readonly ["tag"];
160
+ readonly optional: readonly ["count", "cursor"];
161
+ readonly list: true;
162
+ };
163
+ };
164
+ };
165
+ export type SocialAction<P extends SocialPlatform> = keyof (typeof SOCIAL_ACTIONS)[P] & string;
166
+ /** Action names in table order, for the tool's `action` enum. */
167
+ export declare function socialActionNames<P extends SocialPlatform>(platform: P): [SocialAction<P>, ...SocialAction<P>[]];
168
+ /** "video_id (required), count, cursor" */
169
+ export declare function socialActionUsage(platform: SocialPlatform, action: string): string;
170
+ /**
171
+ * The route and arguments for one call. Throws before any request when a needed
172
+ * argument is missing or an argument does not apply to the action.
173
+ */
174
+ export declare function socialRequest(platform: SocialPlatform, args: Record<string, unknown>): {
175
+ spec: SocialActionSpec;
176
+ path: string;
177
+ values: Record<string, string | number>;
178
+ };
179
+ /** One sentence on how to get the next page. */
180
+ export declare function socialNextStep(platform: SocialPlatform, action: string, spec: SocialActionSpec, nextCursor: string | null): string;
181
+ /**
182
+ * Run one `tiktok`, `facebook`, or `instagram` action. A single post, profile, or
183
+ * media item comes back as the API sent it. A list comes back as
184
+ * `{ results, next_cursor, next }`: `next_cursor` is the `x-desearch-next-cursor`
185
+ * header (null on the last page) and `next` says how to ask for the next page.
186
+ */
187
+ export declare function runSocialAction(call: DesearchApi, platform: SocialPlatform, args: Record<string, unknown>): Promise<unknown>;
188
+ //# sourceMappingURL=social.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"social.d.ts","sourceRoot":"","sources":["../social.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,gBAAgB,8CAA+C,CAAC;AAC7E,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D,eAAO,MAAM,kBAAkB,2BAA2B,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,8EAA8E;IAC9E,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,8CAA8C;IAC9C,IAAI,CAAC,EAAE,IAAI,CAAC;CACf;AAED,eAAO,MAAM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+ * TikTok, Facebook, and Instagram on the Desearch API (`/desearch/{platform}/*`).
3
+ *
4
+ * desearch-js 1.5 has no social methods, so the `tiktok`, `facebook`, and
5
+ * `instagram` tools call these routes through `desearch-api.ts`. Each tool takes an
6
+ * `action` that picks one route; the table below says which arguments each route
7
+ * needs and accepts, and the request is refused before it is sent when they do not match.
8
+ *
9
+ * Paging (desearch-public-api docs/social-pagination.md): a list route answers with a
10
+ * JSON array and, when there is another page, an `x-desearch-next-cursor` header.
11
+ * The caller sends that value back unchanged as `cursor`, on the same route with the
12
+ * same target. The header is absent on the last page. A cursor is opaque and lasts
13
+ * 24 hours; this module never builds or changes one.
14
+ */
15
+ export const SOCIAL_PLATFORMS = ["tiktok", "facebook", "instagram"];
16
+ export const NEXT_CURSOR_HEADER = "x-desearch-next-cursor";
17
+ export const SOCIAL_ACTIONS = {
18
+ tiktok: {
19
+ search: {
20
+ method: "POST",
21
+ path: "/desearch/tiktok/search",
22
+ required: ["query"],
23
+ optional: ["count", "sort", "cursor"],
24
+ list: true,
25
+ },
26
+ post: { method: "GET", path: "/desearch/tiktok/post/{id}", required: ["id"], optional: [] },
27
+ profile: { method: "GET", path: "/desearch/tiktok/profile/{username}", required: ["username"], optional: [] },
28
+ profile_posts: {
29
+ method: "GET",
30
+ path: "/desearch/tiktok/profile/{username}/posts",
31
+ required: ["username"],
32
+ optional: ["count", "cursor"],
33
+ list: true,
34
+ },
35
+ comments: {
36
+ method: "GET",
37
+ path: "/desearch/tiktok/comments/{video_id}",
38
+ required: ["video_id"],
39
+ optional: ["count", "cursor"],
40
+ list: true,
41
+ },
42
+ hashtag: {
43
+ method: "GET",
44
+ path: "/desearch/tiktok/hashtag/{tag}",
45
+ required: ["tag"],
46
+ optional: ["count", "cursor"],
47
+ list: true,
48
+ },
49
+ trending: {
50
+ method: "GET",
51
+ path: "/desearch/tiktok/trending",
52
+ required: [],
53
+ optional: ["region", "count"],
54
+ list: true,
55
+ },
56
+ },
57
+ facebook: {
58
+ search: {
59
+ method: "POST",
60
+ path: "/desearch/facebook/search",
61
+ required: ["query"],
62
+ optional: ["count", "cursor"],
63
+ list: true,
64
+ },
65
+ post: { method: "GET", path: "/desearch/facebook/post/{id}", required: ["id"], optional: [] },
66
+ profile: {
67
+ method: "GET",
68
+ path: "/desearch/facebook/profile/{profile_id}",
69
+ required: ["profile_id"],
70
+ optional: [],
71
+ },
72
+ profile_posts: {
73
+ method: "GET",
74
+ path: "/desearch/facebook/profile/{profile_id}/posts",
75
+ required: ["profile_id"],
76
+ optional: ["count", "cursor"],
77
+ list: true,
78
+ },
79
+ comments: {
80
+ method: "GET",
81
+ path: "/desearch/facebook/comments/{post_id}",
82
+ required: ["post_id"],
83
+ optional: ["count", "cursor"],
84
+ list: true,
85
+ },
86
+ hashtag: {
87
+ method: "GET",
88
+ path: "/desearch/facebook/hashtag/{tag}",
89
+ required: ["tag"],
90
+ optional: ["count", "cursor"],
91
+ list: true,
92
+ },
93
+ },
94
+ instagram: {
95
+ // Instagram search returns one page; the API answers 422 to any cursor.
96
+ search: {
97
+ method: "POST",
98
+ path: "/desearch/instagram/search",
99
+ required: ["query"],
100
+ optional: ["count"],
101
+ list: true,
102
+ },
103
+ media: { method: "GET", path: "/desearch/instagram/media/{id}", required: ["id"], optional: [] },
104
+ profile: {
105
+ method: "GET",
106
+ path: "/desearch/instagram/profile/{username}",
107
+ required: ["username"],
108
+ optional: [],
109
+ },
110
+ profile_posts: {
111
+ method: "GET",
112
+ path: "/desearch/instagram/profile/{username}/posts",
113
+ required: ["username"],
114
+ optional: ["count", "cursor"],
115
+ list: true,
116
+ },
117
+ comments: {
118
+ method: "GET",
119
+ path: "/desearch/instagram/comments/{shortcode}",
120
+ required: ["shortcode"],
121
+ optional: ["count", "cursor"],
122
+ list: true,
123
+ },
124
+ hashtag: {
125
+ method: "GET",
126
+ path: "/desearch/instagram/hashtag/{tag}",
127
+ required: ["tag"],
128
+ optional: ["count", "cursor"],
129
+ list: true,
130
+ },
131
+ },
132
+ };
133
+ /** Action names in table order, for the tool's `action` enum. */
134
+ export function socialActionNames(platform) {
135
+ return Object.keys(SOCIAL_ACTIONS[platform]);
136
+ }
137
+ function specFor(platform, action) {
138
+ const actions = SOCIAL_ACTIONS[platform];
139
+ return Object.hasOwn(actions, action) ? actions[action] : undefined;
140
+ }
141
+ /** "video_id (required), count, cursor" */
142
+ export function socialActionUsage(platform, action) {
143
+ const spec = specFor(platform, action);
144
+ if (!spec) {
145
+ return "";
146
+ }
147
+ const parts = [...spec.required.map((name) => `${name} (required)`), ...spec.optional];
148
+ return parts.length > 0 ? parts.join(", ") : "no other arguments";
149
+ }
150
+ /**
151
+ * Light clean-up of a target: trim it, and drop a leading "@" from a username or
152
+ * "#" from a tag, which the API takes without them. Cursors are never touched.
153
+ */
154
+ function cleanTarget(name, value) {
155
+ const trimmed = value.trim();
156
+ if (name === "username") {
157
+ return trimmed.replace(/^@+/, "");
158
+ }
159
+ if (name === "tag") {
160
+ return trimmed.replace(/^#+/, "");
161
+ }
162
+ return trimmed;
163
+ }
164
+ const ARGUMENT_NAMES = [
165
+ "query",
166
+ "sort",
167
+ "id",
168
+ "username",
169
+ "profile_id",
170
+ "post_id",
171
+ "video_id",
172
+ "shortcode",
173
+ "tag",
174
+ "region",
175
+ "count",
176
+ "cursor",
177
+ ];
178
+ /**
179
+ * The route and arguments for one call. Throws before any request when a needed
180
+ * argument is missing or an argument does not apply to the action.
181
+ */
182
+ export function socialRequest(platform, args) {
183
+ const action = String(args.action);
184
+ const spec = specFor(platform, action);
185
+ if (!spec) {
186
+ throw new Error(`Unknown ${platform} action "${action}". Actions: ${Object.keys(SOCIAL_ACTIONS[platform]).join(", ")}.`);
187
+ }
188
+ const accepted = new Set([...spec.required, ...spec.optional]);
189
+ const values = {};
190
+ const extra = [];
191
+ for (const name of ARGUMENT_NAMES) {
192
+ const raw = args[name];
193
+ if (raw === undefined) {
194
+ continue;
195
+ }
196
+ if (!accepted.has(name)) {
197
+ extra.push(name);
198
+ continue;
199
+ }
200
+ values[name] =
201
+ typeof raw === "string" && spec.required.includes(name) ? cleanTarget(name, raw) : raw;
202
+ }
203
+ const missing = spec.required.filter((name) => values[name] === undefined || values[name] === "");
204
+ if (missing.length > 0 || extra.length > 0) {
205
+ const problems = [];
206
+ if (missing.length > 0) {
207
+ problems.push(`${platform} action "${action}" needs ${missing.join(" and ")}.`);
208
+ }
209
+ if (extra.length > 0) {
210
+ problems.push(`${platform} action "${action}" does not take ${extra.join(", ")}.`);
211
+ }
212
+ throw new Error(`${problems.join(" ")} ${action} takes: ${socialActionUsage(platform, action)}. No request was sent.`);
213
+ }
214
+ const inPath = new Set();
215
+ const path = spec.path.replace(/\{(\w+)\}/g, (_, name) => {
216
+ inPath.add(name);
217
+ // {id:path} routes accept a "/" in the value; encoded, it still reaches the route as one value.
218
+ return encodeURIComponent(String(values[name]));
219
+ });
220
+ const rest = {};
221
+ for (const [name, value] of Object.entries(values)) {
222
+ if (!inPath.has(name)) {
223
+ rest[name] = value;
224
+ }
225
+ }
226
+ return { spec, path, values: rest };
227
+ }
228
+ /** One sentence on how to get the next page. */
229
+ export function socialNextStep(platform, action, spec, nextCursor) {
230
+ if (!spec.optional.includes("cursor")) {
231
+ return "This action returns one page and takes no cursor.";
232
+ }
233
+ if (nextCursor === null) {
234
+ return "Last page: there are no more results.";
235
+ }
236
+ const same = spec.required.length > 0 ? `, the same ${spec.required.join(" and ")},` : "";
237
+ return `More results: call ${platform} again with action "${action}"${same} and cursor set to next_cursor, unchanged. A cursor works for 24 hours.`;
238
+ }
239
+ /**
240
+ * Run one `tiktok`, `facebook`, or `instagram` action. A single post, profile, or
241
+ * media item comes back as the API sent it. A list comes back as
242
+ * `{ results, next_cursor, next }`: `next_cursor` is the `x-desearch-next-cursor`
243
+ * header (null on the last page) and `next` says how to ask for the next page.
244
+ */
245
+ export async function runSocialAction(call, platform, args) {
246
+ const { spec, path, values } = socialRequest(platform, args);
247
+ const response = spec.method === "POST" ? await call("POST", path, { body: values }) : await call("GET", path, { query: values });
248
+ if (!spec.list) {
249
+ return response.data;
250
+ }
251
+ const header = response.headers.get(NEXT_CURSOR_HEADER);
252
+ const nextCursor = header ? header : null;
253
+ return {
254
+ results: response.data,
255
+ next_cursor: nextCursor,
256
+ next: socialNextStep(platform, String(args.action), spec, nextCursor),
257
+ };
258
+ }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "desearch-mcp-server",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "mcpName": "io.github.Desearch-ai/mcp-desearch",
5
- "description": "AI search (web, Reddit, Hacker News, arXiv, Wikipedia, and Twitter), X (Twitter) search, web search, page extraction, X data, and People Search (find people and creators on X, YouTube, LinkedIn, and TikTok) tools for AI agents.",
5
+ "description": "AI search (web, Reddit, Hacker News, arXiv, Wikipedia, and Twitter), X (Twitter) search, web search, the Search API, public TikTok, Facebook, and Instagram data, People Search exports, page extraction, X data, People Search (find people and creators on X, YouTube, LinkedIn, and TikTok), and Company Search (find companies and their public contacts and leaders, or enrich domains you send) tools for AI agents. Includes 36 tools.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://desearch.ai",
8
8
  "type": "module",
@@ -45,9 +45,14 @@
45
45
  "creator-search",
46
46
  "influencer-search",
47
47
  "lead-generation",
48
+ "company-search",
49
+ "company-enrich",
50
+ "company-enrichment",
48
51
  "youtube",
49
52
  "tiktok",
50
- "linkedin"
53
+ "linkedin",
54
+ "instagram",
55
+ "facebook"
51
56
  ],
52
57
  "scripts": {
53
58
  "build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\"",