desearch-mcp-server 0.9.0 → 0.10.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,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.0
4
+
5
+ Cost on every tool result, as the hosted server has had since 06a3ec0.
6
+
7
+ - 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.
8
+ - Every version (package, `server.json`, the Gemini extension, the plugin manifests, and `SERVER_VERSION`) is 0.10.0. The tool count is unchanged (39).
9
+
3
10
  ## 0.9.0
4
11
 
5
12
  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.10.0 exposes 39 tools.
56
56
 
57
57
  ## Tools
58
58
 
@@ -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;
41
+ }
42
+ return { result, cost };
43
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"desearch-api.d.ts","sourceRoot":"","sources":["../desearch-api.ts"],"names":[],"mappings":"AAEA;;;;;;;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,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B,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
  }
@@ -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;AAiOD;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAgL9E;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";
@@ -279,6 +281,42 @@ export async function handleMcpHttpRequest(request) {
279
281
  },
280
282
  }));
281
283
  }
284
+ const musePathname = new URL(request.url).pathname;
285
+ const musePrefix = "/.well-known/muse-challenge/";
286
+ if (musePathname.startsWith(musePrefix) || musePathname === "/api/muse-challenge") {
287
+ if (request.method !== "GET" && request.method !== "HEAD") {
288
+ return withCors(jsonRpcError(405, -32000, "Method not allowed.", { Allow: "GET, HEAD" }));
289
+ }
290
+ const token = musePathname === "/api/muse-challenge"
291
+ ? "a68cf22bcf914c4484bf5adb84ba1401604f2374615d870b51ef7414a681fd7e"
292
+ : musePathname.slice(musePrefix.length);
293
+ const body = MUSE_CHALLENGES.get(token);
294
+ if (body === undefined) {
295
+ return withCors(new Response(JSON.stringify({ error: "Not found" }), {
296
+ status: 404,
297
+ headers: { "Content-Type": "application/json" },
298
+ }));
299
+ }
300
+ return withCors(new Response(request.method === "HEAD" ? null : body, {
301
+ status: 200,
302
+ headers: {
303
+ "Content-Type": "text/plain; charset=utf-8",
304
+ "Cache-Control": "no-store",
305
+ },
306
+ }));
307
+ }
308
+ if (pathname === "/.well-known/mcpbundles.json" || pathname === "/api/mcpbundles") {
309
+ if (request.method !== "GET" && request.method !== "HEAD") {
310
+ return withCors(jsonRpcError(405, -32000, "Method not allowed.", { Allow: "GET, HEAD" }));
311
+ }
312
+ return withCors(new Response(request.method === "HEAD" ? null : MCPBUNDLES_BODY, {
313
+ status: 200,
314
+ headers: {
315
+ "Content-Type": "application/json",
316
+ "Cache-Control": "no-store",
317
+ },
318
+ }));
319
+ }
282
320
  if (pathname === "/.well-known/agent-tools.txt" || pathname === "/api/agent-tools") {
283
321
  if (request.method !== "GET" && request.method !== "HEAD") {
284
322
  return withCors(jsonRpcError(405, -32000, "Method not allowed.", { Allow: "GET, HEAD" }));
@@ -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.10.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,EAA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C,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACvD,QAAQ,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3D;AA4YD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AAuCvD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAYzD;AAoJD;;;;;;;;;;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,CAo6CX"}
package/build/server.js CHANGED
@@ -2,13 +2,14 @@ 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 { 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.10.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;
@@ -441,7 +491,11 @@ function registerTool(server, apiKey, name, title, description, inputSchema, han
441
491
  if (!apiKey) {
442
492
  return fail("Desearch", new Error("Desearch API key required. Send it in the Authorization: Bearer <key> header or the x-api-key header."));
443
493
  }
444
- return handler(args);
494
+ const { result, cost } = await withCostMeter(() => handler(args));
495
+ if (Object.keys(cost).length === 0) {
496
+ return result;
497
+ }
498
+ return { ...result, _meta: { ...result._meta, ...cost } };
445
499
  };
446
500
  register(name, {
447
501
  title,
@@ -463,7 +517,7 @@ function registerTool(server, apiKey, name, title, description, inputSchema, han
463
517
  * for that key.
464
518
  */
465
519
  export function createDesearchMcpServer(apiKey, client, peopleClient, companyClient) {
466
- const desearch = client ?? new Desearch(apiKey);
520
+ const desearch = meteredClient(client ?? new Desearch(apiKey));
467
521
  const api = createDesearchApi(apiKey);
468
522
  const people = peopleClient ?? peopleClientFor(api);
469
523
  const companies = companyClient ?? companyClientFor(api);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "desearch-mcp-server",
3
- "version": "0.9.0",
3
+ "version": "0.10.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",