desearch-mcp-server 0.6.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.
- package/CHANGELOG.md +16 -0
- package/README.md +45 -4
- package/build/companies.d.ts +6 -3
- package/build/companies.d.ts.map +1 -1
- package/build/companies.js +8 -4
- package/build/desearch-api.d.ts +31 -0
- package/build/desearch-api.d.ts.map +1 -0
- package/build/desearch-api.js +67 -0
- package/build/people.d.ts +64 -15
- package/build/people.d.ts.map +1 -1
- package/build/people.js +152 -68
- package/build/server.d.ts +4 -1
- package/build/server.d.ts.map +1 -1
- package/build/server.js +199 -6
- package/build/social.d.ts +188 -0
- package/build/social.d.ts.map +1 -0
- package/build/social.js +258 -0
- package/package.json +5 -3
package/build/people.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DESEARCH_API_BASE_URL, createDesearchApi } from "./desearch-api.js";
|
|
2
2
|
/**
|
|
3
3
|
* People Search on the Desearch API (`/desearch/people/*`).
|
|
4
4
|
*
|
|
5
5
|
* desearch-js 1.5 has no People Search methods, so this module calls the routes
|
|
6
|
-
* directly with the same base URL, `Authorization: <key>`
|
|
7
|
-
* `HTTP <status>: <detail>` error text that desearch-js uses.
|
|
6
|
+
* directly through `desearch-api.ts`, with the same base URL, `Authorization: <key>`
|
|
7
|
+
* header, and `HTTP <status>: <detail>` error text that desearch-js uses.
|
|
8
8
|
*
|
|
9
9
|
* - `POST /desearch/people/search/{platform}` starts a background search and is billed:
|
|
10
10
|
* it reserves `count` people at the route price and settles to what it delivers.
|
|
11
|
-
* - Every other route (tasks, results, pause/resume/cancel, profiles) is free.
|
|
11
|
+
* - Every other route (tasks, results, pause/resume/cancel, profiles, exports) is free.
|
|
12
12
|
*/
|
|
13
|
-
export const PEOPLE_API_BASE_URL =
|
|
13
|
+
export const PEOPLE_API_BASE_URL = DESEARCH_API_BASE_URL;
|
|
14
14
|
export const PEOPLE_PLATFORMS = ["x", "youtube", "linkedin", "tiktok"];
|
|
15
15
|
export const PEOPLE_TASK_STATUSES = [
|
|
16
16
|
"queued",
|
|
@@ -82,90 +82,44 @@ export const PEOPLE_SEARCH_FILTER_NAMES = [
|
|
|
82
82
|
"keywords",
|
|
83
83
|
"exclude_keywords",
|
|
84
84
|
];
|
|
85
|
+
export const PEOPLE_EXPORT_FORMATS = ["csv", "jsonl"];
|
|
85
86
|
function isPlainObject(value) {
|
|
86
87
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
87
88
|
}
|
|
88
|
-
function errorDetail(data, text) {
|
|
89
|
-
if (isPlainObject(data) && data.detail !== undefined) {
|
|
90
|
-
const detail = typeof data.detail === "string" ? data.detail : JSON.stringify(data.detail);
|
|
91
|
-
const task = isPlainObject(data.task) ? data.task : undefined;
|
|
92
|
-
return typeof task?.status === "string" ? `${detail} Task status: ${task.status}.` : detail;
|
|
93
|
-
}
|
|
94
|
-
return text.length > 500 ? `${text.slice(0, 500)}...` : text;
|
|
95
|
-
}
|
|
96
|
-
export function withQuery(path, params) {
|
|
97
|
-
const search = new URLSearchParams();
|
|
98
|
-
for (const [key, value] of Object.entries(params)) {
|
|
99
|
-
if (value !== undefined) {
|
|
100
|
-
search.append(key, String(value));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const qs = search.toString();
|
|
104
|
-
return qs ? `${path}?${qs}` : path;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* One Desearch API request with the desearch-js conventions: `Authorization: <key>`,
|
|
108
|
-
* a JSON body, and `HTTP <status>: <detail>` on an error status. People Search and
|
|
109
|
-
* Company Search (companies.ts) share it.
|
|
110
|
-
*/
|
|
111
|
-
export function createApiCall(apiKey, baseUrl = PEOPLE_API_BASE_URL) {
|
|
112
|
-
return async function call(method, path, options = {}) {
|
|
113
|
-
const headers = { Authorization: apiKey, ...options.headers };
|
|
114
|
-
if (options.body) {
|
|
115
|
-
headers["Content-Type"] = "application/json";
|
|
116
|
-
}
|
|
117
|
-
let response;
|
|
118
|
-
let text;
|
|
119
|
-
try {
|
|
120
|
-
response = await fetch(`${baseUrl}${path}`, {
|
|
121
|
-
method,
|
|
122
|
-
headers,
|
|
123
|
-
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
124
|
-
});
|
|
125
|
-
text = await response.text();
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
throw new Error(`Unexpected Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
129
|
-
}
|
|
130
|
-
let data = text;
|
|
131
|
-
if (text) {
|
|
132
|
-
try {
|
|
133
|
-
data = JSON.parse(text);
|
|
134
|
-
}
|
|
135
|
-
catch {
|
|
136
|
-
// Not JSON: keep the text.
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (!response.ok) {
|
|
140
|
-
throw new Error(`HTTP ${response.status}: ${errorDetail(data, text)}`);
|
|
141
|
-
}
|
|
142
|
-
return { status: response.status, data };
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
89
|
export function createPeopleClient(apiKey, baseUrl = PEOPLE_API_BASE_URL) {
|
|
146
|
-
|
|
90
|
+
return peopleClientFor(createDesearchApi(apiKey, baseUrl));
|
|
91
|
+
}
|
|
92
|
+
/** A People Search client on an existing API caller, so the server shares one per key. */
|
|
93
|
+
export function peopleClientFor(call) {
|
|
147
94
|
const taskPath = (taskId) => `/desearch/people/tasks/${encodeURIComponent(taskId)}`;
|
|
148
95
|
return {
|
|
149
|
-
startSearch(platform, body, idempotencyKey) {
|
|
150
|
-
|
|
96
|
+
async startSearch(platform, body, idempotencyKey) {
|
|
97
|
+
const { status, data } = await call("POST", `/desearch/people/search/${platform}`, {
|
|
151
98
|
body,
|
|
152
99
|
headers: idempotencyKey ? { "Idempotency-Key": idempotencyKey } : undefined,
|
|
153
100
|
});
|
|
101
|
+
return { status, data };
|
|
154
102
|
},
|
|
155
103
|
async getTask(taskId) {
|
|
156
104
|
return (await call("GET", taskPath(taskId))).data;
|
|
157
105
|
},
|
|
158
106
|
async getResults(taskId, params) {
|
|
159
|
-
return (await call("GET",
|
|
107
|
+
return (await call("GET", `${taskPath(taskId)}/results`, { query: params })).data;
|
|
160
108
|
},
|
|
161
109
|
async controlTask(taskId, action) {
|
|
162
110
|
return (await call("POST", `${taskPath(taskId)}/${action}`)).data;
|
|
163
111
|
},
|
|
164
112
|
async listTasks(params) {
|
|
165
|
-
return (await call("GET",
|
|
113
|
+
return (await call("GET", "/desearch/people/tasks", { query: params })).data;
|
|
166
114
|
},
|
|
167
115
|
async listProfiles(params) {
|
|
168
|
-
return (await call("GET",
|
|
116
|
+
return (await call("GET", "/desearch/people/profiles", { query: params })).data;
|
|
117
|
+
},
|
|
118
|
+
async exportTask(taskId, params) {
|
|
119
|
+
return (await call("GET", `${taskPath(taskId)}/export`, { query: params })).text;
|
|
120
|
+
},
|
|
121
|
+
async exportProfiles(params) {
|
|
122
|
+
return (await call("GET", "/desearch/people/profiles/export", { query: params })).text;
|
|
169
123
|
},
|
|
170
124
|
};
|
|
171
125
|
}
|
|
@@ -497,3 +451,133 @@ export async function listPeopleProfiles(client, args) {
|
|
|
497
451
|
profiles: arrayOf(page.profiles).map(compactPerson),
|
|
498
452
|
};
|
|
499
453
|
}
|
|
454
|
+
/** Rows `people-search-export` returns when the caller does not set `max_rows`. */
|
|
455
|
+
export const PEOPLE_EXPORT_DEFAULT_ROWS = 100;
|
|
456
|
+
export const PEOPLE_EXPORT_MAX_ROWS = 1000;
|
|
457
|
+
/** Most characters of file text one reply carries; whole rows only. */
|
|
458
|
+
export const PEOPLE_EXPORT_MAX_CHARS = 50_000;
|
|
459
|
+
/**
|
|
460
|
+
* End offset (after the line break) of each non-blank record. CSV fields in quotes
|
|
461
|
+
* may hold line breaks, so a CSV line break only ends a record outside quotes; a
|
|
462
|
+
* doubled quote inside a field toggles twice and changes nothing. JSON Lines escape
|
|
463
|
+
* line breaks, so every line is a record.
|
|
464
|
+
*/
|
|
465
|
+
export function exportRecordEnds(text, format) {
|
|
466
|
+
const ends = [];
|
|
467
|
+
const csv = format === "csv";
|
|
468
|
+
let inQuotes = false;
|
|
469
|
+
let start = 0;
|
|
470
|
+
for (let i = 0; i < text.length; i++) {
|
|
471
|
+
const ch = text[i];
|
|
472
|
+
if (csv && ch === '"') {
|
|
473
|
+
inQuotes = !inQuotes;
|
|
474
|
+
}
|
|
475
|
+
else if (ch === "\n" && !inQuotes) {
|
|
476
|
+
if (text.slice(start, i).trim() !== "") {
|
|
477
|
+
ends.push(i + 1);
|
|
478
|
+
}
|
|
479
|
+
start = i + 1;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (text.slice(start).trim() !== "") {
|
|
483
|
+
ends.push(text.length);
|
|
484
|
+
}
|
|
485
|
+
return ends;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Keep the CSV header and at most `maxRows` whole rows that fit in `maxChars`.
|
|
489
|
+
* The kept text is a prefix of the file, so it parses the same way the file does.
|
|
490
|
+
*/
|
|
491
|
+
export function truncateExport(text, format, maxRows, maxChars = PEOPLE_EXPORT_MAX_CHARS) {
|
|
492
|
+
const ends = exportRecordEnds(text, format);
|
|
493
|
+
const headerRecords = format === "csv" && ends.length > 0 ? 1 : 0;
|
|
494
|
+
const totalRows = ends.length - headerRecords;
|
|
495
|
+
let end = headerRecords ? ends[0] : 0;
|
|
496
|
+
let kept = 0;
|
|
497
|
+
let charLimited = false;
|
|
498
|
+
for (let i = headerRecords; i < ends.length && kept < maxRows; i++) {
|
|
499
|
+
if (ends[i] > maxChars) {
|
|
500
|
+
charLimited = true;
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
end = ends[i];
|
|
504
|
+
kept++;
|
|
505
|
+
}
|
|
506
|
+
const cut = totalRows - kept;
|
|
507
|
+
return {
|
|
508
|
+
// A file without rows (only a header, or empty) comes back unchanged.
|
|
509
|
+
text: cut === 0 ? text : text.slice(0, end),
|
|
510
|
+
total_rows: totalRows,
|
|
511
|
+
returned_rows: kept,
|
|
512
|
+
cut_rows: cut,
|
|
513
|
+
char_limited: charLimited,
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
function exportQuery(args) {
|
|
517
|
+
return {
|
|
518
|
+
format: args.format,
|
|
519
|
+
has: args.has?.length ? args.has.join(",") : undefined,
|
|
520
|
+
min_audience: args.min_audience,
|
|
521
|
+
max_audience: args.max_audience,
|
|
522
|
+
min_score: args.min_score,
|
|
523
|
+
location: args.location,
|
|
524
|
+
verified: args.verified,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* `people-search-export`: one search's people (`task_id`) or everyone the caller's
|
|
529
|
+
* searches found on a platform (`platform`), as CSV or JSON Lines text cut to
|
|
530
|
+
* `max_rows` rows and PEOPLE_EXPORT_MAX_CHARS characters.
|
|
531
|
+
*/
|
|
532
|
+
export async function exportPeople(client, args) {
|
|
533
|
+
const format = args.format ?? "csv";
|
|
534
|
+
const maxRows = args.max_rows ?? PEOPLE_EXPORT_DEFAULT_ROWS;
|
|
535
|
+
let text;
|
|
536
|
+
let what;
|
|
537
|
+
let route;
|
|
538
|
+
if (args.task_id !== undefined) {
|
|
539
|
+
const profileOnly = ["platform", "q", "sort"].filter((key) => args[key] !== undefined);
|
|
540
|
+
if (profileOnly.length > 0) {
|
|
541
|
+
throw new Error(`${profileOnly.join(", ")} ${profileOnly.length === 1 ? "applies" : "apply"} only to a platform export. Send task_id to export one search, or platform (without task_id) to export everyone your searches found on it.`);
|
|
542
|
+
}
|
|
543
|
+
text = await client.exportTask(args.task_id, exportQuery({ ...args, format }));
|
|
544
|
+
what = `task ${args.task_id}`;
|
|
545
|
+
route = `/desearch/people/tasks/${args.task_id}/export?format=${format}`;
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
if (args.platform === undefined) {
|
|
549
|
+
throw new Error("Send task_id to export one search, or platform to export everyone your searches found on it.");
|
|
550
|
+
}
|
|
551
|
+
text = await client.exportProfiles({
|
|
552
|
+
platform: args.platform,
|
|
553
|
+
q: args.q,
|
|
554
|
+
sort: args.sort,
|
|
555
|
+
...exportQuery({ ...args, format }),
|
|
556
|
+
});
|
|
557
|
+
what = `everyone found on ${args.platform}`;
|
|
558
|
+
route = `/desearch/people/profiles/export?platform=${args.platform}&format=${format}`;
|
|
559
|
+
}
|
|
560
|
+
const kept = truncateExport(text, format, maxRows);
|
|
561
|
+
const label = format === "csv" ? "CSV" : "JSON Lines";
|
|
562
|
+
const rows = (n) => `${n} ${n === 1 ? "row" : "rows"}`;
|
|
563
|
+
let note;
|
|
564
|
+
if (kept.cut_rows === 0) {
|
|
565
|
+
note = `${label} export of ${what}: ${rows(kept.total_rows)}, all shown.`;
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
const reason = kept.char_limited
|
|
569
|
+
? `to keep this reply under ${PEOPLE_EXPORT_MAX_CHARS.toLocaleString("en-US")} characters`
|
|
570
|
+
: `by max_rows ${maxRows}`;
|
|
571
|
+
note =
|
|
572
|
+
`${label} export of ${what}: ${rows(kept.total_rows)}. Showing the first ${rows(kept.returned_rows)}; ` +
|
|
573
|
+
`${rows(kept.cut_rows)} ${kept.cut_rows === 1 ? "was" : "were"} cut ${reason}. ` +
|
|
574
|
+
`For the whole file, call GET ${PEOPLE_API_BASE_URL}${route} (plus the same filters) with your API key, or page through people with people-search-status or people-profiles.`;
|
|
575
|
+
}
|
|
576
|
+
return {
|
|
577
|
+
note,
|
|
578
|
+
text: kept.text,
|
|
579
|
+
total_rows: kept.total_rows,
|
|
580
|
+
returned_rows: kept.returned_rows,
|
|
581
|
+
cut_rows: kept.cut_rows,
|
|
582
|
+
};
|
|
583
|
+
}
|
package/build/server.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type Icon } from "@modelcontextprotocol/sdk/types.js";
|
|
|
3
3
|
import { type PeopleClient } from "./people.js";
|
|
4
4
|
import { type CompanyClient } from "./companies.js";
|
|
5
5
|
export declare const SERVER_NAME = "Desearch";
|
|
6
|
-
export declare const SERVER_VERSION = "0.
|
|
6
|
+
export declare const SERVER_VERSION = "0.7.0";
|
|
7
7
|
export declare const SERVER_TITLE = "Desearch";
|
|
8
8
|
export declare const SERVER_WEBSITE_URL = "https://www.desearch.ai";
|
|
9
9
|
export declare const MCP_PUBLIC_BASE_URL: string;
|
|
@@ -106,6 +106,9 @@ export declare function presentSearchBody(value: unknown): unknown;
|
|
|
106
106
|
* `client`, `peopleClient`, and `companyClient` are test seams. Production callers omit
|
|
107
107
|
* them and the server builds a desearch-js client, a People Search client (people.ts), and
|
|
108
108
|
* a Company Search client (companies.ts) from `apiKey`.
|
|
109
|
+
* The routes desearch-js 1.5 does not cover (People Search, Company Search, TikTok,
|
|
110
|
+
* Facebook, Instagram, `POST /search`) share one direct API caller (desearch-api.ts)
|
|
111
|
+
* for that key.
|
|
109
112
|
*/
|
|
110
113
|
export declare function createDesearchMcpServer(apiKey: string, client?: DesearchClient, peopleClient?: PeopleClient, companyClient?: CompanyClient): McpServer;
|
|
111
114
|
export {};
|
package/build/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAKH,KAAK,IAAI,EAEZ,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAKH,KAAK,IAAI,EAEZ,MAAM,oCAAoC,CAAC;AAI5C,OAAO,EAqBH,KAAK,YAAY,EACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAcH,KAAK,aAAa,EACrB,MAAM,gBAAgB,CAAC;AAIxB,eAAO,MAAM,WAAW,aAAa,CAAC;AACtC,eAAO,MAAM,cAAc,UAAU,CAAC;AACtC,e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C,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7F,OAAO,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtE,OAAO,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACvD,QAAQ,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3D;AA2UD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AAuCvD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAYzD;AAgJD;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACnC,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,cAAc,EACvB,YAAY,CAAC,EAAE,YAAY,EAC3B,aAAa,CAAC,EAAE,aAAa,GAC9B,SAAS,CA+xCX"}
|
package/build/server.js
CHANGED
|
@@ -2,11 +2,13 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
2
2
|
import { ListPromptsRequestSchema, ListResourcesRequestSchema, ListResourceTemplatesRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
3
3
|
import DesearchImport from "desearch-js";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { createDesearchApi } from "./desearch-api.js";
|
|
6
|
+
import { PEOPLE_EXPORT_DEFAULT_ROWS, PEOPLE_EXPORT_FORMATS, PEOPLE_EXPORT_MAX_CHARS, PEOPLE_EXPORT_MAX_ROWS, PEOPLE_FILTER_CHANNELS, PEOPLE_METADATA_KEY_PATTERN, PEOPLE_METADATA_MAX_FILTERS, PEOPLE_METADATA_MAX_KEYS, PEOPLE_METADATA_VALUE_MAX, PEOPLE_PLATFORMS, PEOPLE_PROFILE_SORTS, PEOPLE_SEARCH_FILTERS, PEOPLE_TASK_STATUSES, controlPeopleTask, exportPeople, listPeopleProfiles, listPeopleTasks, peopleClientFor, readPeopleStatus, startPeopleSearch, } from "./people.js";
|
|
7
|
+
import { COMPANY_COUNTRIES_MAX, COMPANY_DOMAINS_MAX, COMPANY_EXCLUDE_MAX, COMPANY_REQUIREMENTS, COMPANY_ROLES, COMPANY_TASK_STATUSES, COMPANY_TASK_TYPES, companyClientFor, controlCompanyTask, listCompanyTasks, readCompanyStatus, startCompanyEnrich, startCompanySearch, } from "./companies.js";
|
|
8
|
+
import { runSocialAction, socialActionNames } from "./social.js";
|
|
7
9
|
import { AI_SEARCH_TOOLS, WEB_LINK_TOOLS, toolIdSchema } from "./tool-sources.js";
|
|
8
10
|
export const SERVER_NAME = "Desearch";
|
|
9
|
-
export const SERVER_VERSION = "0.
|
|
11
|
+
export const SERVER_VERSION = "0.7.0";
|
|
10
12
|
export const SERVER_TITLE = "Desearch";
|
|
11
13
|
export const SERVER_WEBSITE_URL = "https://www.desearch.ai";
|
|
12
14
|
// Public origin of the hosted server, which serves the icons below.
|
|
@@ -118,6 +120,43 @@ const peoplePlatform = z
|
|
|
118
120
|
function strictArgs(shape) {
|
|
119
121
|
return z.object(shape).strict();
|
|
120
122
|
}
|
|
123
|
+
// Social tool arguments. A new schema per field, like peopleKeywordList: one shared
|
|
124
|
+
// instance in a tool's schema would serialize as a JSON Schema $ref.
|
|
125
|
+
function socialTarget(description) {
|
|
126
|
+
return z.string().min(1).max(2048).optional().describe(description);
|
|
127
|
+
}
|
|
128
|
+
function socialCount() {
|
|
129
|
+
return z
|
|
130
|
+
.number()
|
|
131
|
+
.int()
|
|
132
|
+
.min(1)
|
|
133
|
+
.max(100)
|
|
134
|
+
.optional()
|
|
135
|
+
.describe("Most items to return (1-100). API default: 10 for search, 20 for the other list actions. One page may hold fewer.");
|
|
136
|
+
}
|
|
137
|
+
function socialCursor() {
|
|
138
|
+
return z
|
|
139
|
+
.string()
|
|
140
|
+
.min(1)
|
|
141
|
+
.max(4096)
|
|
142
|
+
.optional()
|
|
143
|
+
.describe("next_cursor from the previous page of the same action and target, sent back unchanged. Omit it for the first page.");
|
|
144
|
+
}
|
|
145
|
+
function socialQuery(example) {
|
|
146
|
+
return z
|
|
147
|
+
.string()
|
|
148
|
+
.min(1)
|
|
149
|
+
.max(1000)
|
|
150
|
+
.optional()
|
|
151
|
+
.describe(`search: keyword or phrase, example: '${example}'.`);
|
|
152
|
+
}
|
|
153
|
+
function socialTag() {
|
|
154
|
+
return socialTarget("hashtag: the hashtag without #, example: 'ai'. A leading # is removed.");
|
|
155
|
+
}
|
|
156
|
+
function socialAction(platform, description) {
|
|
157
|
+
return z.enum(socialActionNames(platform)).describe(description);
|
|
158
|
+
}
|
|
159
|
+
const SOCIAL_PAGING = "List actions return { results, next_cursor, next }. For the next page, call again with the same action and target and cursor set to next_cursor, unchanged; next_cursor is null on the last page. A cursor lasts 24 hours.";
|
|
121
160
|
// A new schema per field: one shared instance would serialize as a JSON Schema $ref.
|
|
122
161
|
function peopleKeywordList() {
|
|
123
162
|
return z.array(z.string().min(1).max(120)).max(20);
|
|
@@ -412,11 +451,15 @@ function registerTool(server, apiKey, name, title, description, inputSchema, han
|
|
|
412
451
|
* `client`, `peopleClient`, and `companyClient` are test seams. Production callers omit
|
|
413
452
|
* them and the server builds a desearch-js client, a People Search client (people.ts), and
|
|
414
453
|
* a Company Search client (companies.ts) from `apiKey`.
|
|
454
|
+
* The routes desearch-js 1.5 does not cover (People Search, Company Search, TikTok,
|
|
455
|
+
* Facebook, Instagram, `POST /search`) share one direct API caller (desearch-api.ts)
|
|
456
|
+
* for that key.
|
|
415
457
|
*/
|
|
416
458
|
export function createDesearchMcpServer(apiKey, client, peopleClient, companyClient) {
|
|
417
459
|
const desearch = client ?? new Desearch(apiKey);
|
|
418
|
-
const
|
|
419
|
-
const
|
|
460
|
+
const api = createDesearchApi(apiKey);
|
|
461
|
+
const people = peopleClient ?? peopleClientFor(api);
|
|
462
|
+
const companies = companyClient ?? companyClientFor(api);
|
|
420
463
|
const serverInfo = {
|
|
421
464
|
name: SERVER_NAME,
|
|
422
465
|
version: SERVER_VERSION,
|
|
@@ -425,7 +468,7 @@ export function createDesearchMcpServer(apiKey, client, peopleClient, companyCli
|
|
|
425
468
|
icons: SERVER_ICONS,
|
|
426
469
|
};
|
|
427
470
|
const server = new McpServer(serverInfo, {
|
|
428
|
-
instructions: "Search the public web and X with Desearch. Use search for titles and links, then fetch with a result URL to read the page. Other tools cover AI search, X posts, and page extraction. People Search finds people and creators on X, YouTube, LinkedIn, and TikTok: people-search starts a paid job billed to the user's Desearch balance, people-search-status reads progress,
|
|
471
|
+
instructions: "Search the public web and X with Desearch. Use search for titles and links, then fetch with a result URL to read the page. search-api returns ranked pages with the passage that best matches the query. Other tools cover AI search, X posts, and page extraction. tiktok, facebook, and instagram read public posts, profiles, comments, and hashtags; their list actions return next_cursor for the next page. People Search finds people and creators on X, YouTube, LinkedIn, and TikTok: people-search starts a paid job billed to the user's Desearch balance, people-search-status reads progress, people-search-pause, people-search-resume, and people-search-cancel pause, resume, or cancel it, and people-search-export returns the people found as CSV or JSON Lines. Company Search finds companies on the web from a description and Company Enrich reads the domains you send; both collect public emails, phones, social profiles, and leaders (CEO, founders, CTO, CFO): company-search and company-enrich start paid jobs billed to the user's Desearch balance, company-search-status reads progress and the companies, and company-search-pause, company-search-resume, and company-search-cancel pause, resume, or cancel a task. Calls need a Desearch API key.",
|
|
429
472
|
});
|
|
430
473
|
registerTool(server, apiKey, "ai-search", "AI Search", "AI search and analysis on web using Desearch AI", {
|
|
431
474
|
prompt: z.string().describe("Question, example: 'What is the latest news on AI?'"),
|
|
@@ -716,6 +759,104 @@ export function createDesearchMcpServer(apiKey, client, peopleClient, companyCli
|
|
|
716
759
|
return fail("X Trends error", error);
|
|
717
760
|
}
|
|
718
761
|
});
|
|
762
|
+
registerTool(server, apiKey, "search-api", "Search API", "Search the web with the Desearch Search API and return ranked pages, each with its title, URL, publication date when known, and the passage that best matches the query. Set page_text to add each page's full text. Returns { results, cost_usd, usage_count, service, currency }. Use search for titles and links only, and web-search for SERP-style snippets.", {
|
|
763
|
+
query: z.string().min(1).max(2000).describe("Search query, example: 'Who won the 2024 Nobel Prize in Physics?'"),
|
|
764
|
+
mode: z
|
|
765
|
+
.enum(["fast", "balanced"])
|
|
766
|
+
.optional()
|
|
767
|
+
.describe("'fast' returns results sooner; 'balanced' (API default) favors relevance."),
|
|
768
|
+
count: z
|
|
769
|
+
.number()
|
|
770
|
+
.int()
|
|
771
|
+
.min(10)
|
|
772
|
+
.max(20)
|
|
773
|
+
.multipleOf(5)
|
|
774
|
+
.optional()
|
|
775
|
+
.describe("Number of results: 10 (API default), 15, or 20."),
|
|
776
|
+
start_date: z
|
|
777
|
+
.string()
|
|
778
|
+
.regex(/^\d{4}-\d{2}-\d{2}$/, "Use YYYY-MM-DD")
|
|
779
|
+
.optional()
|
|
780
|
+
.describe("Only pages published on or after this date (YYYY-MM-DD)."),
|
|
781
|
+
end_date: z
|
|
782
|
+
.string()
|
|
783
|
+
.regex(/^\d{4}-\d{2}-\d{2}$/, "Use YYYY-MM-DD")
|
|
784
|
+
.optional()
|
|
785
|
+
.describe("Only pages published on or before this date (YYYY-MM-DD)."),
|
|
786
|
+
highlights: z
|
|
787
|
+
.boolean()
|
|
788
|
+
.optional()
|
|
789
|
+
.describe("Include the passage that best matches the query (API default true)."),
|
|
790
|
+
page_text: z.boolean().optional().describe("Include each page's full text (API default false)."),
|
|
791
|
+
}, async ({ query, mode, count, start_date, end_date, highlights, page_text }) => {
|
|
792
|
+
try {
|
|
793
|
+
const body = { query, ...definedFields({ mode, count, start_date, end_date, highlights, page_text }) };
|
|
794
|
+
return ok((await api("POST", "/search", { body })).data);
|
|
795
|
+
}
|
|
796
|
+
catch (error) {
|
|
797
|
+
return fail("Search API error", error);
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
registerTool(server, apiKey, "tiktok", "TikTok", "Read public TikTok data with Desearch. Set action and that action's arguments. search (query; optional count, sort, cursor): videos that match a keyword. post (id): one video by its ID. profile (username): one profile. profile_posts (username; optional count, cursor): a user's videos. comments (video_id; optional count, cursor): a video's comments. hashtag (tag; optional count, cursor): videos with a hashtag. trending (optional region, count): trending videos for a region, one page. A video id from search can be passed to post or comments. post and profile return the item itself. " +
|
|
801
|
+
SOCIAL_PAGING, strictArgs({
|
|
802
|
+
action: socialAction("tiktok", "What to read: 'search', 'post', 'profile', 'profile_posts', 'comments', 'hashtag', or 'trending'."),
|
|
803
|
+
query: socialQuery("bittensor"),
|
|
804
|
+
sort: socialTarget("search: sort option, when TikTok supports one."),
|
|
805
|
+
id: socialTarget("post: the TikTok video ID, example: '7620891413932166433'."),
|
|
806
|
+
username: socialTarget("profile, profile_posts: TikTok username, example: 'tiktok'. A leading @ is removed."),
|
|
807
|
+
video_id: socialTarget("comments: the TikTok video ID."),
|
|
808
|
+
tag: socialTag(),
|
|
809
|
+
region: z
|
|
810
|
+
.string()
|
|
811
|
+
.length(2)
|
|
812
|
+
.optional()
|
|
813
|
+
.describe("trending: two-letter region code, example: 'US' (API default)."),
|
|
814
|
+
count: socialCount(),
|
|
815
|
+
cursor: socialCursor(),
|
|
816
|
+
}), async (args) => {
|
|
817
|
+
try {
|
|
818
|
+
return ok(await runSocialAction(api, "tiktok", args));
|
|
819
|
+
}
|
|
820
|
+
catch (error) {
|
|
821
|
+
return fail("TikTok error", error);
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
registerTool(server, apiKey, "facebook", "Facebook", "Read public Facebook data with Desearch. Set action and that action's arguments. search (query; optional count, cursor) and hashtag (tag; optional count, cursor) return Meta Ad Library ads that match, not organic posts. post (id): one public post. profile (profile_id): a page or profile by ID or public handle. profile_posts (profile_id; optional count, cursor): its posts. comments (post_id; optional count, cursor): a post's comments, about 10 per page. post and profile return the item itself. " +
|
|
825
|
+
SOCIAL_PAGING, strictArgs({
|
|
826
|
+
action: socialAction("facebook", "What to read: 'search', 'post', 'profile', 'profile_posts', 'comments', or 'hashtag'."),
|
|
827
|
+
query: socialQuery("running shoes"),
|
|
828
|
+
id: socialTarget("post: the public Facebook post or media ID."),
|
|
829
|
+
profile_id: socialTarget("profile, profile_posts: page or profile ID, or its public handle, example: 'facebook'."),
|
|
830
|
+
post_id: socialTarget("comments: the public Facebook post or media ID."),
|
|
831
|
+
tag: socialTag(),
|
|
832
|
+
count: socialCount(),
|
|
833
|
+
cursor: socialCursor(),
|
|
834
|
+
}), async (args) => {
|
|
835
|
+
try {
|
|
836
|
+
return ok(await runSocialAction(api, "facebook", args));
|
|
837
|
+
}
|
|
838
|
+
catch (error) {
|
|
839
|
+
return fail("Facebook error", error);
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
registerTool(server, apiKey, "instagram", "Instagram", "Read public Instagram data with Desearch. Set action and that action's arguments. search (query; optional count): profiles that match, one page with no cursor. media (id): one post by shortcode, numeric ID, or URL. profile (username): one profile. profile_posts (username; optional count, cursor): a user's posts. comments (shortcode; optional count, cursor): a post's comments. hashtag (tag; optional count, cursor): posts with a hashtag. media and profile return the item itself. " +
|
|
843
|
+
SOCIAL_PAGING, strictArgs({
|
|
844
|
+
action: socialAction("instagram", "What to read: 'search', 'media', 'profile', 'profile_posts', 'comments', or 'hashtag'."),
|
|
845
|
+
query: socialQuery("desearch"),
|
|
846
|
+
id: socialTarget("media: the post shortcode, numeric media ID, or public URL."),
|
|
847
|
+
username: socialTarget("profile, profile_posts: Instagram username, example: 'instagram'. A leading @ is removed."),
|
|
848
|
+
shortcode: socialTarget("comments: the code in the post URL, such as 'DeuOR-CjKE9' in https://www.instagram.com/p/DeuOR-CjKE9/. Numeric media IDs return 404."),
|
|
849
|
+
tag: socialTag(),
|
|
850
|
+
count: socialCount(),
|
|
851
|
+
cursor: socialCursor(),
|
|
852
|
+
}), async (args) => {
|
|
853
|
+
try {
|
|
854
|
+
return ok(await runSocialAction(api, "instagram", args));
|
|
855
|
+
}
|
|
856
|
+
catch (error) {
|
|
857
|
+
return fail("Instagram error", error);
|
|
858
|
+
}
|
|
859
|
+
});
|
|
719
860
|
registerTool(server, apiKey, "search", "Search", "Search the public web and return titles and links. Use fetch with a result URL to read the page.", {
|
|
720
861
|
query: z.string().describe("Search query."),
|
|
721
862
|
}, async ({ query }) => {
|
|
@@ -988,6 +1129,58 @@ export function createDesearchMcpServer(apiKey, client, peopleClient, companyCli
|
|
|
988
1129
|
return fail("People Profiles error", error);
|
|
989
1130
|
}
|
|
990
1131
|
}, undefined, READ_ONLY_OPEN_WORLD);
|
|
1132
|
+
registerTool(server, apiKey, "people-search-export", "Export People Found", `The people your own People Searches found, as CSV or JSON Lines text: one search (task_id), or everyone found on one platform (platform, with the same q, sort, and filters as people-profiles). Free: it reads people your earlier searches found and runs no new search. The reply is a note with the row count, then the file text cut at a row boundary to max_rows rows and ${PEOPLE_EXPORT_MAX_CHARS.toLocaleString("en-US")} characters; the note says how many rows were cut and where to get the whole file. CSV keeps its header row. The data came from public profiles and posts, with only the contacts each person lists publicly.`, strictArgs({
|
|
1133
|
+
task_id: z
|
|
1134
|
+
.string()
|
|
1135
|
+
.uuid()
|
|
1136
|
+
.optional()
|
|
1137
|
+
.describe("Export one search: the task_id returned by people-search. Omit it and set platform to export everyone your searches found on that platform."),
|
|
1138
|
+
platform: z
|
|
1139
|
+
.enum(PEOPLE_PLATFORMS)
|
|
1140
|
+
.optional()
|
|
1141
|
+
.describe("Without task_id: export everyone found on 'x', 'youtube', 'linkedin', or 'tiktok'."),
|
|
1142
|
+
format: z
|
|
1143
|
+
.enum(PEOPLE_EXPORT_FORMATS)
|
|
1144
|
+
.default("csv")
|
|
1145
|
+
.describe("'csv' (default) or 'jsonl' (one JSON object per line)."),
|
|
1146
|
+
q: z
|
|
1147
|
+
.string()
|
|
1148
|
+
.max(200)
|
|
1149
|
+
.optional()
|
|
1150
|
+
.describe("Platform export only: text in the name, handle, bio, or location."),
|
|
1151
|
+
sort: z
|
|
1152
|
+
.enum(PEOPLE_PROFILE_SORTS)
|
|
1153
|
+
.optional()
|
|
1154
|
+
.describe("Platform export only: 'score' (API default), 'recent', or 'audience'."),
|
|
1155
|
+
has: z
|
|
1156
|
+
.array(z.enum(PEOPLE_FILTER_CHANNELS))
|
|
1157
|
+
.optional()
|
|
1158
|
+
.describe("Channels every person must have, example: ['email']. 'email' is a public email; the others are a link of that type."),
|
|
1159
|
+
min_audience: z.number().int().min(0).optional().describe("Minimum followers (subscribers on YouTube)."),
|
|
1160
|
+
max_audience: z.number().int().min(0).optional().describe("Maximum followers (subscribers on YouTube)."),
|
|
1161
|
+
min_score: z.number().int().min(0).max(100).optional().describe("Minimum fit score (0-100)."),
|
|
1162
|
+
location: z.string().max(100).optional().describe("Text in the location, example: 'united states'."),
|
|
1163
|
+
verified: z.boolean().optional().describe("Only verified accounts. Only X and TikTok people carry a verified flag."),
|
|
1164
|
+
max_rows: z
|
|
1165
|
+
.number()
|
|
1166
|
+
.int()
|
|
1167
|
+
.min(1)
|
|
1168
|
+
.max(PEOPLE_EXPORT_MAX_ROWS)
|
|
1169
|
+
.default(PEOPLE_EXPORT_DEFAULT_ROWS)
|
|
1170
|
+
.describe(`Most rows to return (1-${PEOPLE_EXPORT_MAX_ROWS}, default ${PEOPLE_EXPORT_DEFAULT_ROWS}). The reply also stops before ${PEOPLE_EXPORT_MAX_CHARS.toLocaleString("en-US")} characters of file text.`),
|
|
1171
|
+
}), async (args) => {
|
|
1172
|
+
try {
|
|
1173
|
+
const exported = await exportPeople(people, args);
|
|
1174
|
+
const content = [{ type: "text", text: exported.note }];
|
|
1175
|
+
if (exported.text) {
|
|
1176
|
+
content.push({ type: "text", text: exported.text });
|
|
1177
|
+
}
|
|
1178
|
+
return { content };
|
|
1179
|
+
}
|
|
1180
|
+
catch (error) {
|
|
1181
|
+
return fail("People Search Export error", error);
|
|
1182
|
+
}
|
|
1183
|
+
}, undefined, READ_ONLY_OPEN_WORLD);
|
|
991
1184
|
registerTool(server, apiKey, "company-search", "Company Search", "Start a paid job billed to the user's Desearch balance: find companies on the web that match a plain-language description, and collect each one's public contact data. Returns a task_id at once, with the task's status and reserved_cost_usd. " +
|
|
992
1185
|
"Cost: the call reserves count companies at the Company Search per-company price at the time of the call (reserved_cost_usd; prices at https://desearch.ai/pricing). When the task ends you pay only for the companies it delivered (final_cost_usd; a minimum of 2 when it delivers any; a task that delivers none is free) and the rest of the reservation is returned. A company left out by min_score or require is not billed. " +
|
|
993
1186
|
"Each company has a fit score (0-100) and why it matched, plus fully_verified and unverified_criteria (what its own pages do and do not confirm). " +
|