@usemcpkit/core 0.10.0 → 0.11.1

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
@@ -170,6 +170,10 @@ trust: its `cli` buttons name the programs usemcpkit runs when you click them.
170
170
 
171
171
  The domain comes from the env var, else `config.json`, else `default`. The form shows it prefilled and lets the
172
172
  user change it (`host[:port][/path]`, no scheme), unless the env var is set.
173
+ `suggestedHosts` lists hosts the field offers after the saved ones (n8n offers `app.n8n.cloud` and `localhost:5678`);
174
+ offering one does not pick it. With `loopbackHttp: true`, a `localhost` or `127.0.0.1` domain is reached over
175
+ `http://` in `baseUrl`, the upstream and OAuth URLs and `{domain}` links; every other server stays on `https://`, even on
176
+ localhost.
173
177
 
174
178
  **OAuth 2.0 with PKCE.** The user signs in once in the browser against the provider directly:
175
179
 
@@ -56,6 +56,8 @@ export declare interface CredentialRequest {
56
56
  domain?: DomainField;
57
57
  /** The domain in use when the form opened; the form's own domain field wins when it has one. */
58
58
  domainInUse?: string;
59
+ /** Links to a `localhost` or `127.0.0.1` domain open over `http://` (the manifest's `domain.loopbackHttp`). */
60
+ loopbackHttp?: boolean;
59
61
  options: readonly CredentialOption[];
60
62
  /** Whether the server offers an OAuth2 browser sign-in. */
61
63
  signIn: boolean;
@@ -96,6 +98,8 @@ export declare interface DomainField {
96
98
  value: string;
97
99
  /** Hosts already used with this server, offered for picking; the user can still type a new one. */
98
100
  knownHosts: readonly string[];
101
+ /** Hosts the server suggests (`domain.suggestedHosts`), offered after the known ones; none is picked for the user. */
102
+ suggestedHosts?: readonly string[];
99
103
  }
100
104
 
101
105
  /** Lets one server talk to any host of the same API, for example a self-hosted GitHub Enterprise. */
@@ -110,6 +114,10 @@ export declare interface DomainSpec {
110
114
  env?: string;
111
115
  /** Picks the saved host the git remote of the working directory points at, so a repository needs no question. */
112
116
  matchGitRemote?: boolean;
117
+ /** Hosts the domain field offers besides the saved ones; offering one does not pick it. */
118
+ suggestedHosts?: readonly string[];
119
+ /** Reaches a `localhost` or `127.0.0.1` domain over `http://`, for servers that usually run locally without TLS. */
120
+ loopbackHttp?: boolean;
113
121
  }
114
122
 
115
123
  /** A deployment of the same API that needs other requests, for example Atlassian Cloud next to Data Center. */
@@ -311,8 +319,8 @@ declare interface RequestSpec {
311
319
  fixedBody?: FixedValues;
312
320
  }
313
321
 
314
- /** Undefined while the link needs a domain and there is none yet. */
315
- export declare const resolveLinkUrl: (url: string, domain: string | undefined) => string | undefined;
322
+ /** Undefined while the link needs a domain and there is none yet; with `loopbackHttp` a link to a loopback domain opens over `http://`. */
323
+ export declare const resolveLinkUrl: (url: string, domain: string | undefined, loopbackHttp: boolean) => string | undefined;
316
324
 
317
325
  export declare interface ResponseSpec {
318
326
  root?: string;
@@ -55,19 +55,46 @@ var SERVER_NAME_PATTERN = /^[a-z][a-z0-9_]*$/;
55
55
  /** `resource:action`, for example `pull_request:list`; the action part is optional. */
56
56
  var TOOL_NAME_PATTERN = /^[a-z][a-z0-9_]*(:[a-z][a-z0-9_]*)*$/;
57
57
  var DOMAIN_PLACEHOLDER = "{domain}";
58
+ /** Hosts a `domain.loopbackHttp` server reaches over `http://`. */
59
+ var LOOPBACK_HOSTS = ["localhost", "127.0.0.1"];
60
+ var HTTPS_PREFIX = "https://";
61
+ var HTTP_PREFIX = "http://";
58
62
  /** A host with an optional port and path, for example `ghe.example.com/api/v3`. */
59
63
  var DOMAIN_VALUE_PATTERN = /^[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:\d{1,5})?(\/[a-z0-9._~-]+)*$/i;
60
64
  //#endregion
61
65
  //#region src/manifest/domain/fill-domain.ts
62
66
  var fillDomain = (template, domain) => template.replaceAll(DOMAIN_PLACEHOLDER, domain);
63
67
  //#endregion
68
+ //#region src/manifest/domain/to-domain-host.ts
69
+ /** The lowercase host of a domain value: what comes before its path and port. */
70
+ var toDomainHost = (domain) => (domain.split("/")[0] ?? "").split(":")[0]?.toLowerCase() ?? "";
71
+ //#endregion
72
+ //#region src/manifest/domain/to-loopback-http-url.ts
73
+ /**
74
+ * `https://localhost:5678/api/v1` → `http://localhost:5678/api/v1` when the URL points at `domain` and that domain is
75
+ * a loopback host; any other URL is returned as is.
76
+ */
77
+ var toLoopbackHttpUrl = (url, domain) => {
78
+ const host = toDomainHost(domain);
79
+ if (!LOOPBACK_HOSTS.includes(host) || !url.startsWith("https://")) return url;
80
+ const rest = url.slice(HTTPS_PREFIX.length);
81
+ return toDomainHost(rest) === host ? `${HTTP_PREFIX}${rest}` : url;
82
+ };
83
+ //#endregion
84
+ //#region src/manifest/domain/fill-domain-url.ts
85
+ /** A URL template with `{domain}` filled in, over `http://` for a loopback domain when the server allows it (`domain.loopbackHttp`). */
86
+ var fillDomainUrl = (template, domain, loopbackHttp) => {
87
+ const url = fillDomain(template, domain);
88
+ return loopbackHttp ? toLoopbackHttpUrl(url, domain) : url;
89
+ };
90
+ //#endregion
64
91
  //#region src/manifest/domain/apply-auth-domain.ts
65
- var applyAuthDomain = (auth, domain) => {
92
+ var applyAuthDomain = (auth, domain, loopbackHttp) => {
66
93
  if (auth.type !== "oauth") return auth;
67
94
  return {
68
95
  ...auth,
69
- authorizationUrl: fillDomain(auth.authorizationUrl, domain),
70
- tokenUrl: fillDomain(auth.tokenUrl, domain)
96
+ authorizationUrl: fillDomainUrl(auth.authorizationUrl, domain, loopbackHttp),
97
+ tokenUrl: fillDomainUrl(auth.tokenUrl, domain, loopbackHttp)
71
98
  };
72
99
  };
73
100
  //#endregion
@@ -84,7 +111,7 @@ var applyToolEdition = (tool, editionName) => {
84
111
  //#endregion
85
112
  //#region src/manifest/domain/find-edition.ts
86
113
  var findEdition = (editions, domain) => {
87
- const host = (domain.split("/")[0] ?? "").split(":")[0]?.toLowerCase() ?? "";
114
+ const host = toDomainHost(domain);
88
115
  return Object.entries(editions ?? {}).find(([, edition]) => edition.hosts.some((suffix) => host.endsWith(suffix.toLowerCase())))?.[0];
89
116
  };
90
117
  //#endregion
@@ -92,15 +119,16 @@ var findEdition = (editions, domain) => {
92
119
  /** A copy of the manifest with `{domain}` filled in and each tool set to the domain's edition; without a domain the manifest is returned as is. */
93
120
  var applyDomain = (manifest, domain) => {
94
121
  if (domain === void 0) return manifest;
122
+ const loopbackHttp = manifest.domain?.loopbackHttp === true;
95
123
  const editionName = findEdition(manifest.editions, domain);
96
124
  return {
97
125
  ...manifest,
98
- baseUrl: fillDomain(manifest.baseUrl, domain),
126
+ baseUrl: fillDomainUrl(manifest.baseUrl, domain, loopbackHttp),
99
127
  upstream: manifest.upstream?.type === "http" ? {
100
128
  ...manifest.upstream,
101
- url: fillDomain(manifest.upstream.url, domain)
129
+ url: fillDomainUrl(manifest.upstream.url, domain, loopbackHttp)
102
130
  } : manifest.upstream,
103
- auth: manifest.auth?.map((auth) => applyAuthDomain(auth, domain)),
131
+ auth: manifest.auth?.map((auth) => applyAuthDomain(auth, domain, loopbackHttp)),
104
132
  tools: manifest.tools.map((tool) => applyToolEdition(tool, editionName))
105
133
  };
106
134
  };
@@ -187,13 +215,14 @@ var toWebHost = (domain) => {
187
215
  };
188
216
  //#endregion
189
217
  //#region src/credentials-form/resolve-link-url.ts
190
- /** Undefined while the link needs a domain and there is none yet. */
191
- var resolveLinkUrl = (url, domain) => {
218
+ /** Undefined while the link needs a domain and there is none yet; with `loopbackHttp` a link to a loopback domain opens over `http://`. */
219
+ var resolveLinkUrl = (url, domain, loopbackHttp) => {
192
220
  if (readPlaceholders(url).some((name) => UI_DOMAIN_PLACEHOLDERS.includes(name)) && !domain) return;
193
- return fillTemplate(url, {
221
+ const filled = fillTemplate(url, {
194
222
  domain: domain ?? "",
195
223
  webHost: domain ? toWebHost(domain) : ""
196
224
  });
225
+ return domain && loopbackHttp ? toLoopbackHttpUrl(filled, domain) : filled;
197
226
  };
198
227
  //#endregion
199
228
  //#region src/errors/describe-error.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usemcpkit/core",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "The usemcpkit manifest format: types, the server SDK and the credentials form contract.",
5
5
  "repository": {
6
6
  "type": "git",