@maviapi/mcp 0.2.5 → 0.2.7

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
@@ -102,7 +102,7 @@ Leave out `env` to try it with the demo key.
102
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. |
103
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`. |
104
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. |
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. |
105
+ | `request_endpoint` | Add one endpoint to an API that exists, or a change to one (it ships beside the old one, e.g. `/search-v2`). Previews first; `confirm: true` starts the build. |
106
106
  | `list_requests` | Your API and endpoint requests, with their status. |
107
107
  | `send_request_message` | Tell a build something in plain words: add detail, fix or drop a failed endpoint, try again. |
108
108
  | `call_draft` | Call an endpoint of a draft before it is published. Costs no credits. |
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/client.js CHANGED
@@ -52,10 +52,10 @@ export class MaviapiClient {
52
52
  getBuild(id) {
53
53
  return this.send("GET", `/v1/requests/${encodeURIComponent(id)}`);
54
54
  }
55
- /** Call one endpoint through the maviapi gateway, on the live build or on `version`. */
56
- async call(slug, endpoint, params, version) {
55
+ /** Call one endpoint through the maviapi gateway, on the live build. */
56
+ async call(slug, endpoint, params) {
57
57
  const { path, query } = fillPath(endpoint.path, params);
58
- return this.send(endpoint.method, `/v1/sites/${encodeURIComponent(slug)}${path}${buildQuery(query)}`, undefined, version === undefined ? {} : { "x-maviapi-version": String(version) });
58
+ return this.send(endpoint.method, `/v1/sites/${encodeURIComponent(slug)}${path}${buildQuery(query)}`);
59
59
  }
60
60
  /** Drop what is cached about one API, after a request changed it. */
61
61
  invalidateApi(slug) {
package/dist/config.js CHANGED
@@ -1,4 +1,4 @@
1
- export const VERSION = "0.2.5";
1
+ export const VERSION = "0.2.7";
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
@@ -20,7 +20,7 @@ export const REQUEST_TOOLS = [
20
20
  {
21
21
  name: "request_endpoint",
22
22
  title: "Ask for a new maviapi endpoint",
23
- description: "Add one endpoint to an API that already exists, or a changed version of one of its endpoints. " +
23
+ description: "Add one endpoint to an API that already exists, or a change to one of its endpoints. " +
24
24
  "Use it when get_api shows the API lacks the data, or an endpoint returns the wrong thing. " +
25
25
  "Existing endpoints never change: a change ships as a new endpoint beside the old one (e.g. /search-v2). " +
26
26
  "Without `confirm` nothing is built: the tool answers with the endpoint as it would be built, for the user to agree to. " +
@@ -42,7 +42,7 @@ export const REQUEST_TOOLS = [
42
42
  },
43
43
  change: {
44
44
  type: "string",
45
- description: 'For a changed version of an existing endpoint: that endpoint\'s name or path, e.g. "/search". Use instead of `path`.',
45
+ description: 'For a change to an existing endpoint: that endpoint\'s name or path, e.g. "/search". Use instead of `path`.',
46
46
  },
47
47
  confirm: { type: "boolean", description: "true starts the build. Leave it out to preview first." },
48
48
  },
@@ -128,7 +128,7 @@ export const REQUEST_TOOLS = [
128
128
  name: "report_endpoint_issue",
129
129
  title: "Report a broken maviapi endpoint",
130
130
  description: "Tell maviapi that an endpoint that exists returns the wrong thing: it fails, comes back empty, or repeats the same page. " +
131
- "Use this instead of asking for a changed version when the endpoint is simply broken: the fix lands on the endpoint itself, for everyone. " +
131
+ "Use this instead of asking for a change when the endpoint is simply broken: the fix lands on the endpoint itself, for everyone. " +
132
132
  "maviapi replays the call at once and then runs its own check of the endpoint. If that check fails too the report is confirmed and the endpoint is queued for repair; " +
133
133
  "if not (a fault only certain parameters show, a repeated page, wrong values) a person on the team reads the report. " +
134
134
  "A report's status is confirmed, fixed or received. " +
@@ -163,7 +163,7 @@ export const REQUEST_TOOLS = [
163
163
  },
164
164
  {
165
165
  name: "get_changelog",
166
- title: "Show a maviapi API's versions",
166
+ title: "Show what changed in a maviapi API",
167
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
168
  "Use it when an endpoint behaves differently than before.",
169
169
  inputSchema: {
@@ -320,7 +320,7 @@ export class RequestTools {
320
320
  const path = stringArg(args, "path");
321
321
  const change = stringArg(args, "change");
322
322
  if (!path && !change) {
323
- throw new UserError('Pass `path` for a new endpoint (e.g. "/reviews"), or `change` with an existing endpoint to get a changed version of it.');
323
+ throw new UserError('Pass `path` for a new endpoint (e.g. "/reviews"), or `change` with an existing endpoint to get a change to it.');
324
324
  }
325
325
  if (path && change)
326
326
  throw new UserError("Pass `path` or `change`, not both.");
@@ -355,7 +355,7 @@ export class RequestTools {
355
355
  const endpoint = (body.endpoint ?? {});
356
356
  const out = [
357
357
  `Nothing has been built yet. This would add to ${api.name} (${api.slug}):`,
358
- ` GET ${endpoint.path}${endpoint.of ? ` (a changed version of GET ${endpoint.of}, which stays as it is)` : ""}`,
358
+ ` GET ${endpoint.path}${endpoint.of ? ` (a change to GET ${endpoint.of}, which stays as it is)` : ""}`,
359
359
  ` ${endpoint.summary}`,
360
360
  "",
361
361
  "Show this to the user. If they agree, call request_endpoint again with the same arguments and confirm: true.",
@@ -425,7 +425,7 @@ export class RequestTools {
425
425
  ? "Nothing more to do: the endpoint keeps its path, so the same call works once it is repaired. " +
426
426
  "get_api shows the endpoint's health; report_endpoint_issue with no arguments shows where this report stands."
427
427
  : "If the fault only shows with certain parameters, they are in the report for the person who reads it. " +
428
- "If you need different behavior rather than a fix, request_endpoint with `change` builds a new version beside this one.",
428
+ "If you need different behavior rather than a fix, request_endpoint with `change` builds the change beside this one.",
429
429
  ].join("\n"));
430
430
  }
431
431
  async listReports() {
package/dist/tools.js CHANGED
@@ -53,10 +53,6 @@ const GENERIC_TOOLS = [
53
53
  description: "Endpoint parameters, as listed by get_api.",
54
54
  additionalProperties: true,
55
55
  },
56
- version: {
57
- type: "integer",
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.",
59
- },
60
56
  },
61
57
  required: ["api", "endpoint"],
62
58
  },
@@ -243,14 +239,10 @@ export class Toolset {
243
239
  throw new UserError(`${api.slug} has no endpoint "${ref}". Available: ${endpoints.map((e) => e.name).join(", ")}. ` +
244
240
  `get_api "${api.slug}" lists their parameters.`);
245
241
  }
246
- const version = args.version === undefined || args.version === null ? undefined : Number(args.version);
247
- if (version !== undefined && (!Number.isInteger(version) || version < 1)) {
248
- throw new UserError("`version` must be a build number of this API, e.g. 3. Leave it out to call the live build.");
249
- }
250
- return this.run(api.slug, endpoint, params, version);
242
+ return this.run(api.slug, endpoint, params);
251
243
  }
252
244
  /** Call an endpoint and turn the outcome into something an agent can act on. */
253
- async run(slug, endpoint, input, version) {
245
+ async run(slug, endpoint, input) {
254
246
  const params = { ...input };
255
247
  if ("limit" in endpoint.inputSchema.properties && params.limit === undefined) {
256
248
  params.limit = DEFAULT_LIMIT;
@@ -258,7 +250,7 @@ export class Toolset {
258
250
  const missing = (endpoint.inputSchema.required ?? []).filter((name) => params[name] === undefined || params[name] === null || params[name] === "");
259
251
  if (missing.length)
260
252
  throw new MissingParamsError(missing);
261
- const result = await this.client.call(slug, endpoint, params, version);
253
+ const result = await this.client.call(slug, endpoint, params);
262
254
  if (!result.ok)
263
255
  return failure(this.describeFailure(result));
264
256
  const asked = Number(params.limit);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maviapi/mcp",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
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",