@maviapi/mcp 0.2.6 → 0.2.8

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/dist/catalog.js CHANGED
@@ -11,34 +11,67 @@
11
11
  const HIDDEN_PARAMS = new Set(["refresh"]);
12
12
  /** Results per page when an agent omits `limit`: endpoints default to 50, which floods a context window. */
13
13
  export const DEFAULT_LIMIT = 10;
14
- /** Path parameter names, in order. Accepts both `/items/{id}` and `/items/:id`. */
14
+ /**
15
+ * Path parameter names, in order. Accepts `/items/{id}`, `/items/:id`, and a
16
+ * `{param}` inside a segment (`/events/{city}-v2`): a live endpoint shipped
17
+ * before the manifest gate refused that shape, and a call that leaves the
18
+ * placeholder in the URL answers 502 (#1074).
19
+ */
15
20
  export function pathParams(path) {
16
- return path
17
- .split("/")
18
- .map(paramName)
19
- .filter((name) => name !== null);
21
+ return path.split("/").flatMap(segmentParams);
22
+ }
23
+ const BRACED = /\{([^{}/]+)\}/g;
24
+ function segmentParams(segment) {
25
+ if (segment.startsWith(":") && segment.length > 1)
26
+ return [segment.slice(1)];
27
+ return [...segment.matchAll(BRACED)].map((m) => m[1]);
20
28
  }
29
+ /** The one parameter a segment is, or null when it is a literal or has text beside it. */
21
30
  function paramName(segment) {
22
31
  if (segment.startsWith(":") && segment.length > 1)
23
32
  return segment.slice(1);
24
- if (segment.startsWith("{") && segment.endsWith("}") && segment.length > 2) {
25
- return segment.slice(1, -1);
26
- }
27
- return null;
33
+ const m = /^\{([^{}/]+)\}$/.exec(segment);
34
+ return m ? m[1] : null;
28
35
  }
29
36
  /**
30
- * A readable endpoint name. Catalog slugs are inconsistent: some are a bare
31
- * word ("hotel" for /hotel/{country}/{slug}), others the route itself
32
- * ("listing/:id"). Static segments are kept and parameters become a `_by_`
33
- * suffix, so /templates and /templates/:id stay distinct.
37
+ * The name older clients knew, derived from the catalog slug: some slugs are a
38
+ * bare word ("hotel" for /hotel/{country}/{slug}), others the route itself
39
+ * ("listing/:id"). Kept only so a name an agent saved still resolves.
34
40
  */
35
- export function endpointName(slug) {
41
+ export function slugName(slug) {
36
42
  const parts = slug.split("/").filter(Boolean);
37
43
  const words = parts.filter((p) => paramName(p) === null);
38
44
  const params = parts.map(paramName).filter((p) => p !== null);
39
45
  const base = words.join("-") || "root";
40
46
  return params.length ? `${base}_by_${params.join("_and_")}` : base;
41
47
  }
48
+ /**
49
+ * The endpoint's name, from its PATH (#1090), the same rule as the backend's
50
+ * backend/worker/src/endpoint-name.ts (the catalog sends it as `name`; this is
51
+ * the fallback). Literal segments are kept, params become a `_by_` suffix:
52
+ * "/events-v2/{city}" is "events-v2_by_city". A param glued to text keeps the
53
+ * text without braces: "/events/{city}-v2" is "events-city-v2_by_city".
54
+ */
55
+ export function endpointName(path, method = "GET") {
56
+ const words = [];
57
+ const params = [];
58
+ for (const seg of (path.split("?")[0] ?? "").split("/").filter(Boolean)) {
59
+ const whole = /^\{(\w+)\}$/.exec(seg) ?? /^:(\w+)$/.exec(seg);
60
+ if (whole) {
61
+ params.push(whole[1]);
62
+ continue;
63
+ }
64
+ for (const m of seg.matchAll(/\{(\w+)\}/g))
65
+ params.push(m[1]);
66
+ const text = seg.replace(/[{}]/g, "").replace(/[^A-Za-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "");
67
+ if (text)
68
+ words.push(text.toLowerCase());
69
+ }
70
+ const base = words.join("-") || "root";
71
+ const name = params.length ? `${base}_by_${params.join("_and_")}` : base;
72
+ const verb = method.toUpperCase();
73
+ return verb === "GET" || verb === "HEAD" ? name : `${verb.toLowerCase()}-${name}`;
74
+ }
42
75
  export class MissingParamsError extends Error {
43
76
  missing;
44
77
  constructor(missing) {
@@ -53,17 +86,19 @@ export class MissingParamsError extends Error {
53
86
  export function fillPath(path, params) {
54
87
  const query = { ...params };
55
88
  const missing = [];
56
- const segments = path.split("/").map((segment) => {
57
- const name = paramName(segment);
58
- if (name === null)
59
- return segment;
89
+ const fill = (name, whole) => {
60
90
  const value = query[name];
61
91
  delete query[name];
62
92
  if (value === undefined || value === null || value === "") {
63
93
  missing.push(name);
64
- return segment;
94
+ return whole;
65
95
  }
66
96
  return encodeURIComponent(String(value));
97
+ };
98
+ const segments = path.split("/").map((segment) => {
99
+ if (segment.startsWith(":") && segment.length > 1)
100
+ return fill(segment.slice(1), segment);
101
+ return segment.replace(BRACED, (whole, name) => fill(name, whole));
67
102
  });
68
103
  if (missing.length)
69
104
  throw new MissingParamsError(missing);
@@ -157,7 +192,8 @@ export function normalizeEndpoint(raw) {
157
192
  if (required.length)
158
193
  inputSchema.required = required;
159
194
  return {
160
- name: endpointName(raw.slug),
195
+ name: raw.name || endpointName(raw.path, raw.method),
196
+ legacyName: slugName(raw.slug),
161
197
  slug: raw.slug,
162
198
  path: raw.path,
163
199
  method: raw.method.toUpperCase(),
@@ -190,12 +226,13 @@ export function findApi(apis, ref) {
190
226
  apis.find((a) => a.name.toLowerCase() === r) ??
191
227
  (host ? apis.find((a) => hostOf(a.target_url) === host) : undefined));
192
228
  }
193
- /** Resolve an endpoint by name, catalog slug, or path (leading slash optional). */
229
+ /** Resolve an endpoint by name, path (leading slash optional), catalog slug, or a name older clients knew. */
194
230
  export function findEndpoint(endpoints, ref) {
195
231
  const r = ref.trim().toLowerCase().replace(/^\/+/, "");
196
232
  return (endpoints.find((e) => e.name.toLowerCase() === r) ??
233
+ endpoints.find((e) => e.path.toLowerCase().replace(/^\/+/, "") === r) ??
197
234
  endpoints.find((e) => e.slug.toLowerCase() === r) ??
198
- endpoints.find((e) => e.path.toLowerCase().replace(/^\/+/, "") === r));
235
+ endpoints.find((e) => e.legacyName.toLowerCase() === r));
199
236
  }
200
237
  /** Query words that say nothing about which API is meant. */
201
238
  const STOP_WORDS = new Set([
package/dist/config.js CHANGED
@@ -1,4 +1,4 @@
1
- export const VERSION = "0.2.6";
1
+ export const VERSION = "0.2.8";
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
@@ -149,6 +149,10 @@ export const REQUEST_TOOLS = [
149
149
  description: 'The parameters of a call that shows the fault, e.g. {"geo": "187147", "page": 2}.',
150
150
  additionalProperties: true,
151
151
  },
152
+ request_id: {
153
+ type: "string",
154
+ description: "Optional: the x-request-id header of the failed call, so the team can find that exact call in its logs.",
155
+ },
152
156
  },
153
157
  },
154
158
  annotations: WRITE,
@@ -183,6 +187,13 @@ function describeReport(report) {
183
187
  return report.message;
184
188
  return `status ${String(report.status ?? "unknown")}`;
185
189
  }
190
+ /** "The build stopped at the build step (build_failed): <message>." with the code, message and step the backend gives. */
191
+ export function stoppedLine(s) {
192
+ const step = s.failure?.step;
193
+ const code = s.failure?.code ?? s.resultCode;
194
+ const message = (s.failure?.message ?? s.error ?? "no reason given").trim();
195
+ return `The build stopped${step ? ` at the ${step} step` : ""}${code ? ` (${code})` : ""}: ${message}${/[.!?]$/.test(message) ? "" : "."}`;
196
+ }
186
197
  const RUNNING = new Set(["queued", "reading", "mapping", "building", "testing"]);
187
198
  /** Phases that change on their own, so waiting on them is worth it. */
188
199
  const MOVING = new Set([...RUNNING, "publishing"]);
@@ -400,10 +411,12 @@ export class RequestTools {
400
411
  throw new UserError(`${api.slug} has no endpoint "${endpointArg}". Its endpoints: ${endpoints.map((e) => e.path).join(", ")}.`);
401
412
  }
402
413
  const params = objectArg(args, "params");
414
+ const requestId = typeof args.request_id === "string" ? args.request_id.trim() : "";
403
415
  const result = await this.client.reportEndpoint(api.slug, {
404
416
  path: endpoint.path,
405
417
  description,
406
418
  ...(Object.keys(params).length > 0 && { params }),
419
+ ...(requestId && { request_id: requestId }),
407
420
  });
408
421
  const body = payloadOf(result);
409
422
  if (!result.ok) {
@@ -531,7 +544,7 @@ export class RequestTools {
531
544
  out.push(`Live${s.live ? ` as ${s.live.version} at ${s.live.baseUrl}` : ""}. get_api "${s.slug}" shows it and call_api calls it.`);
532
545
  }
533
546
  else if (s.phase === "failed") {
534
- out.push(`The build stopped: ${s.error ?? "no reason given"}. ` +
547
+ out.push(`${stoppedLine(s)} ` +
535
548
  'send_request_message "try again" builds it again; a narrower description may build where this did not.');
536
549
  }
537
550
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maviapi/mcp",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
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",