@maviapi/mcp 0.2.2 → 0.2.4

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/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # maviapi MCP server
2
2
 
3
- Give Claude, Cursor, or any MCP client **live, structured JSON from websites that have no API**: Booking.com, Airbnb, Tripadvisor, Kiwi.com, Trainline, Hepsiburada, Yemeksepeti and more, plus any site you ask for.
3
+ [![npm](https://img.shields.io/npm/v/@maviapi/mcp)](https://www.npmjs.com/package/@maviapi/mcp) [![kuzenlabs/maviapi-mcp MCP server](https://glama.ai/mcp/servers/kuzenlabs/maviapi-mcp/badges/score.svg)](https://glama.ai/mcp/servers/kuzenlabs/maviapi-mcp)
4
+
5
+ **The unofficial API for any website, as MCP tools.** Give Claude, Cursor, or any MCP client live, structured JSON from websites that have no official API: Booking.com, Airbnb, Tripadvisor, Kiwi.com, Trainline, Hepsiburada, Yemeksepeti and more, plus any site you ask for. These are independent integrations, not affiliated with the sites.
4
6
 
5
7
  ```
6
8
  You: Find me a 3-night Airbnb in Lisbon next month under €120 a night.
@@ -97,7 +99,7 @@ Leave out `env` to try it with the demo key.
97
99
  |------|--------------|
98
100
  | `search_apis` | Find an API for a website or topic ("flights", "turkish news", "booking.com"). Empty query lists the whole catalog. |
99
101
  | `get_api` | An API's endpoints, their parameters, and the fields each one returns. |
100
- | `call_api` | Call an endpoint and get live JSON back. List endpoints return 10 results unless you pass `limit`. |
102
+ | `call_api` | Call an endpoint and get live JSON back. List endpoints return 10 results unless you pass `limit`. An answer over 50,000 characters is cut to whole rows and flagged `truncated` (rows returned, rows asked); the HTTP API itself never cuts. |
101
103
  | `create_api` | No API for the site you need? Starts a build from a URL and a plain-language description, and returns a `request_id`. |
102
104
  | `get_build_status` | Where a build is: its phase, each endpoint with its test results or what went wrong, and what the build said last. `wait_seconds` returns as soon as something changes. A finished build is not public until it is published. |
103
105
  | `request_endpoint` | Add one endpoint to an API that exists, or a changed version of one (it ships beside the old one, e.g. `/search-v2`). Previews first; `confirm: true` starts the build. |
@@ -107,8 +109,8 @@ Leave out `env` to try it with the demo key.
107
109
  | `publish_request` | Make a finished request live. Needs a key with the `requests:publish` permission. |
108
110
  | `cancel_request` | Stop the build running for a request. |
109
111
  | `report_endpoint_issue` | Report an endpoint that fails, comes back empty or repeats the same page. maviapi replays the call and checks the endpoint itself: a fault its own check confirms is repaired in place, the rest go to a person. You can report an API you have called with your own key. With no arguments it lists your reports. |
110
- | `get_key_info` | What the configured key may do: permissions, plan, remaining credits, limits. |
111
- | `get_changelog` | An API's versions, newest first, with what changed. `call_api` takes a `version`. |
112
+ | `get_key_info` | What the configured key may do: permissions, plan, remaining credits, limits. Works with any key of your own, with or without permissions. |
113
+ | `get_changelog` | What changed in an API, newest first: the date of each change, which one is live, and what it changed. |
112
114
 
113
115
  The request tools need your own API key with request permissions. A key only calls data APIs unless you turn permissions on when you create it on the [keys page](https://maviapi.com/dashboard/keys): "Start and manage builds" for asking, steering, cancelling and reporting, and "Publish builds" for `publish_request`. `create_api` works with any key. Every rule (who may publish, one build per API at a time with up to 3 requests in line, the daily limits) is enforced by maviapi, not by this server.
114
116
 
package/dist/catalog.js CHANGED
@@ -197,36 +197,69 @@ export function findEndpoint(endpoints, ref) {
197
197
  endpoints.find((e) => e.slug.toLowerCase() === r) ??
198
198
  endpoints.find((e) => e.path.toLowerCase().replace(/^\/+/, "") === r));
199
199
  }
200
- /** Rank catalog APIs against a free-text query. An empty query lists them all. */
201
- export function searchApis(apis, query) {
200
+ /** Query words that say nothing about which API is meant. */
201
+ const STOP_WORDS = new Set([
202
+ "a", "an", "the", "of", "in", "on", "at", "for", "to", "from", "by", "with", "and", "or",
203
+ "api", "apis", "data", "site", "website", "com", "www",
204
+ ]);
205
+ /**
206
+ * A score an API reaches only through its slug, name or site (not its
207
+ * description alone). With it an API is kept even when some query words miss.
208
+ */
209
+ export const STRONG_MATCH = 4;
210
+ /** Lowercase words of a text: letters and digits in any script, split at everything else. */
211
+ function words(text) {
212
+ return text.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean).map(singular);
213
+ }
214
+ /**
215
+ * Rank catalog APIs against a free-text query. An empty query lists them all.
216
+ *
217
+ * Query words match whole words (not parts of words, so "out" does not match
218
+ * "without"), and an API is kept only when every query word matches it
219
+ * somewhere, or one matches its slug, name or site. A query no API answers
220
+ * returns nothing, rather than every API that shares a word with it.
221
+ * `loose` keeps any API that matches one word: for "did you mean" hints.
222
+ */
223
+ export function searchApis(apis, query, opts = {}) {
202
224
  const q = (query ?? "").trim().toLowerCase();
203
225
  if (!q)
204
226
  return [...apis];
205
- const tokens = q.split(/\s+/).filter((t) => t.length > 1);
206
227
  const queryHost = hostOf(q);
228
+ const all = words(q).filter((t) => t.length > 1);
229
+ const meaningful = all.filter((t) => !STOP_WORDS.has(t));
230
+ const tokens = meaningful.length ? meaningful : all;
207
231
  const scored = apis.map((api) => {
208
232
  const slug = api.slug.toLowerCase();
209
- const name = api.name.toLowerCase();
233
+ const slugWords = new Set(words(slug));
210
234
  const host = hostOf(api.target_url) ?? "";
211
- const description = (api.description ?? "").toLowerCase();
235
+ const hostWords = new Set(words(host));
236
+ const nameWords = new Set(words(api.name));
237
+ const descriptionWords = new Set(words(api.description ?? ""));
212
238
  let score = queryHost && queryHost === host ? 20 : 0;
213
- for (const token of tokens.map(singular)) {
239
+ let matched = 0;
240
+ for (const token of tokens) {
241
+ let hit = 0;
214
242
  if (slug === token)
215
- score += 10;
216
- else if (slug.includes(token))
217
- score += 5;
218
- if (host.includes(token))
219
- score += 5;
220
- if (name.includes(token))
221
- score += 4;
222
- if (description.includes(token))
223
- score += 1;
243
+ hit += 10;
244
+ else if (slugWords.has(token) || (token.length >= 4 && slug.includes(token)))
245
+ hit += 5;
246
+ if (hostWords.has(token) || (token.length >= 4 && host.includes(token)))
247
+ hit += 5;
248
+ if (nameWords.has(token))
249
+ hit += 4;
250
+ if (descriptionWords.has(token))
251
+ hit += 1;
252
+ if (hit)
253
+ matched++;
254
+ score += hit;
224
255
  }
225
- return { api, score };
256
+ const kept = opts.loose || score >= STRONG_MATCH || (tokens.length > 0 && matched === tokens.length);
257
+ return { api, score: kept ? score : 0, matched };
226
258
  });
259
+ // An API that matches more of the query's words ranks first, then the higher score.
227
260
  return scored
228
261
  .filter((s) => s.score > 0)
229
- .sort((a, b) => b.score - a.score)
262
+ .sort((a, b) => b.matched - a.matched || b.score - a.score)
230
263
  .map((s) => s.api);
231
264
  }
232
265
  /** "hotels" -> "hotel", so a plural query still matches a singular description. Leaves "news" and "class" alone. */
@@ -259,15 +292,16 @@ export function describeParams(schema) {
259
292
  /**
260
293
  * Flatten a response schema into `path: type` lines (`data.items[].price:
261
294
  * number`), so an agent knows which fields come back without reading a full
262
- * JSON Schema document.
295
+ * JSON Schema document. Past `maxLines`, one last line says how many fields
296
+ * were left out.
263
297
  */
264
- export function outlineOutput(schema, maxLines = 40, maxDepth = 5) {
298
+ export function outlineOutput(schema, maxLines = OUTLINE_MAX_LINES, maxDepth = 5) {
265
299
  if (!schema)
266
300
  return [];
267
301
  const lines = [];
268
302
  const walk = (node, prefix, depth) => {
269
303
  for (const [key, child] of Object.entries(node.properties ?? {})) {
270
- if (lines.length >= maxLines)
304
+ if (lines.length > OUTLINE_HARD_CAP)
271
305
  return;
272
306
  const path = prefix ? `${prefix}.${key}` : key;
273
307
  if (child.properties && depth < maxDepth) {
@@ -282,10 +316,19 @@ export function outlineOutput(schema, maxLines = 40, maxDepth = 5) {
282
316
  }
283
317
  };
284
318
  walk(schema, "", 0);
285
- if (lines.length >= maxLines)
286
- lines.push("…");
287
- return lines;
319
+ if (lines.length <= maxLines)
320
+ return lines;
321
+ const left = lines.length - maxLines;
322
+ const more = lines.length > OUTLINE_HARD_CAP ? `${left}+` : String(left);
323
+ return [...lines.slice(0, maxLines), `… and ${more} more field${left === 1 ? "" : "s"}`];
288
324
  }
325
+ /**
326
+ * Response fields get_api lists per endpoint. Endpoints return a few dozen
327
+ * fields; a full list keeps an agent from guessing at the ones it cannot see.
328
+ */
329
+ export const OUTLINE_MAX_LINES = 200;
330
+ /** Stop walking a schema past this many fields. */
331
+ const OUTLINE_HARD_CAP = 1000;
289
332
  /** MCP tool names allow [A-Za-z0-9_-], up to 64 characters. */
290
333
  export function toolName(apiSlug, endpointSlug) {
291
334
  return `${apiSlug}_${endpointSlug}`.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64);
package/dist/config.js CHANGED
@@ -1,4 +1,4 @@
1
- export const VERSION = "0.2.2";
1
+ export const VERSION = "0.2.4";
2
2
  export const DEFAULT_BASE_URL = "https://api.maviapi.com";
3
3
  export const SITE_URL = "https://maviapi.com";
4
4
  /**
package/dist/requests.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { findEndpoint, truncate } from "./catalog.js";
2
2
  import { siteLink } from "./config.js";
3
- import { MAX_RESULT_CHARS, UserError, failure, humanDuration, objectArg, stringArg, text } from "./result.js";
3
+ import { UserError, failure, fitAnswer, humanDuration, objectArg, stringArg, text } from "./result.js";
4
4
  /**
5
5
  * The request tools: ask for an endpoint on an API that exists, follow its
6
6
  * build, try the draft, publish it, cancel it. They drive the same routes the
@@ -157,15 +157,15 @@ export const REQUEST_TOOLS = [
157
157
  name: "get_key_info",
158
158
  title: "Show this maviapi key",
159
159
  description: "What the configured API key may do: its permissions, the account's plan and remaining credits, and the limits that apply. " +
160
- "Check it before starting something that needs a permission or uses credits. Needs an API key with a request permission.",
160
+ "Check it before starting something that needs a permission or uses credits. Works with any API key of your own.",
161
161
  inputSchema: { type: "object", properties: {} },
162
162
  annotations: READ,
163
163
  },
164
164
  {
165
165
  name: "get_changelog",
166
166
  title: "Show a maviapi API's versions",
167
- description: "Every version of an API, newest first: which is live, when it was built, and what changed (endpoints added or removed, fields changed). " +
168
- "Use it when an endpoint behaves differently than before, or to pick a version for call_api's `version`.",
167
+ description: "What changed in an API, newest first: the date of each change, which one is live, and what it changed (endpoints added, fields changed, fixes). " +
168
+ "Use it when an endpoint behaves differently than before.",
169
169
  inputSchema: {
170
170
  type: "object",
171
171
  properties: {
@@ -224,6 +224,20 @@ export function describeDiff(diff) {
224
224
  }
225
225
  return parts.join("; ");
226
226
  }
227
+ /** One changelog entry as a line, with its listed changes under it. */
228
+ export function describeChange(e) {
229
+ const live = e.live ?? e.state === "active";
230
+ const tags = [live ? "live" : "", e.compat === "breaking" ? "breaking" : ""].filter(Boolean);
231
+ const when = (e.date ?? e.id ?? "").slice(0, 10);
232
+ const label = [when, typeof e.version === "number" ? `build ${e.version}` : ""].filter(Boolean).join(", ") || "undated";
233
+ const headline = e.title?.trim() || e.notes?.summary?.trim() || (e.hotfix_of ? `Repair of build ${e.hotfix_of}.` : describeDiff(e.diff)) || "No details.";
234
+ const out = [`- ${label}${tags.length ? ` (${tags.join(", ")})` : ""}: ${headline}`];
235
+ for (const change of (e.notes?.changes ?? []).slice(0, 8)) {
236
+ if (change.text)
237
+ out.push(` - ${change.kind ? `${change.kind}: ` : ""}${change.text}`);
238
+ }
239
+ return out;
240
+ }
227
241
  export class RequestTools {
228
242
  client;
229
243
  config;
@@ -574,11 +588,12 @@ export class RequestTools {
574
588
  filled[p.name] = p.example;
575
589
  }
576
590
  const result = await this.client.callDraft(status.draft.id, shortPath(endpoint.path, status.slug), filled);
591
+ if (result.ok) {
592
+ const asked = Number(filled.limit);
593
+ return fitAnswer(result.body, { asked: Number.isFinite(asked) ? asked : undefined });
594
+ }
577
595
  const body = typeof result.body === "string" ? result.body : JSON.stringify(result.body);
578
- const out = truncate(body, MAX_RESULT_CHARS, "pass a smaller limit, or page with offset");
579
- return result.ok
580
- ? text(out)
581
- : failure(`The draft answered ${result.status}: ${truncate(body, 2000)}`);
596
+ return failure(`The draft answered ${result.status}: ${truncate(body, 2000)}`);
582
597
  }
583
598
  async publish(args) {
584
599
  const id = stringArg(args, "request_id", true);
@@ -649,19 +664,13 @@ export class RequestTools {
649
664
  return failure(this.deps.describeFailure(result));
650
665
  const entries = (result.body.entries ?? []);
651
666
  if (!entries.length)
652
- return text(`${api.name} (${api.slug}) has no recorded versions yet.`);
653
- const lines = entries.slice(0, 30).map((e) => {
654
- const tags = [e.state === "active" ? "live" : e.state, e.compat === "breaking" ? "breaking" : ""]
655
- .filter(Boolean)
656
- .join(", ");
657
- const changes = e.hotfix_of ? `repair of v${e.hotfix_of}` : describeDiff(e.diff);
658
- return `- v${e.version} (${tags}${e.date ? `, ${e.date.slice(0, 10)}` : ""})${changes ? `: ${changes}` : ""}`;
659
- });
667
+ return text(`${api.name} (${api.slug}) has no recorded changes yet.`);
668
+ const lines = entries.slice(0, 30).flatMap(describeChange);
660
669
  return text([
661
- `${api.name} (${api.slug}) versions, newest first:`,
670
+ `${api.name} (${api.slug}) changes, newest first:`,
662
671
  ...lines,
663
672
  "",
664
- 'call_api serves the live version; pass "version": <n> to call another one that is still callable.',
673
+ "call_api always serves the live build.",
665
674
  ].join("\n"));
666
675
  }
667
676
  }
package/dist/result.js CHANGED
@@ -3,6 +3,94 @@ export const MAX_RESULT_CHARS = 50_000;
3
3
  /** A failure worth showing the agent verbatim: bad input, unknown names. */
4
4
  export class UserError extends Error {
5
5
  }
6
+ const META_KEY = "maviapi/truncation";
7
+ /** The path to the longest list in a JSON answer, two levels deep at most: where its rows are. */
8
+ function rowsPath(value, depth = 0) {
9
+ if (Array.isArray(value))
10
+ return [];
11
+ if (!value || typeof value !== "object" || depth > 1)
12
+ return null;
13
+ let best = null;
14
+ for (const [key, child] of Object.entries(value)) {
15
+ const sub = rowsPath(child, depth + 1);
16
+ if (!sub)
17
+ continue;
18
+ const size = JSON.stringify(child).length;
19
+ if (!best || size > best.size)
20
+ best = { path: [key, ...sub], size };
21
+ }
22
+ return best?.path ?? null;
23
+ }
24
+ function getAt(value, path) {
25
+ return path.reduce((node, key) => node[key], value);
26
+ }
27
+ /** A copy of `value` whose list at `path` keeps only its first `n` rows. */
28
+ function withRows(value, path, n) {
29
+ if (!path.length)
30
+ return value.slice(0, n);
31
+ const [key, ...rest] = path;
32
+ return { ...value, [key]: withRows(value[key], rest, n) };
33
+ }
34
+ /**
35
+ * An endpoint's answer as tool text, cut to `max` characters when it is
36
+ * longer. A JSON answer is cut at whole rows of its longest list, so what is
37
+ * left still parses; anything else is cut at `max` characters. The result
38
+ * says what was left out, and that the HTTP API itself never cuts.
39
+ */
40
+ export function fitAnswer(body, opts = {}) {
41
+ const max = opts.max ?? MAX_RESULT_CHARS;
42
+ const full = typeof body === "string" ? body : JSON.stringify(body);
43
+ if (full.length <= max)
44
+ return text(full);
45
+ const where = opts.url ? ` (${opts.url})` : "";
46
+ const http = `The HTTP API${where} does not cut answers.`;
47
+ let kept = null;
48
+ let truncation = null;
49
+ const path = typeof body === "string" ? null : rowsPath(body);
50
+ if (path) {
51
+ const rows = getAt(body, path);
52
+ // The most rows that still fit: whole rows only, so the JSON stays valid.
53
+ let lo = 0;
54
+ let hi = rows.length;
55
+ while (lo < hi) {
56
+ const mid = Math.ceil((lo + hi) / 2);
57
+ if (JSON.stringify(withRows(body, path, mid)).length <= max)
58
+ lo = mid;
59
+ else
60
+ hi = mid - 1;
61
+ }
62
+ const candidate = JSON.stringify(withRows(body, path, lo));
63
+ if (lo > 0 && candidate.length <= max) {
64
+ kept = candidate;
65
+ truncation = {
66
+ truncated: true,
67
+ rows_returned: lo,
68
+ rows_in_answer: rows.length,
69
+ ...(opts.asked !== undefined && { rows_asked: opts.asked }),
70
+ max_chars: max,
71
+ note: `This tool cut the answer to ${lo} of its ${rows.length} rows to stay under ${max.toLocaleString("en-US")} characters. ` +
72
+ `${http} Pass a smaller limit and page with offset to read the rest here.`,
73
+ };
74
+ }
75
+ }
76
+ if (!truncation) {
77
+ kept = full.slice(0, max);
78
+ truncation = {
79
+ truncated: true,
80
+ ...(opts.asked !== undefined && { rows_asked: opts.asked }),
81
+ max_chars: max,
82
+ note: `This tool cut the answer at ${max.toLocaleString("en-US")} of its ${full.length.toLocaleString("en-US")} characters, so the text above is incomplete. ` +
83
+ `${http} Pass a smaller limit and page with offset to read the rest here.`,
84
+ };
85
+ }
86
+ return {
87
+ content: [
88
+ { type: "text", text: kept ?? "" },
89
+ { type: "text", text: JSON.stringify(truncation) },
90
+ ],
91
+ _meta: { [META_KEY]: truncation },
92
+ };
93
+ }
6
94
  export function text(body) {
7
95
  return { content: [{ type: "text", text: body }] };
8
96
  }
package/dist/server.js CHANGED
@@ -3,11 +3,12 @@ import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprot
3
3
  import { MaviapiClient } from "./client.js";
4
4
  import { VERSION } from "./config.js";
5
5
  import { Toolset } from "./tools.js";
6
- const INSTRUCTIONS = `maviapi gives you live, structured JSON from websites that have no official API (travel, e-commerce, news, events, finance and more).
6
+ const INSTRUCTIONS = `maviapi is the unofficial API for any website: live, structured JSON from websites that have no official API (travel, e-commerce, news, events, finance and more).
7
7
  Workflow: search_apis to find an API for a site or topic, get_api to read its endpoints and parameters, then call_api to fetch data.
8
8
  If no API covers the site you need, create_api builds one (about half an hour; follow it with get_build_status).
9
9
  If an API exists but lacks an endpoint, or you need one to behave differently, request_endpoint adds one: preview it, let the user agree, start it with confirm: true, follow it with get_build_status (wait_seconds), try it with call_draft, and publish_request when the user wants it live.
10
10
  If an endpoint is simply broken (it fails, comes back empty, or repeats the same page), report_endpoint_issue with the params of the failing call: maviapi replays it and checks the endpoint itself. A fault its own check confirms is repaired in place; the rest are read by a person.
11
+ The request tools need a key of your own with permissions: request_endpoint, send_request_message, cancel_request and report_endpoint_issue need "Start and manage builds" (requests:write), list_requests and call_draft either permission, and publish_request "Publish builds" (requests:publish). Without them, the user publishes a finished build on its page in the dashboard (https://maviapi.com/dashboard/requests), and creates a key with permissions at https://maviapi.com/dashboard/keys. get_key_info shows what the configured key may do, its credits and its limits.
11
12
  Starting a build and publishing change things for the user: do them when the user asked, not on your own.`;
12
13
  /**
13
14
  * App directories (Claude's among them) read a tool's display name from
package/dist/tools.js CHANGED
@@ -1,7 +1,7 @@
1
- import { DEFAULT_LIMIT, MissingParamsError, describeParams, findApi, findEndpoint, hostOf, outlineOutput, searchApis, toolName, truncate, } from "./catalog.js";
1
+ import { DEFAULT_LIMIT, MissingParamsError, buildQuery, describeParams, fillPath, findApi, findEndpoint, hostOf, outlineOutput, searchApis, toolName, truncate, } from "./catalog.js";
2
2
  import { MaviapiError } from "./client.js";
3
3
  import { MAX_WAIT_SECONDS, REQUEST_TOOLS, RequestTools } from "./requests.js";
4
- import { MAX_RESULT_CHARS, UserError, failure, humanDuration, objectArg, stringArg, text } from "./result.js";
4
+ import { MAX_RESULT_CHARS, UserError, failure, fitAnswer, humanDuration, objectArg, stringArg, text } from "./result.js";
5
5
  export { humanDuration };
6
6
  import { PLAYGROUND_DAILY_LIMIT, PLAYGROUND_FREE_BUILDS, PLAYGROUND_RATE_LIMIT, siteLink, } from "./config.js";
7
7
  const READ_ONLY = { readOnlyHint: true, destructiveHint: false, idempotentHint: true };
@@ -41,7 +41,8 @@ const GENERIC_TOOLS = [
41
41
  title: "Call a maviapi endpoint",
42
42
  description: "Fetch live, structured JSON from a website through a maviapi endpoint. " +
43
43
  "`api` is the API slug (or domain), `endpoint` the endpoint name or path from get_api, and `params` its parameters, path parameters such as {id} included. " +
44
- `List endpoints return ${DEFAULT_LIMIT} results unless you pass \`limit\`; page with \`offset\`. Each successful call uses one maviapi credit.`,
44
+ `List endpoints return ${DEFAULT_LIMIT} results unless you pass \`limit\`; page with \`offset\`. Each successful call uses one maviapi credit. ` +
45
+ `An answer over ${MAX_RESULT_CHARS.toLocaleString("en-US")} characters is cut to whole rows here and flagged \`truncated\` (the HTTP API returns it in full).`,
45
46
  inputSchema: {
46
47
  type: "object",
47
48
  properties: {
@@ -54,7 +55,7 @@ const GENERIC_TOOLS = [
54
55
  },
55
56
  version: {
56
57
  type: "integer",
57
- description: "Call this version of the API instead of the live one (see get_changelog). Rarely needed.",
58
+ description: "Call this build of the API instead of the live one. Only the API's owner can pick a build; anyone else gets the live one. Rarely needed.",
58
59
  },
59
60
  },
60
61
  required: ["api", "endpoint"],
@@ -161,8 +162,9 @@ export class Toolset {
161
162
  const apis = await this.client.listApis();
162
163
  const hits = searchApis(apis, query);
163
164
  if (!hits.length) {
164
- return text(`No catalog API matches "${query}". ${apis.length} APIs are available: call search_apis with no query to list them all. ` +
165
- "If the site you need is missing, create_api can build an API for it.");
165
+ return text(`No maviapi API covers "${query}". None of the ${apis.length} APIs in the catalog is about it, so do not use an unrelated one instead. ` +
166
+ "If the query names a site, create_api can build an API for it. For a topic, try one plain word (e.g. \"hotels\"), " +
167
+ "or call search_apis with no query to list the whole catalog.");
166
168
  }
167
169
  const header = query ? `${hits.length} API(s) match "${query}":` : `${apis.length} APIs in the maviapi catalog:`;
168
170
  const lines = hits.map((api) => {
@@ -179,7 +181,7 @@ export class Toolset {
179
181
  const apis = await this.client.listApis();
180
182
  const api = findApi(apis, ref);
181
183
  if (!api) {
182
- const suggestions = searchApis(apis, ref).slice(0, 3).map((a) => a.slug);
184
+ const suggestions = searchApis(apis, ref, { loose: true }).slice(0, 3).map((a) => a.slug);
183
185
  throw new UserError(`No maviapi API named "${ref}".` +
184
186
  (suggestions.length ? ` Did you mean: ${suggestions.join(", ")}?` : " Use search_apis to find one.") +
185
187
  " If the site is not in the catalog, create_api can build one.");
@@ -217,7 +219,7 @@ export class Toolset {
217
219
  const params = describeParams(ep.inputSchema);
218
220
  out.push(params.length ? "Parameters:" : "Parameters: none");
219
221
  out.push(...params);
220
- const fields = outlineOutput(ep.outputSchema, 25);
222
+ const fields = outlineOutput(ep.outputSchema);
221
223
  if (fields.length)
222
224
  out.push("Returns:", ...fields.map((f) => ` ${f}`));
223
225
  }
@@ -246,7 +248,7 @@ export class Toolset {
246
248
  }
247
249
  const version = args.version === undefined || args.version === null ? undefined : Number(args.version);
248
250
  if (version !== undefined && (!Number.isInteger(version) || version < 1)) {
249
- throw new UserError("`version` must be a version number from get_changelog, e.g. 3.");
251
+ throw new UserError("`version` must be a build number of this API, e.g. 3. Leave it out to call the live build.");
250
252
  }
251
253
  return this.run(api.slug, endpoint, params, version);
252
254
  }
@@ -262,15 +264,20 @@ export class Toolset {
262
264
  const result = await this.client.call(slug, endpoint, params, version);
263
265
  if (!result.ok)
264
266
  return failure(this.describeFailure(result));
265
- const body = typeof result.body === "string" ? result.body : JSON.stringify(result.body);
266
- let out = truncate(body, MAX_RESULT_CHARS, "pass a smaller limit, or page with offset");
267
+ const asked = Number(params.limit);
268
+ const filled = fillPath(endpoint.path, params);
269
+ const answer = fitAnswer(result.body, {
270
+ asked: Number.isFinite(asked) ? asked : undefined,
271
+ url: `${this.config.baseUrl}/v1/sites/${encodeURIComponent(slug)}${filled.path}${buildQuery(filled.query)}`,
272
+ });
267
273
  if (this.config.usingPlaygroundKey && !this.nudged) {
268
274
  this.nudged = true;
269
- out +=
275
+ const first = answer.content[0];
276
+ first.text +=
270
277
  `\n\n(Served with maviapi's shared demo key, limited to ${PLAYGROUND_RATE_LIMIT} requests a minute. ` +
271
278
  `For a higher limit, create a free key at ${siteLink("/sign-up", "demo_key_notice")} and set MAVIAPI_API_KEY.)`;
272
279
  }
273
- return text(out);
280
+ return answer;
274
281
  }
275
282
  describeFailure({ status, body, retryAfter }) {
276
283
  const payload = (body && typeof body === "object" ? body : {});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maviapi/mcp",
3
- "version": "0.2.2",
4
- "description": "MCP server that gives AI agents live, structured JSON from websites with no official API (Booking.com, Airbnb, Tripadvisor, Kiwi.com, Hepsiburada and more), through self-repairing maviapi endpoints.",
3
+ "version": "0.2.4",
4
+ "description": "MCP server for maviapi, the unofficial API for any website: hosted, documented JSON APIs for sites with no official API, kept working when the site changes.",
5
5
  "mcpName": "io.github.kuzenlabs/maviapi-mcp",
6
6
  "type": "module",
7
7
  "bin": {