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.
package/build/server.js CHANGED
@@ -2,10 +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 { 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, createPeopleClient, listPeopleProfiles, listPeopleTasks, readPeopleStatus, startPeopleSearch, } from "./people.js";
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";
6
9
  import { AI_SEARCH_TOOLS, WEB_LINK_TOOLS, toolIdSchema } from "./tool-sources.js";
7
10
  export const SERVER_NAME = "Desearch";
8
- export const SERVER_VERSION = "0.5.0";
11
+ export const SERVER_VERSION = "0.7.0";
9
12
  export const SERVER_TITLE = "Desearch";
10
13
  export const SERVER_WEBSITE_URL = "https://www.desearch.ai";
11
14
  // Public origin of the hosted server, which serves the icons below.
@@ -29,11 +32,11 @@ const READ_ONLY_OPEN_WORLD = {
29
32
  openWorldHint: true,
30
33
  };
31
34
  /**
32
- * `people-search` starts a paid job billed to the user's Desearch balance.
33
- * It creates a new task and reserves balance, but it does not delete or overwrite
34
- * anything the caller already has, so destructiveHint is false. The unused part
35
- * of the reservation is returned when the search ends.
36
- * Calling it again starts (and reserves) another search unless the same idempotency_key is sent.
35
+ * `people-search`, `company-search`, and `company-enrich` start a paid job billed to the
36
+ * user's Desearch balance. Each creates a new task and reserves balance, but it does not
37
+ * delete or overwrite anything the caller already has, so destructiveHint is false. The
38
+ * unused part of the reservation is returned when the task ends.
39
+ * Calling it again starts (and reserves) another task unless the same idempotency_key is sent.
37
40
  */
38
41
  const BILLED_TASK = {
39
42
  readOnlyHint: false,
@@ -51,6 +54,8 @@ const BILLED_TASK = {
51
54
  * search cannot be resumed. Pause is reversible only within those 7 days; the
52
55
  * cancel itself bills only the people already delivered and returns the rest.
53
56
  * Repeating the same call has no further effect (the API answers 409).
57
+ * `company-search-pause` and `company-search-resume` work the same way on Company
58
+ * Search and Company Enrich tasks, with companies in place of people.
54
59
  */
55
60
  const TASK_STATE_CHANGE = {
56
61
  readOnlyHint: false,
@@ -59,8 +64,8 @@ const TASK_STATE_CHANGE = {
59
64
  openWorldHint: true,
60
65
  };
61
66
  /**
62
- * `people-search-cancel` stops a task for good. It cannot be undone, so destructiveHint is true.
63
- * Repeating it has no further effect (the API answers 409).
67
+ * `people-search-cancel` and `company-search-cancel` stop a task for good. It cannot be
68
+ * undone, so destructiveHint is true. Repeating it has no further effect (the API answers 409).
64
69
  */
65
70
  const TASK_CANCEL = {
66
71
  readOnlyHint: false,
@@ -115,6 +120,43 @@ const peoplePlatform = z
115
120
  function strictArgs(shape) {
116
121
  return z.object(shape).strict();
117
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.";
118
160
  // A new schema per field: one shared instance would serialize as a JSON Schema $ref.
119
161
  function peopleKeywordList() {
120
162
  return z.array(z.string().min(1).max(120)).max(20);
@@ -144,6 +186,39 @@ function peopleMetadata(maxKeys) {
144
186
  }
145
187
  });
146
188
  }
189
+ const companyTaskId = z
190
+ .string()
191
+ .uuid()
192
+ .describe("task_id returned by company-search or company-enrich, example: '5b33f3ee-168b-4780-9c8e-63a626781872'. A People Search task_id is not found here.");
193
+ // Fields company-search and company-enrich share. A new schema per field, like peopleKeywordList.
194
+ function companyTaskFields() {
195
+ return {
196
+ roles: z
197
+ .array(z.enum(COMPANY_ROLES))
198
+ .min(1)
199
+ .optional()
200
+ .describe("The leaders to look for: any of 'ceo', 'founder', 'cto', 'cfo', 'coo', 'cmo', 'president', 'owner', 'managing_director' (API default ['ceo', 'founder', 'cto', 'cfo']). A managing director (Geschäftsführer) counts as 'ceo' when 'ceo' is asked for."),
201
+ infer_emails: z
202
+ .boolean()
203
+ .optional()
204
+ .describe("Guess leaders' emails from the company's address pattern (for example first.last), learned from the addresses found on its site (API default true). Inferred emails say source: inferred and carry a confidence: high when the pattern was learned from this company's own addresses, low for a common pattern."),
205
+ verify_emails: z
206
+ .boolean()
207
+ .optional()
208
+ .describe("Check every email: syntax, mail server (MX) and, for inferred ones, a web search (API default true). Each email then has a verification: valid, invalid, risky, or unknown. Set false to finish sooner without it."),
209
+ idempotency_key: z
210
+ .string()
211
+ .min(1)
212
+ .max(200)
213
+ .optional()
214
+ .describe("Any unique string for this task, for example a UUID. Sending the same key again returns the first task and is not charged again."),
215
+ metadata: peopleMetadata(PEOPLE_METADATA_MAX_KEYS)
216
+ .optional()
217
+ .describe(`Your own labels for this task, example: {"campaign": "q4-outbound"}. Up to ${PEOPLE_METADATA_MAX_KEYS} keys; keys are 1-40 characters of a-z, 0-9, '_', '.', '-'; values are strings of up to ${PEOPLE_METADATA_VALUE_MAX} characters. Returned on the task; filter company-search-tasks by it. The task does not use it.`),
218
+ };
219
+ }
220
+ const COMPANY_DATA = "Data: Desearch reads public data only: each company's own website (its homepage and its contact, about, team, and imprint pages), public web search results, and public LinkedIn profiles of its leaders. Each company comes back with its location, public emails, phones, and social profiles, and its leaders (roles) with their title, LinkedIn profile, and emails. Every contact keeps the page it came from (source_url). Leader emails can be inferred from the company's address pattern (source: inferred, with a confidence), and every email is checked (verification: valid, invalid, risky, or unknown). Companies stay readable for 30 days after the task ends. ";
221
+ const COMPANY_RUNS = "The task runs in the background: poll company-search-status with the task_id to read progress and the companies delivered so far. Each company is delivered first with enrichment status partial, and the later stages (contact pages, leaders, inferred emails, email checks) fill it in until it is complete. Use company-search-pause, company-search-resume, or company-search-cancel to pause, resume, or cancel it. Do not start the same task twice; send idempotency_key so a retry returns the first task instead of charging again.";
147
222
  function platformFilterList() {
148
223
  return Object.entries(PEOPLE_SEARCH_FILTERS)
149
224
  .map(([platform, filters]) => `${platform}: ${filters.join(", ")}`)
@@ -373,12 +448,18 @@ function registerTool(server, apiKey, name, title, description, inputSchema, han
373
448
  * One MCP server bound to a single Desearch API key.
374
449
  * Stdio uses the process env key. Remote HTTP builds a new server per request
375
450
  * so each caller spends their own key.
376
- * `client` and `peopleClient` are test seams. Production callers omit them and the
377
- * server builds a desearch-js client and a People Search client (people.ts) from `apiKey`.
451
+ * `client`, `peopleClient`, and `companyClient` are test seams. Production callers omit
452
+ * them and the server builds a desearch-js client, a People Search client (people.ts), and
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.
378
457
  */
379
- export function createDesearchMcpServer(apiKey, client, peopleClient) {
458
+ export function createDesearchMcpServer(apiKey, client, peopleClient, companyClient) {
380
459
  const desearch = client ?? new Desearch(apiKey);
381
- const people = peopleClient ?? createPeopleClient(apiKey);
460
+ const api = createDesearchApi(apiKey);
461
+ const people = peopleClient ?? peopleClientFor(api);
462
+ const companies = companyClient ?? companyClientFor(api);
382
463
  const serverInfo = {
383
464
  name: SERVER_NAME,
384
465
  version: SERVER_VERSION,
@@ -387,7 +468,7 @@ export function createDesearchMcpServer(apiKey, client, peopleClient) {
387
468
  icons: SERVER_ICONS,
388
469
  };
389
470
  const server = new McpServer(serverInfo, {
390
- 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, and people-search-pause, people-search-resume, and people-search-cancel pause, resume, or cancel it. Calls need a Desearch API key.",
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.",
391
472
  });
392
473
  registerTool(server, apiKey, "ai-search", "AI Search", "AI search and analysis on web using Desearch AI", {
393
474
  prompt: z.string().describe("Question, example: 'What is the latest news on AI?'"),
@@ -678,6 +759,104 @@ export function createDesearchMcpServer(apiKey, client, peopleClient) {
678
759
  return fail("X Trends error", error);
679
760
  }
680
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
+ });
681
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.", {
682
861
  query: z.string().describe("Search query."),
683
862
  }, async ({ query }) => {
@@ -950,6 +1129,213 @@ export function createDesearchMcpServer(apiKey, client, peopleClient) {
950
1129
  return fail("People Profiles error", error);
951
1130
  }
952
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);
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. " +
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. " +
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). " +
1187
+ COMPANY_DATA +
1188
+ COMPANY_RUNS +
1189
+ " To read companies you already know by domain, use company-enrich instead.", strictArgs({
1190
+ query: z
1191
+ .string()
1192
+ .min(3)
1193
+ .max(1000)
1194
+ .describe("The companies you are looking for, in plain language: what they do, where, how far along. Example: 'Series A fintech startups in Berlin building payment infrastructure'."),
1195
+ count: z
1196
+ .number()
1197
+ .int()
1198
+ .min(5)
1199
+ .max(200)
1200
+ .optional()
1201
+ .describe("How many companies to deliver (5-200, API default 25). The task reserves this many and bills only the companies it delivers."),
1202
+ min_score: z
1203
+ .number()
1204
+ .int()
1205
+ .min(0)
1206
+ .max(100)
1207
+ .optional()
1208
+ .describe("Only deliver companies with at least this fit score (0-100)."),
1209
+ exclude: z
1210
+ .array(z.string().min(1))
1211
+ .max(COMPANY_EXCLUDE_MAX)
1212
+ .optional()
1213
+ .describe(`Companies to leave out, as domains or URLs, for example ones you already contacted (up to ${COMPANY_EXCLUDE_MAX}). Each is reduced to its host without www.`),
1214
+ countries: z
1215
+ .array(z.string().min(1).max(120))
1216
+ .max(COMPANY_COUNTRIES_MAX)
1217
+ .optional()
1218
+ .describe(`Where the companies should be: ISO 3166-1 alpha-2 codes or country names, example: ['DE', 'Austria'] (up to ${COMPANY_COUNTRIES_MAX}). Scoring treats them as a location criterion. Sent as filters.countries.`),
1219
+ require: z
1220
+ .array(z.enum(COMPANY_REQUIREMENTS))
1221
+ .optional()
1222
+ .describe("Only deliver companies that have all of these: 'email', 'phone', 'linkedin' (the company's LinkedIn page), 'leader' (one of roles), 'leader_email' (a leader with an email). A company is delivered once the stage that can show them has run (email, phone, linkedin: the contact pages; leader: the leaders; leader_email: the email checks); one that does not have them is not delivered and not billed. Sent as filters.require."),
1223
+ ...companyTaskFields(),
1224
+ }), async (args) => {
1225
+ try {
1226
+ return ok(await startCompanySearch(companies, args));
1227
+ }
1228
+ catch (error) {
1229
+ return fail("Company Search error", error);
1230
+ }
1231
+ }, undefined, BILLED_TASK);
1232
+ registerTool(server, apiKey, "company-enrich", "Company Enrich", "Start a paid job billed to the user's Desearch balance: collect public contact data for companies you already know, by domain. Send 1-200 domains or URLs; each is reduced to its host without www., lowercased, and deduplicated, and the task reads every one. Returns a task_id at once, with the task's status and reserved_cost_usd. You get one company per domain with the same fields as company-search but no fit score (score is null). The task's count is the number of domains left after deduplication. " +
1233
+ "Cost: the call reserves one company per domain sent at the Company Enrich 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 1; a task that delivers none is free) and the rest of the reservation, including duplicate domains, is returned. " +
1234
+ COMPANY_DATA +
1235
+ COMPANY_RUNS +
1236
+ " To find companies from a description, use company-search instead.", strictArgs({
1237
+ domains: z
1238
+ .array(z.string().min(1))
1239
+ .min(1)
1240
+ .max(COMPANY_DOMAINS_MAX)
1241
+ .describe(`1-${COMPANY_DOMAINS_MAX} company domains or URLs, example: ['acme.com', 'https://www.beta.io/about']. Each is reduced to its host without www. and lowercased; duplicates are removed.`),
1242
+ ...companyTaskFields(),
1243
+ }), async (args) => {
1244
+ try {
1245
+ return ok(await startCompanyEnrich(companies, args));
1246
+ }
1247
+ catch (error) {
1248
+ return fail("Company Enrich error", error);
1249
+ }
1250
+ }, undefined, BILLED_TASK);
1251
+ registerTool(server, apiKey, "company-search-status", "Get Company Search Status", "Status, progress, and cost of one Company Search or Company Enrich task, plus a page of the companies delivered so far: domain, name, url, location, fit score (null for Company Enrich) and why it matched, primary_email and primary_contact, public emails, phones, and social profiles with the page each came from (source_url), leaders with their roles, title, LinkedIn profile, and emails (each with its verification status; inferred ones with source: inferred and a confidence), contact_coverage, and enrichment (status partial or complete, and each stage: profile, contacts, people, email_patterns, email_check). Free: it reads a task you already started and runs no new search. Cost fields are reserved_cost_usd and, once the task ended, final_cost_usd. The data came from each company's own website, public web search, and public LinkedIn profiles. " +
1252
+ "Companies arrive while the task runs and are filled in place by the later stages: pass the returned next_cursor as cursor to get only the companies delivered since then, and call without cursor to read every company in its latest version. stage enriching means every company is delivered and only later stages of some are left. When done is true and has_more is false you have every company. An ended task has completion_reason (why it stopped; all_domains_processed for Company Enrich), coverage_limited: true when a budget stopped it before count (more companies may match), and warnings. Company Search results have fully_verified (every criterion confirmed by the company's own pages) and unverified_criteria (criteria that are unknown or not met, or a disqualifier that applies). These are information only: the company still qualified.", strictArgs({
1253
+ task_id: companyTaskId,
1254
+ cursor: z
1255
+ .string()
1256
+ .max(64)
1257
+ .optional()
1258
+ .describe("next_cursor from the previous company-search-status call, to get only the companies delivered since then. Omit to read from the first company, each in its latest version."),
1259
+ limit: z
1260
+ .number()
1261
+ .int()
1262
+ .min(1)
1263
+ .max(100)
1264
+ .default(10)
1265
+ .describe("Companies per page (1-100, default 10)."),
1266
+ include_companies: z
1267
+ .boolean()
1268
+ .default(true)
1269
+ .describe("Set false to read only the status, progress, and cost."),
1270
+ }), async (args) => {
1271
+ try {
1272
+ return ok(await readCompanyStatus(companies, args));
1273
+ }
1274
+ catch (error) {
1275
+ return fail("Company Search Status error", error);
1276
+ }
1277
+ }, undefined, READ_ONLY_OPEN_WORLD);
1278
+ registerTool(server, apiKey, "company-search-pause", "Pause Company Search", "Pause a Company Search or Company Enrich task and return its updated status. Free: it charges and refunds nothing. A queued task pauses at once; a running one finishes its current batch first (status pausing, then paused). Pausing loses no data: the companies delivered so far stay readable with company-search-status, and the task keeps its progress. Billing does not change: the reservation made when the task started stays reserved while paused and is settled only when the task ends. Undo it with company-search-resume, which continues from where the task stopped with no new charge. Limit: a task paused for more than 7 days is cancelled by the API and can no longer be resumed; you then pay only for the companies already delivered, the rest of the reservation is returned, and the companies delivered stay readable for 30 days.", strictArgs({
1279
+ task_id: companyTaskId,
1280
+ }), async (args) => {
1281
+ try {
1282
+ return ok(await controlCompanyTask(companies, { task_id: args.task_id, action: "pause" }));
1283
+ }
1284
+ catch (error) {
1285
+ return fail("Company Search Pause error", error);
1286
+ }
1287
+ }, undefined, TASK_STATE_CHANGE);
1288
+ registerTool(server, apiKey, "company-search-resume", "Resume Company Search", "Resume a paused Company Search or Company Enrich task and return its updated status. Free. The task continues from where it stopped, keeping the companies already delivered, with no new charge. Works only on a paused task, within 7 days of pausing; a task in any other state, including one the API cancelled after 7 days paused, returns 409. Poll company-search-status for the new companies.", strictArgs({
1289
+ task_id: companyTaskId,
1290
+ }), async (args) => {
1291
+ try {
1292
+ return ok(await controlCompanyTask(companies, { task_id: args.task_id, action: "resume" }));
1293
+ }
1294
+ catch (error) {
1295
+ return fail("Company Search Resume error", error);
1296
+ }
1297
+ }, undefined, TASK_STATE_CHANGE);
1298
+ registerTool(server, apiKey, "company-search-cancel", "Cancel Company Search", "Cancel a Company Search or Company Enrich task. Free. The task stops for good; you pay only for the companies it already delivered (a task cancelled before it starts costs nothing) and the rest of the reservation is returned. Companies delivered so far stay readable for 30 days. This cannot be undone.", strictArgs({
1299
+ task_id: companyTaskId,
1300
+ }), async (args) => {
1301
+ try {
1302
+ return ok(await controlCompanyTask(companies, { task_id: args.task_id, action: "cancel" }));
1303
+ }
1304
+ catch (error) {
1305
+ return fail("Company Search Cancel error", error);
1306
+ }
1307
+ }, undefined, TASK_CANCEL);
1308
+ registerTool(server, apiKey, "company-search-tasks", "List Company Search Tasks", "Your Company Search and Company Enrich tasks, newest first, with status, counts, cost, why each ended task stopped (completion_reason, coverage_limited), and the metadata labels set on company-search or company-enrich. Free; it lists your own tasks, not the companies they found (read those with company-search-status). People Search tasks are not listed here (see people-search-tasks). Use it to find a task_id (filter by type, status, or metadata to find the tasks of one campaign), or to see which tasks are still queued, running, or paused: a new task is refused while too many People Search and Company Search tasks are active.", strictArgs({
1309
+ type: z
1310
+ .enum(COMPANY_TASK_TYPES)
1311
+ .optional()
1312
+ .describe("Only Company Search ('search') or only Company Enrich ('enrich') tasks."),
1313
+ status: z
1314
+ .array(z.enum(COMPANY_TASK_STATUSES))
1315
+ .optional()
1316
+ .describe("Only tasks in these statuses, example: ['running', 'paused']."),
1317
+ limit: z
1318
+ .number()
1319
+ .int()
1320
+ .min(1)
1321
+ .max(100)
1322
+ .optional()
1323
+ .describe("Tasks per page (1-100, API default 20)."),
1324
+ cursor: z
1325
+ .string()
1326
+ .optional()
1327
+ .describe("next_cursor from the previous page. Keep the same type, status, and metadata filters when you page."),
1328
+ metadata: peopleMetadata(PEOPLE_METADATA_MAX_FILTERS)
1329
+ .optional()
1330
+ .describe(`Only tasks whose metadata has all of these key/value pairs (exact match, up to ${PEOPLE_METADATA_MAX_FILTERS}), example: {"campaign": "q4-outbound"}.`),
1331
+ }), async (args) => {
1332
+ try {
1333
+ return ok(await listCompanyTasks(companies, args));
1334
+ }
1335
+ catch (error) {
1336
+ return fail("Company Search Tasks error", error);
1337
+ }
1338
+ }, undefined, READ_ONLY_OPEN_WORLD);
953
1339
  // Scanners ask for these lists during discovery. There is nothing to return,
954
1340
  // but an empty list is a successful response. Method-not-found looks like a
955
1341
  // broken server to some directory crawlers.