desearch-mcp-server 0.9.0 → 0.11.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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.11.0
4
+
5
+ `search-api` returns an optional summary. Tool names are unchanged (39 tools).
6
+
7
+ - `search-api` takes `summary` (a short answer written from the results, with numbered citations; no extra charge), `include_domains` (at most 100), and `exclude_domains` (at most 1,200). The result lists `summary` first (`{ text, citations: [{ index, url, title }] }`, or `null` with `meta.notices` `Summary unavailable.`), then `results`, `meta`, and the billing fields.
8
+ - `search-api` is web search on the Desearch index; the server instructions point web questions to it.
9
+ - `ai-search` covers X posts and web (from the Desearch index) with an optional AI summary. Web results are capped at 20 per request.
10
+ - `web-links-search` is deprecated in favor of `search-api`. It keeps calling `POST /desearch/ai/search/links/web`.
11
+ - Every version (package, `server.json`, the Gemini extension, the plugin manifests, and `SERVER_VERSION`) is 0.11.0.
12
+
13
+ ## 0.10.0
14
+
15
+ Cost on every tool result, as the hosted server has had since 06a3ec0.
16
+
17
+ - Every tool result from a billed Desearch API call carries `_meta.cost_usd` and `_meta.usage_count`, read from the API's `X-Desearch-Cost-Usd` and `X-Desearch-Usage-Count` headers, for every result shape: JSON objects, bare lists (`x-search`, `x-posts-by-user`, the other X tools) and text (`extract`, `web-crawl`). Before, only tools whose API body already held cost fields showed a cost. The desearch-js tools ask the SDK for the response metadata (`includeMetadata`); the direct API tools (People Search, Company Search, the social routes, `search-api`) read the headers. Content and `structuredContent` are unchanged. A tool call that makes several billed requests reports the sum; concurrent calls on one server stay apart. A free call reports `cost_usd: 0`; failed calls carry no cost.
18
+ - Every version (package, `server.json`, the Gemini extension, the plugin manifests, and `SERVER_VERSION`) is 0.10.0. The tool count is unchanged (39).
19
+
3
20
  ## 0.9.0
4
21
 
5
22
  Company Search: a search budget (`max_cost_usd`) and continuing an ended search (`continue_from`), the two optional `POST /desearch/companies/search` fields of desearch-public-api #624. Both wait for that API release; until then the API answers 422 to them.
package/README.md CHANGED
@@ -52,7 +52,7 @@ Example output:
52
52
 
53
53
  The tool returns that JSON as pretty-printed text: `{ "content": [{ "type": "text", "text": "<json above>" }] }`.
54
54
 
55
- AI search, X search and web search for AI agents, plus the Search API (ranked pages with the best-matching passage), page extraction, X data tools, public TikTok, Facebook, Instagram, YouTube (videos, transcripts, comments, channels), Reddit, and Threads data, People Search (find people and creators on X, YouTube, LinkedIn, and TikTok), and Company Search (find companies on the web, or enrich domains you have, with their public contacts and leaders). Bring your own Desearch API key. Version 0.9.0 exposes 39 tools.
55
+ AI search, X search and web search for AI agents, plus the Search API (ranked pages with the best-matching passage), page extraction, X data tools, public TikTok, Facebook, Instagram, YouTube (videos, transcripts, comments, channels), Reddit, and Threads data, People Search (find people and creators on X, YouTube, LinkedIn, and TikTok), and Company Search (find companies on the web, or enrich domains you have, with their public contacts and leaders). Bring your own Desearch API key. Version 0.11.0 exposes 39 tools.
56
56
 
57
57
  ## Tools
58
58
 
@@ -60,13 +60,13 @@ The Desearch MCP server includes the following tools.
60
60
 
61
61
  Lookup tools, including `search` and `fetch`, set `readOnlyHint: true`, `destructiveHint: false`, and `openWorldHint: true`. `search-api`, `tiktok`, `facebook`, `instagram`, `youtube`, `reddit`, `threads`, `people-search-status`, `people-search-tasks`, `people-profiles`, and `people-search-export` are lookups too. `people-search` starts a paid job billed to the user's Desearch balance, so `readOnlyHint` is false; it creates a new task and does not delete or overwrite anything, so `destructiveHint` is false. `people-search-pause` and `people-search-resume` change a task's state and undo each other, so `readOnlyHint` and `destructiveHint` are false and `idempotentHint` is true. Pausing loses no data (people found so far stay readable and the search keeps its progress) and changes no billing (nothing is charged or refunded; the reservation stays until the search ends), and resume continues from where the search stopped with no new charge. The caveat: the API cancels a search paused for more than 7 days, and a cancelled search cannot be resumed, so a pause is reversible only within those 7 days. `people-search-cancel` cannot be undone, so `readOnlyHint` is false and `destructiveHint` and `idempotentHint` are true. The Company Search tools follow the same rules: `company-search` and `company-enrich` start paid jobs (`readOnlyHint: false`, `destructiveHint: false`, `idempotentHint: false`), `company-search-status` and `company-search-tasks` are lookups, `company-search-pause` and `company-search-resume` set `destructiveHint: false` and `idempotentHint: true` (with the same 7-day caveat), and `company-search-cancel` sets `destructiveHint: true` and `idempotentHint: true`. `openWorldHint` is true on every tool because the call reaches a live external source.
62
62
 
63
- - **AI Search** (`ai-search`): Performs AI Twitter and web searches with relevant links and summary. `tools` uses short source ids (`web`, `twitter`, `arxiv`, `wikipedia`, `hackernews`, `reddit`). Older labels such as `Web Search`, `ArXiv Search`, `Wikipedia Search`, `Hacker News Search`, and `Reddit Search` are still accepted and sent as the short id. `youtube` is not accepted. Default is `["web", "twitter"]`.
63
+ - **AI Search** (`ai-search`): X (Twitter) posts and web (from the Desearch index) with relevant links and an optional AI summary. Web results are capped at 20 per request; for web only, use `search-api`. `tools` uses short source ids (`web`, `twitter`, `arxiv`, `wikipedia`, `hackernews`, `reddit`). Older labels such as `Web Search`, `ArXiv Search`, `Wikipedia Search`, `Hacker News Search`, and `Reddit Search` are still accepted and sent as the short id. `youtube` is not accepted. Default is `["web", "twitter"]`.
64
64
  - **X Search** (`x-search`): Tweet search on X. Arguments: `query` (required), `count` (optional, default 20). Sort stays Top. Optional filters: `user`, `start_date`, `end_date` (YYYY-MM-DD), `lang`, `verified`, `blue_verified`, `is_quote`, `is_video`, `is_image`, `min_retweets`, `min_replies`, `min_likes`.
65
65
  - **Search** (`search`): Web search that returns `{ results: [{ id, title, url }] }`. Argument: `query` (required). `id` is the result URL.
66
66
  - **Fetch Page** (`fetch`): Read a public page as text. Argument: `id` (required, an `http` or `https` URL from `search`).
67
67
  - **Web Search** (`web-search`): SERP-style web search. Arguments: `query` (required), `start` (optional pagination offset).
68
- - **Search API** (`search-api`): Ranked web pages, each with its title, URL, publication date when known, and the passage that best matches the query (`POST /search`). Arguments: `query` (required, 1–2000 characters), `mode` (optional, `fast` or `balanced`, API default `balanced`), `count` (optional, 10, 15, or 20), `start_date` and `end_date` (optional, YYYY-MM-DD), `highlights` (optional, default `true`), `page_text` (optional, default `false`; adds each page's full text). Returns `results` plus `cost_usd`, `usage_count`, `service`, and `currency`.
69
- - **Web Links Search** (`web-links-search`): Web link search. Arguments: `prompt` (required), `tools` (optional, only `web`, default `["web"]`; `Web Search` is accepted and rewritten to `web`), `count` (optional, 10–200). The links/web API rejects other sources, so they are not in the enum.
68
+ - **Search API** (`search-api`): Web search on the Desearch index (`POST /search`): ranked pages, each with its title, URL, publication date when known, and the passage that best matches the query, plus an optional short answer with numbered citations. Arguments: `query` (required, 1–2000 characters), `mode` (optional, `fast` or `balanced`, API default `balanced`), `count` (optional, 10, 15, or 20), `start_date` and `end_date` (optional, YYYY-MM-DD), `highlights` (optional, default `true`), `page_text` (optional, default `false`; adds each page's full text), `include_domains` (optional, at most 100), `exclude_domains` (optional, at most 1,200; wins over `include_domains`), `summary` (optional, default `false`). Returns `summary` first when requested (`{ text, citations: [{ index, url, title }] }`; `[n]` in `text` refers to `citations[].index`; `null` with `meta.notices` `Summary unavailable.` when it could not be written), then `results`, `meta` (`latency_ms`, `notices`), `cost_usd`, `usage_count`, `service`, and `currency`. The summary has no extra charge.
69
+ - **Web Links Search** (`web-links-search`): Deprecated; use `search-api`. Web link search on `POST /desearch/ai/search/links/web`. Arguments: `prompt` (required), `tools` (optional, only `web`, default `["web"]`; `Web Search` is accepted and rewritten to `web`), `count` (optional, 10–200). The links/web API rejects other sources, so they are not in the enum.
70
70
  - **Extract** (`extract`): Read a public URL as text or HTML. Preferred over crawl. Arguments: `url` (required), `format` (optional, `text`, `markdown` or `html`), `js` (optional), `wait` (optional milliseconds), `full_page` (optional, `text` only: every visible section of the page instead of its main content). Errors carry an `error_code`: `js_required` (retry with `js: true`), `blocked` (the site refused or showed a bot check), `page_not_found`.
71
71
  - **Web Crawl** (`web-crawl`): Same arguments as `extract`, on the legacy `/web/crawl` route. The SDK marks `webCrawl` deprecated in favor of `extract`; this tool stays so that route remains reachable. Prefer `extract` for new integrations.
72
72
  - **X Links Search** (`x-links-search`): AI search for X post links. Arguments: `prompt` (required), `count` (optional, 10–200).
@@ -100,6 +100,17 @@ Lookup tools, including `search` and `fetch`, set `readOnlyHint: true`, `destruc
100
100
  - **Cancel Company Search** (`company-search-cancel`): Stop a task for good. You pay only for the companies it already delivered (a search with `max_cost_usd`: its search effort so far when that is more, up to the budget); the rest of the reservation is returned. Cannot be undone. Argument: `task_id` (required). Free.
101
101
  - **List Company Search Tasks** (`company-search-tasks`): Your Company Search and Company Enrich tasks, newest first. Arguments: `type` (optional, `search` or `enrich`), `status` (optional list), `limit` (optional, 1–100), `cursor` (optional), `metadata` (optional, up to 3 labels, exact match). Free; People Search tasks are not listed here.
102
102
 
103
+ ### Cost of each call
104
+
105
+ Every tool result from a billed Desearch API call carries that call's cost in the result's `_meta`: `cost_usd` (USD) and `usage_count` (billed units), from the API's `X-Desearch-Cost-Usd` and `X-Desearch-Usage-Count` response headers. This holds for every result shape, including tools whose result is a list or plain text (`x-search`, `x-posts-by-user`, `extract`). The result content and `structuredContent` are unchanged. A free call reports `cost_usd: 0`; a failed call and a call with no cost headers carry no `_meta` cost. Example `tools/call` result:
106
+
107
+ ```json
108
+ {
109
+ "content": [{ "type": "text", "text": "[ ... posts ... ]" }],
110
+ "_meta": { "cost_usd": 0.0015, "usage_count": 10 }
111
+ }
112
+ ```
113
+
103
114
  The full SDK method → endpoint → MCP tool map is in [docs/API_MCP_PARITY.md](docs/API_MCP_PARITY.md). Every public `desearch-js` 1.5 method is a tool. `latestTweets` was removed from the SDK (`GET /twitter/latest` in 1.0.1) and is not exposed. People Search, Company Search, the TikTok, Facebook, Instagram, YouTube, Reddit, and Threads routes, and `POST /search` are not in `desearch-js` 1.5; those tools call the routes directly (`/desearch/people/*`, `/desearch/companies/*`, and the rest), and the parity doc lists them too. The network stats routes (`/network/stats`) are not MCP tools.
104
115
 
105
116
  ### TikTok, Facebook, and Instagram
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Cost of one MCP tool call, from the Desearch API's `X-Desearch-Cost-Usd` and
3
+ * `X-Desearch-Usage-Count` response headers.
4
+ *
5
+ * Every tool call runs inside `withCostMeter`. Each API response the call reads
6
+ * (direct calls in desearch-api.ts and desearch-js calls) adds its headers to the
7
+ * call's meter, and the tool result carries the total in `_meta`:
8
+ * `{ cost_usd, usage_count }`. `_meta` works for every result shape (JSON object,
9
+ * bare list, plain text) and never changes the result content or `structuredContent`.
10
+ *
11
+ * AsyncLocalStorage keeps concurrent calls on one server (stdio) apart.
12
+ */
13
+ export interface CostMeta {
14
+ cost_usd?: number;
15
+ usage_count?: number;
16
+ }
17
+ /** Add one billed response to the current tool call. Outside a tool call it does nothing. */
18
+ export declare function recordCost(costUsd: number | undefined, usageCount: number | undefined): void;
19
+ /** Add one API response's `X-Desearch-Cost-Usd` / `X-Desearch-Usage-Count` headers to the current tool call. */
20
+ export declare function recordCostHeaders(headers: {
21
+ get(name: string): string | null;
22
+ }): void;
23
+ /** Run one tool call with its own meter; returns the result and what the call's API responses reported. */
24
+ export declare function withCostMeter<T>(run: () => Promise<T>): Promise<{
25
+ result: T;
26
+ cost: CostMeta;
27
+ }>;
28
+ //# sourceMappingURL=cost-meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost-meta.d.ts","sourceRoot":"","sources":["../cost-meta.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,QAAQ;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAsBD,6FAA6F;AAC7F,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAW5F;AAED,gHAAgH;AAChH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,CAErF;AAED,2GAA2G;AAC3G,wBAAsB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,CAAC,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAWpG"}
@@ -0,0 +1,43 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ const meters = new AsyncLocalStorage();
3
+ /** Header values carry float noise (0.0014999999999999998); ten decimals is far below a billing unit. */
4
+ function round(value) {
5
+ return Math.round(value * 1e10) / 1e10;
6
+ }
7
+ function headerNumber(value) {
8
+ if (value === null || value === undefined || value.trim() === "") {
9
+ return undefined;
10
+ }
11
+ const parsed = Number(value);
12
+ return Number.isFinite(parsed) ? parsed : undefined;
13
+ }
14
+ /** Add one billed response to the current tool call. Outside a tool call it does nothing. */
15
+ export function recordCost(costUsd, usageCount) {
16
+ const meter = meters.getStore();
17
+ if (!meter) {
18
+ return;
19
+ }
20
+ if (costUsd !== undefined && Number.isFinite(costUsd)) {
21
+ meter.costUsd = round((meter.costUsd ?? 0) + costUsd);
22
+ }
23
+ if (usageCount !== undefined && Number.isFinite(usageCount)) {
24
+ meter.usageCount = (meter.usageCount ?? 0) + usageCount;
25
+ }
26
+ }
27
+ /** Add one API response's `X-Desearch-Cost-Usd` / `X-Desearch-Usage-Count` headers to the current tool call. */
28
+ export function recordCostHeaders(headers) {
29
+ recordCost(headerNumber(headers.get("x-desearch-cost-usd")), headerNumber(headers.get("x-desearch-usage-count")));
30
+ }
31
+ /** Run one tool call with its own meter; returns the result and what the call's API responses reported. */
32
+ export async function withCostMeter(run) {
33
+ const meter = {};
34
+ const result = await meters.run(meter, run);
35
+ const cost = {};
36
+ if (meter.costUsd !== undefined) {
37
+ cost.cost_usd = meter.costUsd;
38
+ }
39
+ if (meter.usageCount !== undefined) {
40
+ cost.usage_count = meter.usageCount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+ {"version":3,"file":"desearch-api.d.ts","sourceRoot":"","sources":["../desearch-api.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAGjC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAE/D,MAAM,WAAW,WAAW;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,IAAI,EAAE,OAAO,CAAC;IACd,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CACjD;AAED,MAAM,WAAW,iBAAiB;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED,MAAM,MAAM,WAAW,GAAG,CACtB,MAAM,EAAE,KAAK,GAAG,MAAM,EACtB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,iBAAiB,KAC1B,OAAO,CAAC,WAAW,CAAC,CAAC;AAM1B,uGAAuG;AACvG,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAO/D;AAED,sDAAsD;AACtD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,MAAM,CASlF;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,MAA8B,GAAG,WAAW,CAiCtG"}
@@ -1,4 +1,5 @@
1
1
  import { fetch } from "undici";
2
+ import { recordCostHeaders } from "./cost-meta.js";
2
3
  /**
3
4
  * Direct calls to the Desearch API for routes desearch-js 1.5 does not cover
4
5
  * (People Search, the TikTok, Facebook, Instagram, YouTube, Reddit and Threads routes,
@@ -67,6 +68,7 @@ export function createDesearchApi(apiKey, baseUrl = DESEARCH_API_BASE_URL) {
67
68
  if (!response.ok) {
68
69
  throw new Error(`HTTP ${response.status}: ${errorDetail(data, text)}`);
69
70
  }
71
+ recordCostHeaders(response.headers);
70
72
  return { status: response.status, data, text, headers: response.headers };
71
73
  };
72
74
  }
package/build/http.d.ts CHANGED
@@ -14,12 +14,15 @@ export interface RunningHttpServer {
14
14
  * the rewritten URL (`/api/mcp`) rather than the public path (`/mcp`).
15
15
  */
16
16
  export declare function requestWithPathname(request: Request, pathname: string): Request;
17
+ /** Public docs page that browsers and crawlers land on when they open /mcp without a key. */
18
+ export declare const MCP_DOCS_URL = "https://www.desearch.ai/docs/guide/sdk/mcp";
17
19
  /**
18
20
  * Stateless Streamable HTTP handler.
19
21
  * Each POST builds a fresh MCP server tied to that request's API key.
20
22
  * JSON responses (not a long-lived SSE session) so the same handler runs
21
23
  * in a local Node process and in a Vercel function.
22
24
  * GET and DELETE return 405: this server does not push messages or store sessions.
25
+ * A keyless browser GET (Accept: text/html) is sent to the public MCP docs page instead.
23
26
  */
24
27
  export declare function handleMcpHttpRequest(request: Request): Promise<Response>;
25
28
  export declare function startHttpServer(options?: HttpListenOptions): Promise<RunningHttpServer>;
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../http.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAGzD,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAoBjC,MAAM,WAAW,iBAAiB;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAa/E;AAiOD;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA0I9E;AA8DD,wBAAgB,eAAe,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAiD3F"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../http.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAGzD,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAoBjC,MAAM,WAAW,iBAAiB;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAa/E;AAuED,6FAA6F;AAC7F,eAAO,MAAM,YAAY,+CAA+C,CAAC;AAwLzE;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoL9E;AA8DD,wBAAgB,eAAe,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAiD3F"}
package/build/http.js CHANGED
@@ -3,6 +3,8 @@ import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/
3
3
  import { PUBLIC_ICONS } from "./icons.js";
4
4
  import { AGENT_TOOLS_ORG_TOKEN } from "./agent-tools-org.js";
5
5
  import { AGENT_TOOLS_VERIFY_TOKEN } from "./agent-tools-verify.js";
6
+ import { MUSE_CHALLENGES } from "./muse-challenge.js";
7
+ import { MCPBUNDLES_BODY } from "./mcpbundles.js";
6
8
  import { openaiAppsChallengeToken } from "./openai-apps-challenge.js";
7
9
  import { DIRECT_CLIENT_IP_HEADER } from "./oauth/client-ip.js";
8
10
  import { OAuthConfigError } from "./oauth/errors.js";
@@ -99,6 +101,34 @@ const LOGIN_CHALLENGE = {
99
101
  error: "insufficient_scope",
100
102
  error_description: "You need to login to continue",
101
103
  };
104
+ /** Public docs page that browsers and crawlers land on when they open /mcp without a key. */
105
+ export const MCP_DOCS_URL = "https://www.desearch.ai/docs/guide/sdk/mcp";
106
+ /**
107
+ * A plain page view of /mcp: GET or HEAD, Accept asks for HTML, and nothing
108
+ * marks it as an MCP client (no SSE Accept, no MCP session or protocol header).
109
+ * MCP clients send `Accept: text/event-stream` on GET, so they keep the 401
110
+ * challenge that drives their OAuth or key prompt.
111
+ */
112
+ function isBrowserPageView(request) {
113
+ if (request.method !== "GET" && request.method !== "HEAD") {
114
+ return false;
115
+ }
116
+ const accept = (request.headers.get("accept") ?? "").toLowerCase();
117
+ if (!accept.includes("text/html") || accept.includes("text/event-stream")) {
118
+ return false;
119
+ }
120
+ return !request.headers.has("mcp-session-id") && !request.headers.has("mcp-protocol-version");
121
+ }
122
+ function docsRedirect() {
123
+ return new Response(null, {
124
+ status: 301,
125
+ headers: {
126
+ Location: MCP_DOCS_URL,
127
+ Vary: "Accept",
128
+ "Cache-Control": "no-store",
129
+ },
130
+ });
131
+ }
102
132
  const UNAUTHORIZED_MESSAGE = "Unauthorized. Send your Desearch API key in the Authorization: Bearer <key> header or the x-api-key header.";
103
133
  function challengeHeader(request, challenge) {
104
134
  try {
@@ -246,6 +276,7 @@ function requestWithJsonBody(request, body) {
246
276
  * JSON responses (not a long-lived SSE session) so the same handler runs
247
277
  * in a local Node process and in a Vercel function.
248
278
  * GET and DELETE return 405: this server does not push messages or store sessions.
279
+ * A keyless browser GET (Accept: text/html) is sent to the public MCP docs page instead.
249
280
  */
250
281
  export async function handleMcpHttpRequest(request) {
251
282
  if (request.method === "OPTIONS") {
@@ -279,6 +310,42 @@ export async function handleMcpHttpRequest(request) {
279
310
  },
280
311
  }));
281
312
  }
313
+ const musePathname = new URL(request.url).pathname;
314
+ const musePrefix = "/.well-known/muse-challenge/";
315
+ if (musePathname.startsWith(musePrefix) || musePathname === "/api/muse-challenge") {
316
+ if (request.method !== "GET" && request.method !== "HEAD") {
317
+ return withCors(jsonRpcError(405, -32000, "Method not allowed.", { Allow: "GET, HEAD" }));
318
+ }
319
+ const token = musePathname === "/api/muse-challenge"
320
+ ? "a68cf22bcf914c4484bf5adb84ba1401604f2374615d870b51ef7414a681fd7e"
321
+ : musePathname.slice(musePrefix.length);
322
+ const body = MUSE_CHALLENGES.get(token);
323
+ if (body === undefined) {
324
+ return withCors(new Response(JSON.stringify({ error: "Not found" }), {
325
+ status: 404,
326
+ headers: { "Content-Type": "application/json" },
327
+ }));
328
+ }
329
+ return withCors(new Response(request.method === "HEAD" ? null : body, {
330
+ status: 200,
331
+ headers: {
332
+ "Content-Type": "text/plain; charset=utf-8",
333
+ "Cache-Control": "no-store",
334
+ },
335
+ }));
336
+ }
337
+ if (pathname === "/.well-known/mcpbundles.json" || pathname === "/api/mcpbundles") {
338
+ if (request.method !== "GET" && request.method !== "HEAD") {
339
+ return withCors(jsonRpcError(405, -32000, "Method not allowed.", { Allow: "GET, HEAD" }));
340
+ }
341
+ return withCors(new Response(request.method === "HEAD" ? null : MCPBUNDLES_BODY, {
342
+ status: 200,
343
+ headers: {
344
+ "Content-Type": "application/json",
345
+ "Cache-Control": "no-store",
346
+ },
347
+ }));
348
+ }
282
349
  if (pathname === "/.well-known/agent-tools.txt" || pathname === "/api/agent-tools") {
283
350
  if (request.method !== "GET" && request.method !== "HEAD") {
284
351
  return withCors(jsonRpcError(405, -32000, "Method not allowed.", { Allow: "GET, HEAD" }));
@@ -326,6 +393,9 @@ export async function handleMcpHttpRequest(request) {
326
393
  if (credential.kind === "unavailable") {
327
394
  return withCors(jsonRpcError(500, -32603, "Authorization storage is unavailable."));
328
395
  }
396
+ if (credential.kind === "anonymous" && isBrowserPageView(request)) {
397
+ return withCors(docsRedirect());
398
+ }
329
399
  if (request.method === "GET" || request.method === "DELETE") {
330
400
  if (credential.kind !== "key") {
331
401
  return withCors(unauthorized(request, credential.kind === "unauthorized"));
@@ -0,0 +1,2 @@
1
+ export declare const MCPBUNDLES_BODY: string;
2
+ //# sourceMappingURL=mcpbundles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcpbundles.d.ts","sourceRoot":"","sources":["../mcpbundles.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,QAAkE,CAAC"}
@@ -0,0 +1 @@
1
+ export const MCPBUNDLES_BODY = JSON.stringify({ maintainers: [{ email: "dev@desearch.ai" }] });
@@ -0,0 +1,2 @@
1
+ export declare const MUSE_CHALLENGES: Map<string, string>;
2
+ //# sourceMappingURL=muse-challenge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"muse-challenge.d.ts","sourceRoot":"","sources":["../muse-challenge.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,qBAE1B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export const MUSE_CHALLENGES = new Map([
2
+ ["a68cf22bcf914c4484bf5adb84ba1401604f2374615d870b51ef7414a681fd7e", "muse-challenge=a68cf22bcf914c4484bf5adb84ba1401604f2374615d870b51ef7414a681fd7e"],
3
+ ]);
@@ -1 +1 @@
1
- {"version":3,"file":"redirects.d.ts","sourceRoot":"","sources":["../../oauth/redirects.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAiC3D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAqB7E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMtD"}
1
+ {"version":3,"file":"redirects.d.ts","sourceRoot":"","sources":["../../oauth/redirects.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqBH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAiC3D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAqB7E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMtD"}
@@ -8,6 +8,12 @@ const EXACT_REDIRECTS = new Set([
8
8
  "https://claude.ai/api/mcp/auth_callback",
9
9
  "https://claude.com/api/mcp/auth_callback",
10
10
  "https://chatgpt.com/connector_platform_oauth_redirect",
11
+ "https://muse.ai/api/hatch/oauth/callback",
12
+ "https://platform.muse.ai/oauth/credential-test/callback",
13
+ "https://agent.meta.ai/api/hatch/oauth/callback",
14
+ "https://www.perplexity.ai/rest/connections/oauth_callback",
15
+ "https://enterprise.perplexity.ai/rest/connections/oauth_callback",
16
+ "https://teams.microsoft.com/api/platform/v1.0/oAuthRedirect",
11
17
  ]);
12
18
  const CHATGPT_CALLBACK_ID = /^\/connector\/oauth\/[A-Za-z0-9._~-]{1,200}$/;
13
19
  function isLoopbackHost(hostname) {
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.9.0";
6
+ export declare const SERVER_VERSION = "0.11.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;
@@ -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;AAI5C,OAAO,EAqBH,KAAK,YAAY,EACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAeH,KAAK,aAAa,EACrB,MAAM,gBAAgB,CAAC;AAIxB,eAAO,MAAM,WAAW,aAAa,CAAC;AACtC,eAAO,MAAM,cAAc,UAAU,CAAC;AACtC,eAAO,MAAM,YAAY,aAAa,CAAC;AACvC,eAAO,MAAM,kBAAkB,4BAA4B,CAAC;AAG5D,eAAO,MAAM,mBAAmB,QAA6F,CAAC;AAE9H,eAAO,MAAM,YAAY,EAAE,IAAI,EAG9B,CAAC;AAEF,UAAU,cAAc;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,kBAAkB;IACxB,GAAG,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p.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 { recordCost, withCostMeter } from "./cost-meta.js";
5
6
  import { createDesearchApi } from "./desearch-api.js";
6
7
  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
8
  import { COMPANY_COUNTRIES_MAX, COMPANY_DOMAINS_MAX, COMPANY_EXCLUDE_MAX, COMPANY_REQUIREMENTS, COMPANY_ROLES, COMPANY_SEARCH_MAX_BUDGET_USD, COMPANY_TASK_STATUSES, COMPANY_TASK_TYPES, companyClientFor, controlCompanyTask, listCompanyTasks, readCompanyStatus, startCompanyEnrich, startCompanySearch, } from "./companies.js";
8
9
  import { runSocialAction, socialActionNames } from "./social.js";
9
10
  import { AI_SEARCH_TOOLS, WEB_LINK_TOOLS, toolIdSchema } from "./tool-sources.js";
10
11
  export const SERVER_NAME = "Desearch";
11
- export const SERVER_VERSION = "0.9.0";
12
+ export const SERVER_VERSION = "0.11.0";
12
13
  export const SERVER_TITLE = "Desearch";
13
14
  export const SERVER_WEBSITE_URL = "https://www.desearch.ai";
14
15
  // Public origin of the hosted server, which serves the icons below.
@@ -17,6 +18,55 @@ export const SERVER_ICONS = [
17
18
  { src: `${MCP_PUBLIC_BASE_URL}/icon-512.png`, mimeType: "image/png", sizes: ["512x512"] },
18
19
  { src: `${MCP_PUBLIC_BASE_URL}/icon-64.png`, mimeType: "image/png", sizes: ["64x64"] },
19
20
  ];
21
+ const DESEARCH_CLIENT_METHODS = [
22
+ "aiSearch",
23
+ "xSearch",
24
+ "webSearch",
25
+ "aiWebLinksSearch",
26
+ "aiXLinksSearch",
27
+ "xPostsByUrls",
28
+ "xPostById",
29
+ "xPostsByUser",
30
+ "xPostRetweeters",
31
+ "xUserPosts",
32
+ "xUserReplies",
33
+ "xPostReplies",
34
+ "xTrends",
35
+ "extract",
36
+ "webCrawl",
37
+ ];
38
+ function metadataNumber(value) {
39
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
40
+ }
41
+ /**
42
+ * desearch-js 1.5 returns `{ data, metadata }` when called with `includeMetadata: true`;
43
+ * `metadata` holds the parsed `X-Desearch-Cost-Usd` / `X-Desearch-Usage-Count` headers.
44
+ * The cost goes to the current tool call's meter (cost-meta.ts) and the tool sees `data`,
45
+ * so the result content is the same as before. A client that ignores the option
46
+ * (test fakes) returns the body itself, which passes through with no cost.
47
+ */
48
+ function sdkData(value) {
49
+ if (isPlainObject(value) &&
50
+ Object.keys(value).length === 2 &&
51
+ "data" in value &&
52
+ isPlainObject(value.metadata)) {
53
+ recordCost(metadataNumber(value.metadata.costUsd), metadataNumber(value.metadata.usageCount));
54
+ return value.data;
55
+ }
56
+ return value;
57
+ }
58
+ /** The same client, with every call asking desearch-js for the response's cost headers. */
59
+ function meteredClient(client) {
60
+ const metered = {};
61
+ const source = client;
62
+ for (const name of DESEARCH_CLIENT_METHODS) {
63
+ const method = source[name];
64
+ if (typeof method === "function") {
65
+ metered[name] = async (payload) => sdkData(await method.call(client, payload, { includeMetadata: true }));
66
+ }
67
+ }
68
+ return metered;
69
+ }
20
70
  // desearch-js 1.5 publishes a default class. Node16 resolution types that package
21
71
  // as a module namespace, so the constructor is applied through a cast.
22
72
  const Desearch = DesearchImport;
@@ -345,6 +395,13 @@ export function presentSearchBody(value) {
345
395
  message: NO_LINKS_MESSAGE,
346
396
  };
347
397
  }
398
+ function summaryFirst(value) {
399
+ if (!isPlainObject(value) || !("summary" in value)) {
400
+ return value;
401
+ }
402
+ const { summary, ...rest } = value;
403
+ return { summary, ...rest };
404
+ }
348
405
  function ok(value) {
349
406
  return {
350
407
  content: [{ type: "text", text: JSON.stringify(value, null, 2) }],
@@ -441,7 +498,11 @@ function registerTool(server, apiKey, name, title, description, inputSchema, han
441
498
  if (!apiKey) {
442
499
  return fail("Desearch", new Error("Desearch API key required. Send it in the Authorization: Bearer <key> header or the x-api-key header."));
443
500
  }
444
- return handler(args);
501
+ const { result, cost } = await withCostMeter(() => handler(args));
502
+ if (Object.keys(cost).length === 0) {
503
+ return result;
504
+ }
505
+ return { ...result, _meta: { ...result._meta, ...cost } };
445
506
  };
446
507
  register(name, {
447
508
  title,
@@ -463,7 +524,7 @@ function registerTool(server, apiKey, name, title, description, inputSchema, han
463
524
  * for that key.
464
525
  */
465
526
  export function createDesearchMcpServer(apiKey, client, peopleClient, companyClient) {
466
- const desearch = client ?? new Desearch(apiKey);
527
+ const desearch = meteredClient(client ?? new Desearch(apiKey));
467
528
  const api = createDesearchApi(apiKey);
468
529
  const people = peopleClient ?? peopleClientFor(api);
469
530
  const companies = companyClient ?? companyClientFor(api);
@@ -475,9 +536,9 @@ export function createDesearchMcpServer(apiKey, client, peopleClient, companyCli
475
536
  icons: SERVER_ICONS,
476
537
  };
477
538
  const server = new McpServer(serverInfo, {
478
- 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, instagram, youtube, reddit, and threads read public social data (posts, profiles, comments, hashtags, YouTube transcripts and channels, subreddits); list actions return next_cursor for the next page where the platform has one. 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. Set company-search's max_cost_usd only when the user agreed to that budget: it bills search effort even when few companies are found. Calls need a Desearch API key.",
539
+ 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 is web search on the Desearch index: ranked pages with the passage that best matches the query, and with summary: true a short answer with numbered citations. ai-search covers X posts and web with an optional AI summary. Other tools cover X posts and page extraction. tiktok, facebook, instagram, youtube, reddit, and threads read public social data (posts, profiles, comments, hashtags, YouTube transcripts and channels, subreddits); list actions return next_cursor for the next page where the platform has one. 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. Set company-search's max_cost_usd only when the user agreed to that budget: it bills search effort even when few companies are found. Calls need a Desearch API key.",
479
540
  });
480
- registerTool(server, apiKey, "ai-search", "AI Search", "AI search and analysis on web using Desearch AI", {
541
+ registerTool(server, apiKey, "ai-search", "AI Search", "AI Search over X (Twitter) posts and web (from the Desearch index), with an optional AI summary. Web results are capped at 20 per request. For web-only search, use search-api.", {
481
542
  prompt: z.string().describe("Question, example: 'What is the latest news on AI?'"),
482
543
  tools: z
483
544
  .array(toolIdSchema(AI_SEARCH_TOOLS))
@@ -610,7 +671,7 @@ export function createDesearchMcpServer(apiKey, client, peopleClient, companyCli
610
671
  return fail("Web Search error", error);
611
672
  }
612
673
  });
613
- registerTool(server, apiKey, "web-links-search", "Web Links Search", "Search the web for links using Desearch. Only the web source is accepted.", {
674
+ registerTool(server, apiKey, "web-links-search", "Web Links Search", "Deprecated: use search-api. Search the web for links using Desearch (POST /desearch/ai/search/links/web). Only the web source is accepted.", {
614
675
  prompt: z
615
676
  .string()
616
677
  .describe("Search query prompt, example: 'open source browser automation tools'"),
@@ -766,7 +827,7 @@ export function createDesearchMcpServer(apiKey, client, peopleClient, companyCli
766
827
  return fail("X Trends error", error);
767
828
  }
768
829
  });
769
- 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.", {
830
+ registerTool(server, apiKey, "search-api", "Search API", "Web search on the Desearch index (POST /search). Returns ranked pages, each with its title, URL, publication date when known, and the passage that best matches the query. Set summary: true for a short answer written from the results with numbered citations; [n] in summary.text refers to summary.citations[].index. Set page_text to add each page's full text. Returns { summary, results, meta, cost_usd, usage_count, service, currency }, with summary first when requested; summary is null and meta.notices says 'Summary unavailable.' when it could not be written. Use search for titles and links only, and web-search for SERP-style snippets.", {
770
831
  query: z.string().min(1).max(2000).describe("Search query, example: 'Who won the 2024 Nobel Prize in Physics?'"),
771
832
  mode: z
772
833
  .enum(["fast", "balanced"])
@@ -795,10 +856,37 @@ export function createDesearchMcpServer(apiKey, client, peopleClient, companyCli
795
856
  .optional()
796
857
  .describe("Include the passage that best matches the query (API default true)."),
797
858
  page_text: z.boolean().optional().describe("Include each page's full text (API default false)."),
798
- }, async ({ query, mode, count, start_date, end_date, highlights, page_text }) => {
859
+ include_domains: z
860
+ .array(z.string())
861
+ .max(100)
862
+ .optional()
863
+ .describe("Only pages on these domains or their subdomains (at most 100), example: ['bbc.com', 'reuters.com']"),
864
+ exclude_domains: z
865
+ .array(z.string())
866
+ .max(1200)
867
+ .optional()
868
+ .describe("Never pages on these domains or their subdomains (at most 1,200). Wins over include_domains and site:."),
869
+ summary: z
870
+ .boolean()
871
+ .optional()
872
+ .describe("Also return a short answer written from the results, with numbered citations (API default false). No extra charge."),
873
+ }, async ({ query, mode, count, start_date, end_date, highlights, page_text, include_domains, exclude_domains, summary, }) => {
799
874
  try {
800
- const body = { query, ...definedFields({ mode, count, start_date, end_date, highlights, page_text }) };
801
- return ok((await api("POST", "/search", { body })).data);
875
+ const body = {
876
+ query,
877
+ ...definedFields({
878
+ mode,
879
+ count,
880
+ start_date,
881
+ end_date,
882
+ highlights,
883
+ page_text,
884
+ include_domains,
885
+ exclude_domains,
886
+ summary,
887
+ }),
888
+ };
889
+ return ok(summaryFirst((await api("POST", "/search", { body })).data));
802
890
  }
803
891
  catch (error) {
804
892
  return fail("Search API error", error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "desearch-mcp-server",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "mcpName": "io.github.Desearch-ai/mcp-desearch",
5
5
  "description": "AI search (web, Reddit, Hacker News, arXiv, Wikipedia, and Twitter), X (Twitter) search, web search, the Search API, public TikTok, Facebook, Instagram, YouTube (including transcripts), Reddit, and Threads 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 39 tools.",
6
6
  "license": "MIT",