@mcpjam/cli 3.10.0 → 3.10.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/dist/index.js CHANGED
@@ -1,14 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command, CommanderError } from 'commander';
3
3
  import { realpathSync, mkdirSync, writeFileSync, readFileSync, existsSync, statSync, closeSync, renameSync, openSync } from 'fs';
4
- import { pathToFileURL, fileURLToPath } from 'url';
4
+ import { pathToFileURL } from 'url';
5
5
  import { probeMcpServer, redactSensitiveValue, runServerDoctor, collectServerSnapshot, serializeStableServerSnapshot, serializeServerSnapshot, buildServerDiffReport, validateToolCallResult, isCallToolResultError, buildToolCallValidationReport, listResources, readResource, listPrompts, getPrompt, MCPAppsConformanceTest, MCPAppsConformanceSuite, runOAuthLogin, OAuthConformanceTest, OAuthConformanceSuite, MCPConformanceTest, MCPConformanceSuite, withEphemeralClient, diffServerSnapshots, ServerSnapshotFormatError, renderStructuredRunJUnitXml, renderStructuredRunJson, toConformanceReport, renderConformanceReportJUnitXml, renderConformanceReportJson, formatOAuthConformanceHuman, formatOAuthConformanceSuiteHuman, fetchOAuthMetadata, executeOAuthProxy, executeDebugOAuthProxy, generateRandomString, generateCodeChallenge, createInteractiveAuthorizationSession, openUrlInBrowser, MCPClientManager, MCP_APPS_CHECK_CATEGORIES, MCP_APPS_CHECK_IDS, OAuthProxyError, MCP_CHECK_CATEGORIES, MCP_CHECK_IDS } from '@mcpjam/sdk';
6
6
  import { mkdir, writeFile, readFile, chmod, rename, rm } from 'fs/promises';
7
7
  import path2, { dirname, join, basename } from 'path';
8
8
  import { randomUUID } from 'crypto';
9
9
  import { spawn } from 'child_process';
10
+ import { createRequire } from 'module';
10
11
  import os, { homedir } from 'os';
11
- import { listEvalRunIterationsOperation, getEvalIterationTraceOperation, getEvalSuiteOperation, updateEvalSuiteOperation, deleteEvalSuiteOperation, setEvalSuiteScheduleOperation, listEvalCasesOperation, getEvalCaseOperation, createEvalCaseOperation, updateEvalCaseOperation, deleteEvalCaseOperation, generateEvalCasesOperation, createTunnelOperation, DEFAULT_PLATFORM_API_BASE_URL, PlatformApiClient, isPlatformApiError, PlatformApiError, listProjectsOperation, listProjectServersOperation, showServersOperation, createEvalSuiteOperation, listEvalSuitesOperation, runEvalSuiteOperation, getEvalRunOperation } from '@mcpjam/sdk/platform';
12
+ import { listEvalRunIterationsOperation, getEvalIterationTraceOperation, getEvalSuiteOperation, updateEvalSuiteOperation, deleteEvalSuiteOperation, setEvalSuiteScheduleOperation, listEvalCasesOperation, getEvalCaseOperation, createEvalCaseOperation, updateEvalCaseOperation, deleteEvalCaseOperation, generateEvalCasesOperation, createHostOperation, updateHostOperation, createTunnelOperation, DEFAULT_PLATFORM_API_BASE_URL, PlatformApiClient, isPlatformApiError, PlatformApiError, listProjectsOperation, listProjectServersOperation, showServersOperation, createEvalSuiteOperation, listEvalSuitesOperation, runEvalSuiteOperation, getEvalRunOperation, listHostsOperation, getHostOperation, deleteHostOperation } from '@mcpjam/sdk/platform';
13
+ import { HOST_TEMPLATES as HOST_TEMPLATES$1 } from '@mcpjam/sdk/host-config/templates';
12
14
  import { StdioServerTransport, McpServer } from '@modelcontextprotocol/server';
13
15
  import { z } from 'zod';
14
16
  import { PostHog } from 'posthog-node';
@@ -19,7 +21,7 @@ import { WebSocket } from 'ws';
19
21
 
20
22
  // package.json
21
23
  var package_default = {
22
- version: "3.10.0"};
24
+ version: "3.10.1"};
23
25
 
24
26
  // src/lib/output.ts
25
27
  var DEFAULT_OUTPUT_FORMAT = "json";
@@ -1112,6 +1114,7 @@ function normalizeOptionalAuthValue(value) {
1112
1114
  const trimmed = value?.trim();
1113
1115
  return trimmed ? trimmed : void 0;
1114
1116
  }
1117
+ var require2 = createRequire(import.meta.url);
1115
1118
  var FALLBACK_INSPECTOR_BASE_URL = "http://127.0.0.1:6274";
1116
1119
  var DEFAULT_START_TIMEOUT_MS = 3e4;
1117
1120
  var DEFAULT_COMMAND_TIMEOUT_MS = 3e4;
@@ -1597,9 +1600,12 @@ async function fetchFreshInspectorSessionToken(normalizedBaseUrl) {
1597
1600
  return body.token;
1598
1601
  }
1599
1602
  function getInspectorStartScriptPath() {
1600
- return fileURLToPath(
1601
- new URL("../../../mcpjam-inspector/bin/start.js", import.meta.url)
1602
- );
1603
+ try {
1604
+ const packageJsonPath = require2.resolve("@mcpjam/inspector/package.json");
1605
+ return path2.resolve(path2.dirname(packageJsonPath), "bin/start.js");
1606
+ } catch {
1607
+ return void 0;
1608
+ }
1603
1609
  }
1604
1610
  async function getInspectorHealth(baseUrl, timeoutMs = HEALTH_FETCH_TIMEOUT_MS) {
1605
1611
  try {
@@ -1802,15 +1808,15 @@ async function startInspector(baseUrl, timeoutMs) {
1802
1808
  const parsedUrl = new URL(baseUrl);
1803
1809
  const port = parsedUrl.port || "6274";
1804
1810
  const startScriptPath = getInspectorStartScriptPath();
1805
- const hasStartScript = existsSync(startScriptPath);
1806
- const args = hasStartScript ? [startScriptPath, "--port", port, "--no-open"] : ["-y", "@mcpjam/inspector@latest", "--port", port, "--no-open"];
1807
- const executable = hasStartScript ? process.execPath : getNpxExecutable();
1811
+ const localStartScriptPath = startScriptPath && existsSync(startScriptPath) ? startScriptPath : void 0;
1812
+ const args = localStartScriptPath ? [localStartScriptPath, "--port", port, "--no-open"] : ["-y", "@mcpjam/inspector@latest", "--port", port, "--no-open"];
1813
+ const executable = localStartScriptPath ? process.execPath : getNpxExecutable();
1808
1814
  const logPath = getInspectorStartupLogPath();
1809
1815
  const logFd = openStartupLogFile(logPath);
1810
1816
  let child;
1811
1817
  try {
1812
1818
  child = spawn(executable, args, {
1813
- cwd: hasStartScript ? path2.dirname(startScriptPath) : process.cwd(),
1819
+ cwd: localStartScriptPath ? path2.dirname(localStartScriptPath) : process.cwd(),
1814
1820
  detached: true,
1815
1821
  stdio: ["ignore", logFd, logFd],
1816
1822
  env: {
@@ -4082,6 +4088,180 @@ function registerEvalCommands(program) {
4082
4088
  }
4083
4089
  );
4084
4090
  }
4091
+ var HOST_TEMPLATES = HOST_TEMPLATES$1.map(({ id, label }) => ({ id, label }));
4092
+ function addPlatformOptions2(command) {
4093
+ return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
4094
+ "--api-url <url>",
4095
+ "MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
4096
+ );
4097
+ }
4098
+ async function runPlatformCommand2(options, timeoutMs, execute) {
4099
+ const controller = new AbortController();
4100
+ const timeoutHandle = setTimeout(() => {
4101
+ controller.abort(
4102
+ new PlatformApiError(`Request timed out after ${timeoutMs}ms`, "TIMEOUT", {
4103
+ status: 0
4104
+ })
4105
+ );
4106
+ }, timeoutMs);
4107
+ timeoutHandle.unref?.();
4108
+ try {
4109
+ const { client } = buildPlatformClient({ ...options, timeoutMs });
4110
+ return await execute({ client, signal: controller.signal });
4111
+ } catch (error) {
4112
+ if (controller.signal.aborted && controller.signal.reason instanceof PlatformApiError) {
4113
+ throw toCliError(controller.signal.reason);
4114
+ }
4115
+ throw toCliError(error);
4116
+ } finally {
4117
+ clearTimeout(timeoutHandle);
4118
+ }
4119
+ }
4120
+ function loadConfigObject(options) {
4121
+ if (options.file !== void 0 && options.json !== void 0) {
4122
+ throw usageError("Provide either --file or --json, not both.");
4123
+ }
4124
+ let base;
4125
+ if (options.file !== void 0) {
4126
+ let text;
4127
+ try {
4128
+ text = options.file === "-" ? readFileSync(0, "utf8") : readFileSync(options.file, "utf8");
4129
+ } catch (error) {
4130
+ throw usageError(`Failed to read --file "${options.file}".`, {
4131
+ source: error instanceof Error ? error.message : String(error)
4132
+ });
4133
+ }
4134
+ if (text.trim() === "") throw usageError("--file input is empty.");
4135
+ try {
4136
+ base = JSON.parse(text);
4137
+ } catch (error) {
4138
+ throw usageError("--file must contain valid JSON.", {
4139
+ source: error instanceof Error ? error.message : String(error)
4140
+ });
4141
+ }
4142
+ } else if (options.json !== void 0) {
4143
+ base = new JsonInputContext().parseJsonInputRecord(options.json, "--json");
4144
+ } else {
4145
+ return void 0;
4146
+ }
4147
+ if (typeof base !== "object" || base === null || Array.isArray(base)) {
4148
+ throw usageError("Host config must be a JSON object.");
4149
+ }
4150
+ return base;
4151
+ }
4152
+ function registerHostsCommands(program) {
4153
+ const hosts = program.command("hosts").description("List, create, and manage the hosts in your hosted MCPJam projects");
4154
+ hosts.command("templates").description("List the built-in host templates usable with `hosts create --template`").action((_options, command) => {
4155
+ const globalOptions = getGlobalOptions(command);
4156
+ writeResult({ items: HOST_TEMPLATES }, globalOptions.format);
4157
+ });
4158
+ addPlatformOptions2(
4159
+ hosts.command("list").description("List the hosts saved in a project").option(
4160
+ "--project <id-or-name>",
4161
+ "Project name or ID (defaults to the most recently updated project)"
4162
+ )
4163
+ ).action(async (options, command) => {
4164
+ const globalOptions = getGlobalOptions(command);
4165
+ const result = await runPlatformCommand2(
4166
+ options,
4167
+ globalOptions.timeout,
4168
+ ({ client, signal }) => listHostsOperation.execute({ project: options.project }, { client, signal })
4169
+ );
4170
+ writeResult(result, globalOptions.format);
4171
+ });
4172
+ addPlatformOptions2(
4173
+ hosts.command("get").description("Show one host's full settings, including its host config").requiredOption("--host <id-or-name>", "Host name or ID").option("--project <id-or-name>", "Project name or ID")
4174
+ ).action(
4175
+ async (options, command) => {
4176
+ const globalOptions = getGlobalOptions(command);
4177
+ const result = await runPlatformCommand2(
4178
+ options,
4179
+ globalOptions.timeout,
4180
+ ({ client, signal }) => getHostOperation.execute(
4181
+ { project: options.project, host: options.host },
4182
+ { client, signal }
4183
+ )
4184
+ );
4185
+ writeResult(result, globalOptions.format);
4186
+ }
4187
+ );
4188
+ addPlatformOptions2(
4189
+ hosts.command("create").description(
4190
+ "Create a host from a built-in template (--template) or a full host config (--file/--json)"
4191
+ ).requiredOption("--name <name>", "Display name for the new host").option("--project <id-or-name>", "Project name or ID").option(
4192
+ "--template <id>",
4193
+ "Built-in template id (see `hosts templates`), e.g. claude, chatgpt, cursor"
4194
+ ).option(
4195
+ "--theme <theme>",
4196
+ "Theme for the seeded config: light or dark (template only)"
4197
+ ).option("--file <path>", "Host config v2 JSON file (or - for stdin)").option("--json <json>", "Inline host config v2 JSON (or @file, or -)")
4198
+ ).action(
4199
+ async (options, command) => {
4200
+ const globalOptions = getGlobalOptions(command);
4201
+ const config = loadConfigObject(options);
4202
+ const input = validateInput(createHostOperation, {
4203
+ project: options.project,
4204
+ name: options.name,
4205
+ ...options.template !== void 0 ? { template: options.template } : {},
4206
+ ...options.theme !== void 0 ? { theme: options.theme } : {},
4207
+ ...config !== void 0 ? { config } : {}
4208
+ });
4209
+ const result = await runPlatformCommand2(
4210
+ options,
4211
+ globalOptions.timeout,
4212
+ ({ client, signal }) => createHostOperation.execute(input, { client, signal })
4213
+ );
4214
+ writeResult(result, globalOptions.format);
4215
+ }
4216
+ );
4217
+ addPlatformOptions2(
4218
+ hosts.command("update").description("Edit a host's name and/or its host config").requiredOption("--host <id-or-name>", "Host name or ID").option("--project <id-or-name>", "Project name or ID").option("--name <name>", "New display name").option("--file <path>", "Replacement host config v2 JSON (or - for stdin)").option("--json <json>", "Inline replacement host config v2 JSON (or @file, or -)")
4219
+ ).action(
4220
+ async (options, command) => {
4221
+ const globalOptions = getGlobalOptions(command);
4222
+ const config = loadConfigObject(options);
4223
+ const input = validateInput(updateHostOperation, {
4224
+ project: options.project,
4225
+ host: options.host,
4226
+ ...options.name !== void 0 ? { name: options.name } : {},
4227
+ ...config !== void 0 ? { config } : {}
4228
+ });
4229
+ const result = await runPlatformCommand2(
4230
+ options,
4231
+ globalOptions.timeout,
4232
+ ({ client, signal }) => updateHostOperation.execute(input, { client, signal })
4233
+ );
4234
+ writeResult(result, globalOptions.format);
4235
+ }
4236
+ );
4237
+ addPlatformOptions2(
4238
+ hosts.command("delete").description("Permanently delete a host from a project").requiredOption("--host <id-or-name>", "Host name or ID").option("--project <id-or-name>", "Project name or ID")
4239
+ ).action(
4240
+ async (options, command) => {
4241
+ const globalOptions = getGlobalOptions(command);
4242
+ const result = await runPlatformCommand2(
4243
+ options,
4244
+ globalOptions.timeout,
4245
+ ({ client, signal }) => deleteHostOperation.execute(
4246
+ {
4247
+ project: options.project,
4248
+ host: options.host
4249
+ },
4250
+ { client, signal }
4251
+ )
4252
+ );
4253
+ writeResult(result, globalOptions.format);
4254
+ }
4255
+ );
4256
+ }
4257
+ function validateInput(op, raw) {
4258
+ const parsed = op.inputSchema.safeParse(raw);
4259
+ if (!parsed.success) {
4260
+ const detail = parsed.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
4261
+ throw usageError(`Invalid input: ${detail}`);
4262
+ }
4263
+ return parsed.data;
4264
+ }
4085
4265
 
4086
4266
  // src/lib/server-doctor.ts
4087
4267
  function summarizeServerDoctorTarget(target, config) {
@@ -4833,13 +5013,13 @@ function statusGlyph(status) {
4833
5013
  }
4834
5014
 
4835
5015
  // src/commands/projects.ts
4836
- function addPlatformOptions2(command) {
5016
+ function addPlatformOptions3(command) {
4837
5017
  return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
4838
5018
  "--api-url <url>",
4839
5019
  "MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
4840
5020
  );
4841
5021
  }
4842
- async function runPlatformCommand2(options, timeoutMs, execute) {
5022
+ async function runPlatformCommand3(options, timeoutMs, execute) {
4843
5023
  const controller = new AbortController();
4844
5024
  const timeoutHandle = setTimeout(() => {
4845
5025
  controller.abort(
@@ -4867,11 +5047,11 @@ async function runPlatformCommand2(options, timeoutMs, execute) {
4867
5047
  }
4868
5048
  function registerProjectsCommands(program) {
4869
5049
  const projects = program.command("projects").description("Operate the MCP servers saved in your hosted MCPJam projects");
4870
- addPlatformOptions2(
5050
+ addPlatformOptions3(
4871
5051
  projects.command("list").description("List the projects you can access")
4872
5052
  ).action(async (options, command) => {
4873
5053
  const globalOptions = getGlobalOptions(command);
4874
- const result = await runPlatformCommand2(
5054
+ const result = await runPlatformCommand3(
4875
5055
  options,
4876
5056
  globalOptions.timeout,
4877
5057
  ({ client, signal }) => listProjectsOperation.execute({}, { client, signal })
@@ -4883,14 +5063,14 @@ function registerProjectsCommands(program) {
4883
5063
  writeResult(result, globalOptions.format);
4884
5064
  }
4885
5065
  });
4886
- addPlatformOptions2(
5066
+ addPlatformOptions3(
4887
5067
  projects.command("servers").description("List the servers saved in a project").option(
4888
5068
  "--project <id-or-name>",
4889
5069
  "Project name or ID (defaults to the most recently updated project)"
4890
5070
  )
4891
5071
  ).action(async (options, command) => {
4892
5072
  const globalOptions = getGlobalOptions(command);
4893
- const result = await runPlatformCommand2(
5073
+ const result = await runPlatformCommand3(
4894
5074
  options,
4895
5075
  globalOptions.timeout,
4896
5076
  ({ client, signal }) => listProjectServersOperation.execute(
@@ -4905,7 +5085,7 @@ function registerProjectsCommands(program) {
4905
5085
  writeResult(result, globalOptions.format);
4906
5086
  }
4907
5087
  });
4908
- addPlatformOptions2(
5088
+ addPlatformOptions3(
4909
5089
  projects.command("status").description(
4910
5090
  "Health-check every server in a project (hosted doctor per server)"
4911
5091
  ).option(
@@ -4914,7 +5094,7 @@ function registerProjectsCommands(program) {
4914
5094
  )
4915
5095
  ).action(async (options, command) => {
4916
5096
  const globalOptions = getGlobalOptions(command);
4917
- const payload = await runPlatformCommand2(
5097
+ const payload = await runPlatformCommand3(
4918
5098
  options,
4919
5099
  globalOptions.timeout,
4920
5100
  ({ client, signal }) => showServersOperation.execute(
@@ -8799,6 +8979,7 @@ async function main(argv = process.argv, dependencies = {}) {
8799
8979
  registerAuthCommands(program);
8800
8980
  registerProjectsCommands(program);
8801
8981
  registerEvalCommands(program);
8982
+ registerHostsCommands(program);
8802
8983
  registerTunnelCommands(program);
8803
8984
  registerInspectorCommands(program);
8804
8985
  registerMcpCommands(program);