@evantahler/mcpx 0.18.3 → 0.18.6

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.
Files changed (53) hide show
  1. package/package.json +63 -63
  2. package/src/cli.ts +46 -54
  3. package/src/client/browser.ts +36 -15
  4. package/src/client/debug-fetch.ts +64 -56
  5. package/src/client/elicitation.ts +279 -291
  6. package/src/client/http.ts +1 -1
  7. package/src/client/manager.ts +481 -514
  8. package/src/client/oauth.ts +272 -282
  9. package/src/client/sse.ts +1 -1
  10. package/src/client/stdio.ts +7 -7
  11. package/src/client/trace.ts +146 -152
  12. package/src/client/transport-options.ts +20 -20
  13. package/src/commands/add.ts +160 -165
  14. package/src/commands/allow.ts +141 -142
  15. package/src/commands/auth.ts +86 -90
  16. package/src/commands/check-update.ts +49 -53
  17. package/src/commands/deny.ts +114 -117
  18. package/src/commands/exec.ts +218 -222
  19. package/src/commands/index.ts +41 -41
  20. package/src/commands/info.ts +48 -50
  21. package/src/commands/list.ts +49 -49
  22. package/src/commands/ping.ts +47 -50
  23. package/src/commands/prompt.ts +40 -50
  24. package/src/commands/remove.ts +54 -56
  25. package/src/commands/resource.ts +31 -36
  26. package/src/commands/search.ts +35 -39
  27. package/src/commands/servers.ts +44 -48
  28. package/src/commands/skill.ts +89 -95
  29. package/src/commands/task.ts +50 -60
  30. package/src/commands/upgrade.ts +191 -208
  31. package/src/commands/with-command.ts +27 -29
  32. package/src/config/env.ts +26 -28
  33. package/src/config/loader.ts +103 -103
  34. package/src/config/schemas.ts +78 -87
  35. package/src/constants.ts +17 -17
  36. package/src/context.ts +51 -51
  37. package/src/lib/client-settings.ts +127 -140
  38. package/src/lib/input.ts +23 -26
  39. package/src/output/format-output.ts +12 -16
  40. package/src/output/format-table.ts +39 -42
  41. package/src/output/formatter.ts +794 -815
  42. package/src/output/logger.ts +140 -152
  43. package/src/sdk.ts +283 -291
  44. package/src/search/index.ts +50 -54
  45. package/src/search/indexer.ts +65 -65
  46. package/src/search/keyword.ts +54 -54
  47. package/src/search/semantic.ts +39 -39
  48. package/src/search/staleness.ts +3 -3
  49. package/src/search/types.ts +4 -4
  50. package/src/update/background.ts +51 -51
  51. package/src/update/cache.ts +21 -21
  52. package/src/update/checker.ts +81 -86
  53. package/src/validation/schema.ts +53 -58
@@ -1,23 +1,23 @@
1
- import { yellow, cyan, dim } from "ansis";
1
+ import { cyan, dim, yellow } from "ansis";
2
2
  import pkg from "../../package.json";
3
- import { ENV, DEFAULTS } from "../constants.ts";
4
- import { checkForUpdate, needsCheck, type UpdateCache } from "./checker.ts";
3
+ import { DEFAULTS, ENV } from "../constants.ts";
5
4
  import { loadUpdateCache, saveUpdateCache } from "./cache.ts";
5
+ import { checkForUpdate, needsCheck, type UpdateCache } from "./checker.ts";
6
6
 
7
7
  /** Format an update notice for stderr output. */
8
8
  function formatNotice(currentVersion: string, latestVersion: string, changelog?: string): string {
9
- const lines: string[] = ["", yellow(`Update available: ${currentVersion} → ${latestVersion}`)];
9
+ const lines: string[] = ["", yellow(`Update available: ${currentVersion} → ${latestVersion}`)];
10
10
 
11
- if (changelog) {
12
- lines.push("");
13
- lines.push(dim(changelog));
14
- }
11
+ if (changelog) {
12
+ lines.push("");
13
+ lines.push(dim(changelog));
14
+ }
15
15
 
16
- lines.push("");
17
- lines.push(cyan(`Run \`mcpx upgrade\` to update`));
18
- lines.push("");
16
+ lines.push("");
17
+ lines.push(cyan(`Run \`mcpx upgrade\` to update`));
18
+ lines.push("");
19
19
 
20
- return lines.join("\n");
20
+ return lines.join("\n");
21
21
  }
22
22
 
23
23
  /**
@@ -25,52 +25,52 @@ function formatNotice(currentVersion: string, latestVersion: string, changelog?:
25
25
  * if an update is available, or null otherwise. Never throws.
26
26
  */
27
27
  export async function maybeCheckForUpdate(): Promise<string | null> {
28
- try {
29
- // Opt-out via env var
30
- if (process.env[ENV.NO_UPDATE_CHECK] === "1") return null;
28
+ try {
29
+ // Opt-out via env var
30
+ if (process.env[ENV.NO_UPDATE_CHECK] === "1") return null;
31
31
 
32
- // Skip if this is the check-update or upgrade command
33
- const args = process.argv.slice(2);
34
- const command = args.find((a) => !a.startsWith("-"));
35
- if (command === "check-update" || command === "upgrade") return null;
32
+ // Skip if this is the check-update or upgrade command
33
+ const args = process.argv.slice(2);
34
+ const command = args.find((a) => !a.startsWith("-"));
35
+ if (command === "check-update" || command === "upgrade") return null;
36
36
 
37
- // Only show in TTY
38
- if (!(process.stderr.isTTY ?? false)) return null;
37
+ // Only show in TTY
38
+ if (!(process.stderr.isTTY ?? false)) return null;
39
39
 
40
- const cache = await loadUpdateCache();
40
+ const cache = await loadUpdateCache();
41
41
 
42
- if (!needsCheck(cache)) {
43
- // Cache is fresh — use cached result
44
- if (cache?.hasUpdate) {
45
- return formatNotice(pkg.version, cache.latestVersion, cache.changelog);
46
- }
47
- return null;
48
- }
42
+ if (!needsCheck(cache)) {
43
+ // Cache is fresh — use cached result
44
+ if (cache?.hasUpdate) {
45
+ return formatNotice(pkg.version, cache.latestVersion, cache.changelog);
46
+ }
47
+ return null;
48
+ }
49
49
 
50
- // Cache is stale or missing — check with timeout
51
- const controller = new AbortController();
52
- const timeout = setTimeout(() => controller.abort(), DEFAULTS.UPDATE_CHECK_TIMEOUT_MS);
50
+ // Cache is stale or missing — check with timeout
51
+ const controller = new AbortController();
52
+ const timeout = setTimeout(() => controller.abort(), DEFAULTS.UPDATE_CHECK_TIMEOUT_MS);
53
53
 
54
- try {
55
- const info = await checkForUpdate(pkg.version, controller.signal);
54
+ try {
55
+ const info = await checkForUpdate(pkg.version, controller.signal);
56
56
 
57
- const newCache: UpdateCache = {
58
- lastCheckAt: new Date().toISOString(),
59
- latestVersion: info.latestVersion,
60
- hasUpdate: info.hasUpdate,
61
- changelog: info.changelog,
62
- };
63
- await saveUpdateCache(newCache);
57
+ const newCache: UpdateCache = {
58
+ lastCheckAt: new Date().toISOString(),
59
+ latestVersion: info.latestVersion,
60
+ hasUpdate: info.hasUpdate,
61
+ changelog: info.changelog,
62
+ };
63
+ await saveUpdateCache(newCache);
64
64
 
65
- if (info.hasUpdate) {
66
- return formatNotice(pkg.version, info.latestVersion, info.changelog);
67
- }
68
- } finally {
69
- clearTimeout(timeout);
70
- }
65
+ if (info.hasUpdate) {
66
+ return formatNotice(pkg.version, info.latestVersion, info.changelog);
67
+ }
68
+ } finally {
69
+ clearTimeout(timeout);
70
+ }
71
71
 
72
- return null;
73
- } catch {
74
- return null;
75
- }
72
+ return null;
73
+ } catch {
74
+ return null;
75
+ }
76
76
  }
@@ -1,4 +1,4 @@
1
- import { join } from "path";
1
+ import { join } from "node:path";
2
2
  import { DEFAULT_CONFIG_DIR } from "../constants.ts";
3
3
  import type { UpdateCache } from "./checker.ts";
4
4
 
@@ -6,32 +6,32 @@ const UPDATE_CACHE_PATH = join(DEFAULT_CONFIG_DIR, "update.json");
6
6
 
7
7
  /** Load the cached update check result, if it exists. */
8
8
  export async function loadUpdateCache(): Promise<UpdateCache | undefined> {
9
- try {
10
- const file = Bun.file(UPDATE_CACHE_PATH);
11
- if (!(await file.exists())) return undefined;
12
- return JSON.parse(await file.text()) as UpdateCache;
13
- } catch {
14
- return undefined;
15
- }
9
+ try {
10
+ const file = Bun.file(UPDATE_CACHE_PATH);
11
+ if (!(await file.exists())) return undefined;
12
+ return JSON.parse(await file.text()) as UpdateCache;
13
+ } catch {
14
+ return undefined;
15
+ }
16
16
  }
17
17
 
18
18
  /** Save update check result to the cache file. */
19
19
  export async function saveUpdateCache(cache: UpdateCache): Promise<void> {
20
- try {
21
- await Bun.write(UPDATE_CACHE_PATH, JSON.stringify(cache, null, 2) + "\n");
22
- } catch {
23
- // Ignore write failures (e.g. permissions)
24
- }
20
+ try {
21
+ await Bun.write(UPDATE_CACHE_PATH, `${JSON.stringify(cache, null, 2)}\n`);
22
+ } catch {
23
+ // Ignore write failures (e.g. permissions)
24
+ }
25
25
  }
26
26
 
27
27
  /** Remove the cached update check result. */
28
28
  export async function clearUpdateCache(): Promise<void> {
29
- try {
30
- const file = Bun.file(UPDATE_CACHE_PATH);
31
- if (await file.exists()) {
32
- await Bun.write(UPDATE_CACHE_PATH, "");
33
- }
34
- } catch {
35
- // Ignore
36
- }
29
+ try {
30
+ const file = Bun.file(UPDATE_CACHE_PATH);
31
+ if (await file.exists()) {
32
+ await Bun.write(UPDATE_CACHE_PATH, "");
33
+ }
34
+ } catch {
35
+ // Ignore
36
+ }
37
37
  }
@@ -2,121 +2,116 @@ import pkg from "../../package.json";
2
2
  import { DEFAULTS } from "../constants.ts";
3
3
 
4
4
  const NPM_REGISTRY_URL = `https://registry.npmjs.org/${pkg.name}/latest`;
5
- const GITHUB_REPO = pkg.repository.url
6
- .replace(/^https:\/\/github\.com\//, "")
7
- .replace(/\.git$/, "");
5
+ const GITHUB_REPO = pkg.repository.url.replace(/^https:\/\/github\.com\//, "").replace(/\.git$/, "");
8
6
 
9
7
  export interface UpdateInfo {
10
- currentVersion: string;
11
- latestVersion: string;
12
- hasUpdate: boolean;
13
- aheadOfLatest: boolean;
14
- changelog?: string;
8
+ currentVersion: string;
9
+ latestVersion: string;
10
+ hasUpdate: boolean;
11
+ aheadOfLatest: boolean;
12
+ changelog?: string;
15
13
  }
16
14
 
17
15
  export interface UpdateCache {
18
- lastCheckAt: string;
19
- latestVersion: string;
20
- hasUpdate: boolean;
21
- changelog?: string;
16
+ lastCheckAt: string;
17
+ latestVersion: string;
18
+ hasUpdate: boolean;
19
+ changelog?: string;
22
20
  }
23
21
 
24
22
  export type InstallMethod = "npm" | "bun" | "binary" | "local-dev";
25
23
 
26
24
  /** Compare two semver strings. Returns true if latest > current. */
27
25
  export function isNewerVersion(current: string, latest: string): boolean {
28
- return Bun.semver.order(current, latest) === -1;
26
+ return Bun.semver.order(current, latest) === -1;
29
27
  }
30
28
 
31
29
  /** Fetch the latest version from the npm registry. */
32
30
  export async function fetchLatestVersion(signal?: AbortSignal): Promise<string> {
33
- try {
34
- const res = await fetch(NPM_REGISTRY_URL, { signal });
35
- if (!res.ok) return pkg.version;
36
- const data = (await res.json()) as { version: string };
37
- return data.version;
38
- } catch {
39
- return pkg.version;
40
- }
31
+ try {
32
+ const res = await fetch(NPM_REGISTRY_URL, { signal });
33
+ if (!res.ok) return pkg.version;
34
+ const data = (await res.json()) as { version: string };
35
+ return data.version;
36
+ } catch {
37
+ return pkg.version;
38
+ }
41
39
  }
42
40
 
43
41
  /** Fetch changelog from GitHub releases between two versions. */
44
42
  export async function fetchChangelog(
45
- fromVersion: string,
46
- toVersion: string,
47
- signal?: AbortSignal,
43
+ fromVersion: string,
44
+ toVersion: string,
45
+ signal?: AbortSignal,
48
46
  ): Promise<string | undefined> {
49
- try {
50
- const res = await fetch(`https://api.github.com/repos/${GITHUB_REPO}/releases?per_page=20`, {
51
- signal,
52
- headers: { Accept: "application/vnd.github.v3+json" },
53
- });
54
- if (!res.ok) return undefined;
55
-
56
- const releases = (await res.json()) as Array<{
57
- tag_name: string;
58
- body: string | null;
59
- }>;
60
-
61
- const relevant = releases.filter((r) => {
62
- const v = r.tag_name.replace(/^v/, "");
63
- return isNewerVersion(fromVersion, v) && !isNewerVersion(toVersion, v);
64
- });
65
-
66
- if (relevant.length === 0) return undefined;
67
-
68
- return relevant
69
- .map((r) => `## ${r.tag_name}\n${r.body ?? ""}`)
70
- .join("\n\n")
71
- .trim();
72
- } catch {
73
- return undefined;
74
- }
47
+ try {
48
+ const res = await fetch(`https://api.github.com/repos/${GITHUB_REPO}/releases?per_page=20`, {
49
+ signal,
50
+ headers: { Accept: "application/vnd.github.v3+json" },
51
+ });
52
+ if (!res.ok) return undefined;
53
+
54
+ const releases = (await res.json()) as Array<{
55
+ tag_name: string;
56
+ body: string | null;
57
+ }>;
58
+
59
+ const relevant = releases.filter((r) => {
60
+ const v = r.tag_name.replace(/^v/, "");
61
+ return isNewerVersion(fromVersion, v) && !isNewerVersion(toVersion, v);
62
+ });
63
+
64
+ if (relevant.length === 0) return undefined;
65
+
66
+ return relevant
67
+ .map((r) => `## ${r.tag_name}\n${r.body ?? ""}`)
68
+ .join("\n\n")
69
+ .trim();
70
+ } catch {
71
+ return undefined;
72
+ }
75
73
  }
76
74
 
77
75
  /** Check npm for a newer version and fetch changelog if available. */
78
- export async function checkForUpdate(
79
- currentVersion: string,
80
- signal?: AbortSignal,
81
- ): Promise<UpdateInfo> {
82
- const latestVersion = await fetchLatestVersion(signal);
83
- const hasUpdate = isNewerVersion(currentVersion, latestVersion);
84
- const aheadOfLatest = isNewerVersion(latestVersion, currentVersion);
85
-
86
- let changelog: string | undefined;
87
- if (hasUpdate) {
88
- changelog = await fetchChangelog(currentVersion, latestVersion, signal);
89
- }
90
-
91
- return { currentVersion, latestVersion, hasUpdate, aheadOfLatest, changelog };
76
+ export async function checkForUpdate(currentVersion: string, signal?: AbortSignal): Promise<UpdateInfo> {
77
+ const latestVersion = await fetchLatestVersion(signal);
78
+ const hasUpdate = isNewerVersion(currentVersion, latestVersion);
79
+ const aheadOfLatest = isNewerVersion(latestVersion, currentVersion);
80
+
81
+ let changelog: string | undefined;
82
+ if (hasUpdate) {
83
+ changelog = await fetchChangelog(currentVersion, latestVersion, signal);
84
+ }
85
+
86
+ return { currentVersion, latestVersion, hasUpdate, aheadOfLatest, changelog };
92
87
  }
93
88
 
94
89
  /** Returns true if the cache is missing or older than 24 hours. */
95
90
  export function needsCheck(cache?: UpdateCache): boolean {
96
- if (!cache?.lastCheckAt) return true;
97
- return Date.now() - new Date(cache.lastCheckAt).getTime() > DEFAULTS.UPDATE_CHECK_INTERVAL_MS;
91
+ if (!cache?.lastCheckAt) return true;
92
+ return Date.now() - new Date(cache.lastCheckAt).getTime() > DEFAULTS.UPDATE_CHECK_INTERVAL_MS;
98
93
  }
99
94
 
100
95
  /** Detect how mcpx was installed. */
101
96
  export function detectInstallMethod(): InstallMethod {
102
- const script = process.argv[1] ?? "";
103
- const execPath = process.execPath;
104
-
105
- // Local dev: running src/cli.ts directly outside node_modules
106
- if (script.includes("src/cli.ts") && !script.includes("node_modules")) {
107
- return "local-dev";
108
- }
109
-
110
- // Compiled binary: execPath is the binary itself (not bun/node)
111
- if (!execPath.includes("bun") && !execPath.includes("node")) {
112
- return "binary";
113
- }
114
-
115
- // Bun global install: path contains .bun/install
116
- if (script.includes(".bun/install") || script.includes(".bun/bin")) {
117
- return "bun";
118
- }
119
-
120
- // npm global install: fallback for node_modules paths
121
- return "npm";
97
+ const script = process.argv[1] ?? "";
98
+ const execPath = process.execPath;
99
+
100
+ // Local dev: running src/cli.ts directly outside node_modules
101
+ if (script.includes("src/cli.ts") && !script.includes("node_modules")) {
102
+ return "local-dev";
103
+ }
104
+
105
+ // Compiled binary: execPath is the binary itself (not bun/node)
106
+ if (!execPath.includes("bun") && !execPath.includes("node")) {
107
+ return "binary";
108
+ }
109
+
110
+ // Bun global install: path contains .bun/install
111
+ if (script.includes(".bun/install") || script.includes(".bun/bin")) {
112
+ return "bun";
113
+ }
114
+
115
+ // npm global install: fallback for node_modules paths
116
+ return "npm";
122
117
  }
@@ -7,85 +7,80 @@ const ajv = new Ajv({ allErrors: true, strict: false });
7
7
  const validatorCache = new Map<string, ReturnType<typeof ajv.compile>>();
8
8
 
9
9
  export interface ValidationError {
10
- path: string;
11
- message: string;
10
+ path: string;
11
+ message: string;
12
12
  }
13
13
 
14
14
  export interface ValidationResult {
15
- valid: boolean;
16
- errors: ValidationError[];
15
+ valid: boolean;
16
+ errors: ValidationError[];
17
17
  }
18
18
 
19
19
  /** Compile (or retrieve from cache), validate, and return result */
20
20
  function validateWithSchema(
21
- cacheKey: string,
22
- schema: Record<string, unknown>,
23
- input: Record<string, unknown>,
21
+ cacheKey: string,
22
+ schema: Record<string, unknown>,
23
+ input: Record<string, unknown>,
24
24
  ): ValidationResult {
25
- let validate = validatorCache.get(cacheKey);
25
+ let validate = validatorCache.get(cacheKey);
26
26
 
27
- if (!validate) {
28
- try {
29
- validate = ajv.compile(schema);
30
- validatorCache.set(cacheKey, validate);
31
- } catch {
32
- return { valid: true, errors: [] };
33
- }
34
- }
27
+ if (!validate) {
28
+ try {
29
+ validate = ajv.compile(schema);
30
+ validatorCache.set(cacheKey, validate);
31
+ } catch (err) {
32
+ const msg = err instanceof Error ? err.message : "unknown error";
33
+ return { valid: false, errors: [{ path: "(schema)", message: `schema compilation failed: ${msg}` }] };
34
+ }
35
+ }
35
36
 
36
- const valid = validate(input);
37
- if (valid) {
38
- return { valid: true, errors: [] };
39
- }
37
+ const valid = validate(input);
38
+ if (valid) {
39
+ return { valid: true, errors: [] };
40
+ }
40
41
 
41
- const errors = (validate.errors ?? []).map(formatAjvError);
42
- return { valid: false, errors };
42
+ const errors = (validate.errors ?? []).map(formatAjvError);
43
+ return { valid: false, errors };
43
44
  }
44
45
 
45
46
  /** Validate tool arguments against the tool's inputSchema */
46
- export function validateToolInput(
47
- serverName: string,
48
- tool: Tool,
49
- input: Record<string, unknown>,
50
- ): ValidationResult {
51
- const schema = tool.inputSchema;
52
- if (!schema || Object.keys(schema).length === 0) {
53
- return { valid: true, errors: [] };
54
- }
55
- return validateWithSchema(`${serverName}/${tool.name}`, schema, input);
47
+ export function validateToolInput(serverName: string, tool: Tool, input: Record<string, unknown>): ValidationResult {
48
+ const schema = tool.inputSchema;
49
+ if (!schema || Object.keys(schema).length === 0) {
50
+ return { valid: true, errors: [] };
51
+ }
52
+ return validateWithSchema(`${serverName}/${tool.name}`, schema, input);
56
53
  }
57
54
 
58
55
  /** Validate user-collected form data against an elicitation requestedSchema */
59
56
  export function validateElicitationResponse(
60
- schema: Record<string, unknown>,
61
- input: Record<string, unknown>,
57
+ schema: Record<string, unknown>,
58
+ input: Record<string, unknown>,
62
59
  ): ValidationResult {
63
- return validateWithSchema(`__elicitation__${JSON.stringify(schema)}`, schema, input);
60
+ return validateWithSchema(`__elicitation__${JSON.stringify(schema)}`, schema, input);
64
61
  }
65
62
 
66
63
  function formatAjvError(err: ErrorObject): ValidationError {
67
- const path = err.instancePath
68
- ? err.instancePath.replace(/^\//, "").replace(/\//g, ".")
69
- : "(root)";
64
+ const path = err.instancePath ? err.instancePath.replace(/^\//, "").replace(/\//g, ".") : "(root)";
70
65
 
71
- switch (err.keyword) {
72
- case "required": {
73
- const field = (err.params as { missingProperty: string }).missingProperty;
74
- return { path: field, message: `missing required field "${field}"` };
75
- }
76
- case "type": {
77
- const expected = (err.params as { type: string }).type;
78
- return { path, message: `must be ${expected}` };
79
- }
80
- case "enum": {
81
- const allowed = (err.params as { allowedValues: unknown[] }).allowedValues;
82
- return { path, message: `must be one of: ${allowed.join(", ")}` };
83
- }
84
- case "additionalProperties": {
85
- const extra = (err.params as { additionalProperty: string }).additionalProperty;
86
- return { path: extra, message: `unknown property "${extra}"` };
87
- }
88
- default:
89
- return { path, message: err.message ?? "validation failed" };
90
- }
66
+ switch (err.keyword) {
67
+ case "required": {
68
+ const field = (err.params as { missingProperty: string }).missingProperty;
69
+ return { path: field, message: `missing required field "${field}"` };
70
+ }
71
+ case "type": {
72
+ const expected = (err.params as { type: string }).type;
73
+ return { path, message: `must be ${expected}` };
74
+ }
75
+ case "enum": {
76
+ const allowed = (err.params as { allowedValues: unknown[] }).allowedValues;
77
+ return { path, message: `must be one of: ${allowed.join(", ")}` };
78
+ }
79
+ case "additionalProperties": {
80
+ const extra = (err.params as { additionalProperty: string }).additionalProperty;
81
+ return { path: extra, message: `unknown property "${extra}"` };
82
+ }
83
+ default:
84
+ return { path, message: err.message ?? "validation failed" };
85
+ }
91
86
  }