@mcpjam/cli 6.4.0 → 6.4.2
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 +67 -653
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command, CommanderError, Option } from 'commander';
|
|
3
|
-
import { realpathSync, readFileSync, existsSync, mkdirSync, writeFileSync, statSync, chmodSync, unlinkSync,
|
|
3
|
+
import { realpathSync, readFileSync, existsSync, mkdirSync, writeFileSync, statSync, chmodSync, unlinkSync, renameSync } from 'fs';
|
|
4
4
|
import { pathToFileURL } from 'url';
|
|
5
5
|
import { MODEL_REASONING_EFFORTS, MCP_CHECK_IDS, MCP_APPS_CHECK_IDS, MCP_TASKS_CHECK_IDS, RETIRED_MCP_CHECK_IDS, RENAMED_MCP_TASKS_CHECK_IDS, loadEvalSuiteFile, createSuiteFileRunner, runSuiteFile, SuiteFileRunError, formatLocalEvalRunSummary, renderStructuredRunJson, probeMcpServer, redactForTelemetry, runServerDoctor, collectServerSnapshot, serializeStableServerSnapshot, serializeServerSnapshot, buildServerDiffReport, classifyMcpHeader, validateToolCallResult, isCallToolResultError, buildToolCallValidationReport, listResources, readResource, listServerSkillCatalog, getVerifiedServerSkill, isServerSkillRefusalError, readVerifiedServerSkillFile, SubscriptionCoordinator, listTools, listPrompts, getPrompt, MCPAppsConformanceTest, scoreFromAppsResult, MCPAppsConformanceSuite, MCPTasksConformanceTest, scoreFromTasksResult, runOAuthLogin, OAuthConformanceTest, scoreFromOAuthResult, OAuthConformanceSuite, runXaaFlow, MCPConformanceTest, scoreFromProtocolResult, MCPConformanceSuite, runConformance, OPENAI_SUBMISSION_MODES, renderStructuredRunJUnitXml, renderStructuredRunHtml, withEphemeralClient, diffServerSnapshots, ServerSnapshotFormatError, parseToolResultAuthChallenge, DEFAULT_SUBSCRIPTION_RECONNECT_POLICY, isKnownProtocolVersion, describeConformanceScore, toConformanceReport, buildConformanceRunReport, MCP_TASKS_READINESS_IDS, renderConformanceReportJUnitXml, renderConformanceReportJson, formatOAuthConformanceHuman, formatOAuthConformanceSuiteHuman, fetchOAuthMetadata, executeOAuthProxy, executeDebugOAuthProxy, normalizeRegistrationStrategy, normalizeXaaClientAuth, normalizeIdentityAssertionFormat, IDENTITY_ASSERTION_FORMATS, XAA_CONFIDENTIAL_CIMD_ORIGIN, getLocalConfidentialCimdProvider, MCP_LOG_LEVELS, MCP_PROTOCOL_VERSIONS, isConformanceReportingConfigured, reportConformanceRun, reportConformanceRunSafely, DIRECTORY_FEATURE_CLAIMS, gatherClaudeReadinessEvidence, gradeClaudeReadiness, gatherOpenAIReadinessEvidence, xmldomParseXml, gradeOpenAIReadiness, gatherMuseReadinessEvidence, gradeMuseReadiness, openUrlInBrowser, buildEvalRunReport, GATE_WAIVER_MAX_REASON_LENGTH, GATE_WAIVER_REASON_NOTICE, MCPClientManager, withSkillsExtensionCapability, extractAuthChallenge, isUnauthorized401, detectCiMetadata, MCP_SKILLS_EXTENSION_ID, decodeMcpHeaderValue, canDeclareTasksExtension, createStrictElicitationContentValidator, MCP_APPS_CHECK_CATEGORIES, MCP_TASKS_CHECK_CATEGORIES, validateTaskOverrides, EVENTS_CHECK_IDS, MCP_OAUTH_READINESS_IDS, OAuthProxyError, isLoopbackHost, MCP_READINESS_IDS, LAZY_AUTH_PROBE_LIMITS, OPENAI_SUBMISSION_MODE_SHAPES, createDirectoryPluginFileSource, collectZipArchiveObservations, createZipPluginFileSource, DIRECTORY_SNAPSHOT_LABELS, DIRECTORY_TOOL_TEST_STATUSES, generateRandomString, generateCodeChallenge, createInteractiveAuthorizationSession, declareEvalSuiteFileValidity, aiRefusalClass, formatEvalRunDecisionSummary, gateOutcomeVerdict, applyGateWaiver, formatGateReport, formatGateWaiverLine, detectFlakyCases, evaluateCompareGates, buildRunCompareReport, formatSuiteFileFindings, serializeEvalSuiteFile, MAX_SUITE_FILE_BYTES, buildCorpus, HostedOnlyCaseError, verifyCorpusLock, TaskLifecycleEngine, driveTaskToTerminal, extensionTaskToObservation, legacyTaskToObservation, startEventsConformanceReceiver, runEventsConformance, MCP_CHECK_CATEGORIES, recognizedAiRefusalCode, readEvalRunDecisionSummary as readEvalRunDecisionSummary$1, buildEvalRunDecisionSummary, evaluateGates, gateInputFromPlatformRun, isGateWaiverInForce, calculateLatencyStats, CORPUS_LOCK_VERSION, suiteFilePointer, passRateFractionFromPercent, DEFAULT_MIN_EFFECT_SIZE, DEFAULT_MIN_SAMPLE_SIZE, planPlatformSuiteGradingUpdate, isUnknownTaskError, isMCPTasksWireError, LEGACY_TASK_STATUSES, isMCPEventsWireError, classifyEventsRpcError } from '@mcpjam/sdk';
|
|
6
6
|
import { isMcpjamDeploymentError, deploymentPolicy, resolveDeployment, MCPJAM_CLOUD_API_URL, backendFetch, trimTrailingSlashes } from '@mcpjam/sdk/internal/deployment';
|
|
@@ -11,10 +11,11 @@ import path3, { join, dirname, basename, resolve } from 'path';
|
|
|
11
11
|
import { getAuthFilePath, readStoredAuth, clearStoredAuth, getOAuthAccessToken as getOAuthAccessToken$1, exchangePlatformToken, writeStoredAuth as writeStoredAuth$1 } from '@mcpjam/sdk/platform-auth';
|
|
12
12
|
import { PostHog } from 'posthog-node';
|
|
13
13
|
import { spawn } from 'child_process';
|
|
14
|
-
import
|
|
14
|
+
import { homedir, tmpdir } from 'os';
|
|
15
15
|
import { proxySettings } from '@mcpjam/sdk/internal/network-proxy';
|
|
16
16
|
import { setGlobalDispatcher, EnvHttpProxyAgent } from 'undici';
|
|
17
17
|
import { createRequire } from 'module';
|
|
18
|
+
import { normalizeInspectorFrontendUrl, ensureInspector as ensureInspector$1, stopInspector as stopInspector$1, isAuthFailure, normalizeInspectorBaseUrl as normalizeInspectorBaseUrl$1, isInspectorError, ensureInspectorBackend as ensureInspectorBackend$1, clearInspectorSessionTokenCache as clearInspectorSessionTokenCache$1, fetchInspectorSessionToken as fetchInspectorSessionToken$1, delay } from '@mcpjam/sdk/internal/inspector';
|
|
18
19
|
import { isDeepStrictEqual } from 'util';
|
|
19
20
|
import * as readline from 'readline/promises';
|
|
20
21
|
import { isEvalRunTerminalStatus, swarmVerdictLabel, composeSuiteGateWithBaseReport, EVAL_SUITE_SCHEMA_VERSION, EVAL_SUITE_SCHEMA_VERSIONS, MAX_BATCH_CREATE_CASES, filterSuppressedSuiteAssertions, DEFAULT_SUITE_WIDE_THRESHOLD_PERCENT, evalSuiteFileSchema, MAX_IMPORT_NOTE_CHARS, isOpaqueId } from '@mcpjam/sdk/contract';
|
|
@@ -29,12 +30,12 @@ import { applyVisibilityPolicyAndCountSignals, isAppOnlyTool, extractHostExecuti
|
|
|
29
30
|
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
30
31
|
import { McpServer } from '@modelcontextprotocol/server';
|
|
31
32
|
import { z } from 'zod';
|
|
32
|
-
import { generateWebhookSecret, isValidWebhookSecret, DRAFT_PROFILE_ID, CHATGPT_PROFILE_ID, getEventsProfile, CHATGPT_2026_09_30_PROFILE_ID, selectDeliveryMode, MemoryEventInbox, computeBindingKey, EventsCoordinator, EventsPushRuntime, createManagerPushPort, applySubscriptionPatch, IDLE_NEXT_ACTION_AT, MAX_DELIVERY_BODY_BYTES } from '@mcpjam/sdk/events';
|
|
33
|
+
import { generateWebhookSecret, isValidWebhookSecret, BETA_PROFILE_ID, DRAFT_PROFILE_ID, CHATGPT_PROFILE_ID, getEventsProfile, CHATGPT_2026_09_30_PROFILE_ID, selectDeliveryMode, MemoryEventInbox, computeBindingKey, EventsCoordinator, EventsPushRuntime, hasEventsProfileCapability, createManagerPushPort, applySubscriptionPatch, IDLE_NEXT_ACTION_AT, MAX_DELIVERY_BODY_BYTES } from '@mcpjam/sdk/events';
|
|
33
34
|
import { selectPluginMcpServerMap, detectPluginMcpTransport } from '@mcpjam/sdk/plugin-bundle';
|
|
34
35
|
|
|
35
36
|
// package.json
|
|
36
37
|
var package_default = {
|
|
37
|
-
version: "6.4.
|
|
38
|
+
version: "6.4.2"};
|
|
38
39
|
|
|
39
40
|
// src/lib/command-outcome.ts
|
|
40
41
|
var UNKNOWN_COMMAND = "(unknown)";
|
|
@@ -1883,9 +1884,9 @@ function describeDeploymentSource(deployment) {
|
|
|
1883
1884
|
}
|
|
1884
1885
|
return DEPLOYMENT_SOURCE_DESCRIPTIONS[deployment.source];
|
|
1885
1886
|
}
|
|
1887
|
+
var KEY_TYPE_PREFIX = /^[a-z]{1,8}_/;
|
|
1886
1888
|
function redactCloudApiKey(key) {
|
|
1887
|
-
const
|
|
1888
|
-
const prefix = separator > 0 ? key.slice(0, separator + 1) : "";
|
|
1889
|
+
const prefix = KEY_TYPE_PREFIX.exec(key)?.[0] ?? "";
|
|
1889
1890
|
const secret = key.slice(prefix.length);
|
|
1890
1891
|
if (secret.length < 8) {
|
|
1891
1892
|
return `${prefix}\u2026`;
|
|
@@ -2941,8 +2942,8 @@ function spawnBackgroundFetch(cachePath, packageName = DEFAULT_UPDATE_PACKAGE_NA
|
|
|
2941
2942
|
try {
|
|
2942
2943
|
const env = updateCheckEnv(options.env ?? process.env);
|
|
2943
2944
|
if (env === null) return;
|
|
2944
|
-
const
|
|
2945
|
-
const child =
|
|
2945
|
+
const spawn$1 = options.spawn ?? spawn;
|
|
2946
|
+
const child = spawn$1(
|
|
2946
2947
|
options.execPath ?? process.execPath,
|
|
2947
2948
|
["-e", BACKGROUND_FETCH_SCRIPT, cachePath, packageName],
|
|
2948
2949
|
{
|
|
@@ -3607,301 +3608,58 @@ function withRpcLogsIfRequested(value, collector, options) {
|
|
|
3607
3608
|
return attachCliRpcLogs(value, collector);
|
|
3608
3609
|
}
|
|
3609
3610
|
var require2 = createRequire(import.meta.url);
|
|
3610
|
-
var FALLBACK_INSPECTOR_BASE_URL = "http://127.0.0.1:6274";
|
|
3611
|
-
var DEFAULT_START_TIMEOUT_MS = 3e4;
|
|
3612
3611
|
var DEFAULT_COMMAND_TIMEOUT_MS = 3e4;
|
|
3613
3612
|
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
3614
3613
|
var COMMAND_FETCH_TIMEOUT_BUFFER_MS = 2e3;
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
var SESSION_TOKEN_TIMEOUT_MS = 3e3;
|
|
3619
|
-
var STOP_FETCH_TIMEOUT_MS = 3e3;
|
|
3620
|
-
var STARTUP_LOG_MAX_BYTES = 1024 * 1024;
|
|
3621
|
-
var FRONTEND_PORT_SCAN_WINDOW = 10;
|
|
3622
|
-
var WELL_KNOWN_FRONTEND_PORTS = [5173, 5174, 5175, 8080];
|
|
3623
|
-
var TOKEN_TTL_MS = 5 * 6e4;
|
|
3624
|
-
var tokenCache = /* @__PURE__ */ new Map();
|
|
3625
|
-
var tokenRequests = /* @__PURE__ */ new Map();
|
|
3614
|
+
function toCliError2(error) {
|
|
3615
|
+
return isInspectorError(error) ? operationalError(error.message, error.details) : error;
|
|
3616
|
+
}
|
|
3626
3617
|
function normalizeInspectorBaseUrl(baseUrl) {
|
|
3627
|
-
const value = baseUrl?.trim() || process.env.MCPJAM_INSPECTOR_URL?.trim() || FALLBACK_INSPECTOR_BASE_URL;
|
|
3628
3618
|
try {
|
|
3629
|
-
|
|
3630
|
-
parsed.hash = "";
|
|
3631
|
-
parsed.search = "";
|
|
3632
|
-
return parsed.href.replace(/\/$/, "");
|
|
3619
|
+
return normalizeInspectorBaseUrl$1(baseUrl);
|
|
3633
3620
|
} catch (error) {
|
|
3634
|
-
throw
|
|
3635
|
-
`Invalid Inspector URL "${value}".`,
|
|
3636
|
-
error instanceof Error ? error.message : String(error)
|
|
3637
|
-
);
|
|
3638
|
-
}
|
|
3639
|
-
}
|
|
3640
|
-
function buildInspectorUrl(baseUrl, tab) {
|
|
3641
|
-
if (!tab || !tab.trim()) {
|
|
3642
|
-
return baseUrl;
|
|
3621
|
+
throw toCliError2(error);
|
|
3643
3622
|
}
|
|
3644
|
-
return `${baseUrl}/#${tab.trim()}`;
|
|
3645
3623
|
}
|
|
3646
|
-
function
|
|
3647
|
-
if (typeof frontendUrl !== "string" || !frontendUrl.trim()) {
|
|
3648
|
-
return void 0;
|
|
3649
|
-
}
|
|
3650
|
-
try {
|
|
3651
|
-
const parsed = new URL(frontendUrl.trim());
|
|
3652
|
-
parsed.hash = "";
|
|
3653
|
-
parsed.search = "";
|
|
3654
|
-
return parsed.href.replace(/\/$/, "");
|
|
3655
|
-
} catch {
|
|
3656
|
-
return void 0;
|
|
3657
|
-
}
|
|
3658
|
-
}
|
|
3659
|
-
function normalizeExplicitInspectorFrontendUrl(frontendUrl) {
|
|
3660
|
-
const normalized = normalizeInspectorFrontendUrl(frontendUrl);
|
|
3661
|
-
if (!normalized) {
|
|
3662
|
-
throw operationalError(`Invalid Inspector frontend URL "${frontendUrl}".`);
|
|
3663
|
-
}
|
|
3664
|
-
return normalized;
|
|
3665
|
-
}
|
|
3666
|
-
function canonicalizeInspectorFrontendUrl(baseUrl, frontendUrl) {
|
|
3667
|
-
if (!frontendUrl) {
|
|
3668
|
-
return void 0;
|
|
3669
|
-
}
|
|
3624
|
+
async function ensureInspector(options = {}) {
|
|
3670
3625
|
try {
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
return frontendUrl;
|
|
3678
|
-
}
|
|
3679
|
-
return frontendUrl;
|
|
3680
|
-
}
|
|
3681
|
-
function getEffectiveUrlPort(url) {
|
|
3682
|
-
if (url.port) {
|
|
3683
|
-
return url.port;
|
|
3684
|
-
}
|
|
3685
|
-
return url.protocol === "https:" ? "443" : "80";
|
|
3686
|
-
}
|
|
3687
|
-
async function resolveInspectorBrowserBaseUrl(baseUrl, frontendUrl, options = {}) {
|
|
3688
|
-
const fastResolution = await resolveInspectorBrowserBaseUrlFast(
|
|
3689
|
-
baseUrl,
|
|
3690
|
-
frontendUrl
|
|
3691
|
-
);
|
|
3692
|
-
if (fastResolution.browserBaseUrl) {
|
|
3693
|
-
return fastResolution.browserBaseUrl;
|
|
3694
|
-
}
|
|
3695
|
-
if (options.skipDiscovery) {
|
|
3696
|
-
assertFastFrontendMismatch(fastResolution.candidates);
|
|
3697
|
-
return fastResolution.normalizedFrontendUrl ?? baseUrl;
|
|
3698
|
-
}
|
|
3699
|
-
const discoveredCandidates = await discoverLocalInspectorFrontendCandidates(
|
|
3700
|
-
baseUrl,
|
|
3701
|
-
fastResolution.normalizedFrontendUrl
|
|
3702
|
-
);
|
|
3703
|
-
const usableDiscoveredCandidate = discoveredCandidates.find(
|
|
3704
|
-
isUsableInspectorFrontendCandidate
|
|
3705
|
-
);
|
|
3706
|
-
if (usableDiscoveredCandidate) {
|
|
3707
|
-
return usableDiscoveredCandidate.url;
|
|
3708
|
-
}
|
|
3709
|
-
const candidates = [...fastResolution.candidates, ...discoveredCandidates];
|
|
3710
|
-
assertFullFrontendMismatch(candidates);
|
|
3711
|
-
return fastResolution.normalizedFrontendUrl ?? baseUrl;
|
|
3712
|
-
}
|
|
3713
|
-
async function resolveInspectorBrowserBaseUrlFast(baseUrl, frontendUrl) {
|
|
3714
|
-
const normalizedFrontendUrl = canonicalizeInspectorFrontendUrl(
|
|
3715
|
-
baseUrl,
|
|
3716
|
-
normalizeInspectorFrontendUrl(frontendUrl)
|
|
3717
|
-
);
|
|
3718
|
-
const targets = [];
|
|
3719
|
-
if (normalizedFrontendUrl) {
|
|
3720
|
-
targets.push({ source: "advertised", url: normalizedFrontendUrl });
|
|
3721
|
-
}
|
|
3722
|
-
if (!targets.some((target) => target.url === baseUrl)) {
|
|
3723
|
-
targets.push({ source: "base", url: baseUrl });
|
|
3724
|
-
}
|
|
3725
|
-
const candidates = await inspectInspectorFrontendCandidates(
|
|
3726
|
-
baseUrl,
|
|
3727
|
-
targets
|
|
3728
|
-
);
|
|
3729
|
-
const usableCandidate = candidates.find(isUsableInspectorFrontendCandidate);
|
|
3730
|
-
return {
|
|
3731
|
-
...usableCandidate ? { browserBaseUrl: usableCandidate.url } : {},
|
|
3732
|
-
candidates,
|
|
3733
|
-
...normalizedFrontendUrl ? { normalizedFrontendUrl } : {}
|
|
3734
|
-
};
|
|
3735
|
-
}
|
|
3736
|
-
async function inspectInspectorFrontendCandidates(apiBaseUrl, targets) {
|
|
3737
|
-
const settled = await Promise.allSettled(
|
|
3738
|
-
targets.map(
|
|
3739
|
-
(target) => inspectInspectorFrontendCandidate(apiBaseUrl, target.url, target.source)
|
|
3740
|
-
)
|
|
3741
|
-
);
|
|
3742
|
-
return settled.map((result, index) => {
|
|
3743
|
-
if (result.status === "fulfilled") {
|
|
3744
|
-
return result.value;
|
|
3745
|
-
}
|
|
3746
|
-
const target = targets[index];
|
|
3747
|
-
return {
|
|
3748
|
-
isFrontend: false,
|
|
3749
|
-
originStatus: "unknown",
|
|
3750
|
-
source: target.source,
|
|
3751
|
-
url: target.url
|
|
3752
|
-
};
|
|
3753
|
-
});
|
|
3754
|
-
}
|
|
3755
|
-
function assertFastFrontendMismatch(candidates) {
|
|
3756
|
-
const advertisedCandidate = candidates.find(
|
|
3757
|
-
(candidate) => candidate.source === "advertised"
|
|
3758
|
-
);
|
|
3759
|
-
const rejectedLiveCandidate = candidates.find(
|
|
3760
|
-
(candidate) => candidate.isFrontend && candidate.originStatus === "rejected"
|
|
3761
|
-
);
|
|
3762
|
-
if (!rejectedLiveCandidate) {
|
|
3763
|
-
return;
|
|
3764
|
-
}
|
|
3765
|
-
if (advertisedCandidate === rejectedLiveCandidate) {
|
|
3766
|
-
throw frontendMismatchError(void 0, rejectedLiveCandidate);
|
|
3767
|
-
}
|
|
3768
|
-
throw frontendMismatchError(advertisedCandidate, rejectedLiveCandidate);
|
|
3769
|
-
}
|
|
3770
|
-
function assertFullFrontendMismatch(candidates) {
|
|
3771
|
-
const advertisedCandidate = candidates.find(
|
|
3772
|
-
(candidate) => candidate.source === "advertised"
|
|
3773
|
-
);
|
|
3774
|
-
const rejectedLiveCandidate = candidates.find(
|
|
3775
|
-
(candidate) => candidate !== advertisedCandidate && candidate.isFrontend && candidate.originStatus === "rejected"
|
|
3776
|
-
);
|
|
3777
|
-
if (advertisedCandidate?.isFrontend && advertisedCandidate.originStatus === "rejected") {
|
|
3778
|
-
throw frontendMismatchError(void 0, advertisedCandidate);
|
|
3779
|
-
}
|
|
3780
|
-
if (advertisedCandidate && !advertisedCandidate.isFrontend && advertisedCandidate.originStatus === "accepted") {
|
|
3781
|
-
throw frontendMismatchError(advertisedCandidate, rejectedLiveCandidate);
|
|
3782
|
-
}
|
|
3783
|
-
if (rejectedLiveCandidate) {
|
|
3784
|
-
throw frontendMismatchError(advertisedCandidate, rejectedLiveCandidate);
|
|
3626
|
+
return await ensureInspector$1({
|
|
3627
|
+
...options,
|
|
3628
|
+
resolveStartScriptPath: getInspectorStartScriptPath
|
|
3629
|
+
});
|
|
3630
|
+
} catch (error) {
|
|
3631
|
+
throw toCliError2(error);
|
|
3785
3632
|
}
|
|
3786
3633
|
}
|
|
3787
|
-
async function
|
|
3788
|
-
const skipDiscovery = options.skipDiscovery || options.hasActiveClient && !options.openBrowser;
|
|
3634
|
+
async function ensureInspectorBackend(options = {}) {
|
|
3789
3635
|
try {
|
|
3790
|
-
return await
|
|
3791
|
-
|
|
3636
|
+
return await ensureInspectorBackend$1({
|
|
3637
|
+
...options,
|
|
3638
|
+
resolveStartScriptPath: getInspectorStartScriptPath
|
|
3792
3639
|
});
|
|
3793
3640
|
} catch (error) {
|
|
3794
|
-
|
|
3795
|
-
return canonicalizeInspectorFrontendUrl(
|
|
3796
|
-
baseUrl,
|
|
3797
|
-
normalizeInspectorFrontendUrl(frontendUrl)
|
|
3798
|
-
) ?? baseUrl;
|
|
3799
|
-
}
|
|
3800
|
-
throw error;
|
|
3641
|
+
throw toCliError2(error);
|
|
3801
3642
|
}
|
|
3802
3643
|
}
|
|
3803
|
-
async function
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
const browserBaseUrl3 = explicitFrontendUrl ?? await resolveInspectorBrowserBaseUrlForHealth(baseUrl, health.frontendUrl, {
|
|
3809
|
-
hasActiveClient: health.hasActiveClient,
|
|
3810
|
-
openBrowser: options.openBrowser === true,
|
|
3811
|
-
skipDiscovery: options.skipDiscovery
|
|
3812
|
-
});
|
|
3813
|
-
const url2 = buildInspectorUrl(browserBaseUrl3, options.tab);
|
|
3814
|
-
if (options.openBrowser && !health.hasActiveClient) {
|
|
3815
|
-
openUrl(
|
|
3816
|
-
buildInspectorAccessUrl(url2, await fetchInspectorSessionToken(baseUrl))
|
|
3817
|
-
);
|
|
3818
|
-
}
|
|
3819
|
-
return {
|
|
3820
|
-
baseUrl,
|
|
3821
|
-
...browserBaseUrl3 !== baseUrl ? { frontendUrl: browserBaseUrl3 } : {},
|
|
3822
|
-
hasActiveClient: health.hasActiveClient,
|
|
3823
|
-
url: url2,
|
|
3824
|
-
started: false
|
|
3825
|
-
};
|
|
3826
|
-
}
|
|
3827
|
-
if (!options.startIfNeeded) {
|
|
3828
|
-
throw operationalError(
|
|
3829
|
-
"Inspector is not running. Run `mcpjam inspector open` first or pass an Inspector-backed option that starts it."
|
|
3830
|
-
);
|
|
3831
|
-
}
|
|
3832
|
-
await startInspector(baseUrl, options.timeoutMs ?? DEFAULT_START_TIMEOUT_MS);
|
|
3833
|
-
clearInspectorSessionTokenCache(baseUrl);
|
|
3834
|
-
const startedHealth = await getInspectorHealth(baseUrl);
|
|
3835
|
-
const browserBaseUrl2 = explicitFrontendUrl ?? await resolveInspectorBrowserBaseUrlForHealth(
|
|
3836
|
-
baseUrl,
|
|
3837
|
-
startedHealth.frontendUrl,
|
|
3838
|
-
{
|
|
3839
|
-
hasActiveClient: startedHealth.hasActiveClient,
|
|
3840
|
-
openBrowser: options.openBrowser === true,
|
|
3841
|
-
skipDiscovery: options.skipDiscovery
|
|
3842
|
-
}
|
|
3843
|
-
);
|
|
3844
|
-
const url = buildInspectorUrl(browserBaseUrl2, options.tab);
|
|
3845
|
-
if (options.openBrowser) {
|
|
3846
|
-
openUrl(
|
|
3847
|
-
buildInspectorAccessUrl(url, await fetchInspectorSessionToken(baseUrl))
|
|
3848
|
-
);
|
|
3644
|
+
async function stopInspector(baseUrl) {
|
|
3645
|
+
try {
|
|
3646
|
+
return await stopInspector$1(baseUrl);
|
|
3647
|
+
} catch (error) {
|
|
3648
|
+
throw toCliError2(error);
|
|
3849
3649
|
}
|
|
3850
|
-
return {
|
|
3851
|
-
baseUrl,
|
|
3852
|
-
...browserBaseUrl2 !== baseUrl ? { frontendUrl: browserBaseUrl2 } : {},
|
|
3853
|
-
hasActiveClient: startedHealth.hasActiveClient,
|
|
3854
|
-
url,
|
|
3855
|
-
started: true
|
|
3856
|
-
};
|
|
3857
3650
|
}
|
|
3858
|
-
async function
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
}
|
|
3864
|
-
if (!options.startIfNeeded) {
|
|
3865
|
-
throw operationalError(
|
|
3866
|
-
"Inspector is not running. Run `mcpjam inspector open` first or pass an Inspector-backed option that starts it."
|
|
3867
|
-
);
|
|
3651
|
+
async function fetchInspectorSessionToken(baseUrl) {
|
|
3652
|
+
try {
|
|
3653
|
+
return await fetchInspectorSessionToken$1(baseUrl);
|
|
3654
|
+
} catch (error) {
|
|
3655
|
+
throw toCliError2(error);
|
|
3868
3656
|
}
|
|
3869
|
-
await startInspector(baseUrl, options.timeoutMs ?? DEFAULT_START_TIMEOUT_MS);
|
|
3870
|
-
clearInspectorSessionTokenCache(baseUrl);
|
|
3871
|
-
const startedHealth = await getInspectorHealth(baseUrl);
|
|
3872
|
-
return {
|
|
3873
|
-
baseUrl,
|
|
3874
|
-
hasActiveClient: startedHealth.hasActiveClient,
|
|
3875
|
-
started: true
|
|
3876
|
-
};
|
|
3877
3657
|
}
|
|
3878
|
-
|
|
3879
|
-
const normalized = normalizeInspectorBaseUrl(baseUrl);
|
|
3880
|
-
if (!await isInspectorHealthy(normalized)) {
|
|
3881
|
-
return { stopped: false, baseUrl: normalized };
|
|
3882
|
-
}
|
|
3883
|
-
const fetchShutdown = async () => {
|
|
3884
|
-
const token = await fetchInspectorSessionToken(normalized);
|
|
3885
|
-
return await fetch(`${normalized}/api/shutdown`, {
|
|
3886
|
-
method: "POST",
|
|
3887
|
-
headers: {
|
|
3888
|
-
"X-MCP-Session-Auth": `Bearer ${token}`
|
|
3889
|
-
},
|
|
3890
|
-
signal: AbortSignal.timeout(STOP_FETCH_TIMEOUT_MS)
|
|
3891
|
-
});
|
|
3892
|
-
};
|
|
3658
|
+
function clearInspectorSessionTokenCache(baseUrl) {
|
|
3893
3659
|
try {
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
response = await fetchShutdown();
|
|
3898
|
-
}
|
|
3899
|
-
if (response.ok) {
|
|
3900
|
-
clearInspectorSessionTokenCache(normalized);
|
|
3901
|
-
}
|
|
3902
|
-
return { stopped: response.ok, baseUrl: normalized };
|
|
3903
|
-
} catch {
|
|
3904
|
-
return { stopped: false, baseUrl: normalized };
|
|
3660
|
+
clearInspectorSessionTokenCache$1(baseUrl);
|
|
3661
|
+
} catch (error) {
|
|
3662
|
+
throw toCliError2(error);
|
|
3905
3663
|
}
|
|
3906
3664
|
}
|
|
3907
3665
|
var InspectorApiClient = class {
|
|
@@ -4055,88 +3813,6 @@ var InspectorApiClient = class {
|
|
|
4055
3813
|
return payload;
|
|
4056
3814
|
}
|
|
4057
3815
|
};
|
|
4058
|
-
async function fetchInspectorSessionToken(baseUrl) {
|
|
4059
|
-
const normalizedBaseUrl = normalizeInspectorBaseUrl(baseUrl);
|
|
4060
|
-
const cached = tokenCache.get(normalizedBaseUrl);
|
|
4061
|
-
if (cached && Date.now() - cached.fetchedAt < TOKEN_TTL_MS) {
|
|
4062
|
-
return cached.token;
|
|
4063
|
-
}
|
|
4064
|
-
const pending = tokenRequests.get(normalizedBaseUrl);
|
|
4065
|
-
if (pending) {
|
|
4066
|
-
return pending;
|
|
4067
|
-
}
|
|
4068
|
-
const request = fetchFreshInspectorSessionToken(normalizedBaseUrl).finally(
|
|
4069
|
-
() => {
|
|
4070
|
-
tokenRequests.delete(normalizedBaseUrl);
|
|
4071
|
-
}
|
|
4072
|
-
);
|
|
4073
|
-
tokenRequests.set(normalizedBaseUrl, request);
|
|
4074
|
-
return request;
|
|
4075
|
-
}
|
|
4076
|
-
function clearInspectorSessionTokenCache(baseUrl) {
|
|
4077
|
-
if (!baseUrl) {
|
|
4078
|
-
tokenCache.clear();
|
|
4079
|
-
tokenRequests.clear();
|
|
4080
|
-
return;
|
|
4081
|
-
}
|
|
4082
|
-
const normalizedBaseUrl = normalizeInspectorBaseUrl(baseUrl);
|
|
4083
|
-
tokenCache.delete(normalizedBaseUrl);
|
|
4084
|
-
tokenRequests.delete(normalizedBaseUrl);
|
|
4085
|
-
}
|
|
4086
|
-
async function fetchFreshInspectorSessionToken(normalizedBaseUrl) {
|
|
4087
|
-
const endpoint = new URL(normalizedBaseUrl);
|
|
4088
|
-
if (!isLoopbackHostname(endpoint.hostname))
|
|
4089
|
-
throw operationalError("Inspector attachment requires a local address.");
|
|
4090
|
-
let token;
|
|
4091
|
-
try {
|
|
4092
|
-
const file2 = path3.join(
|
|
4093
|
-
os.homedir(),
|
|
4094
|
-
".mcpjam",
|
|
4095
|
-
"inspector",
|
|
4096
|
-
`${endpoint.port || "6274"}.json`
|
|
4097
|
-
);
|
|
4098
|
-
const stat2 = lstatSync(file2);
|
|
4099
|
-
if (!stat2.isFile() || process.platform !== "win32" && ((stat2.mode & 63) !== 0 || stat2.uid !== process.getuid?.()))
|
|
4100
|
-
throw new Error("Unsafe discovery file permissions");
|
|
4101
|
-
const record = JSON.parse(readFileSync(file2, "utf8"));
|
|
4102
|
-
if (record.port !== Number(endpoint.port || "6274") || !Number.isSafeInteger(record.pid) || record.pid <= 0 || typeof record.token !== "string" || !/^[A-Za-z0-9_-]{24,}$/.test(record.token))
|
|
4103
|
-
throw new Error("Invalid discovery file");
|
|
4104
|
-
process.kill(record.pid, 0);
|
|
4105
|
-
token = record.token;
|
|
4106
|
-
} catch {
|
|
4107
|
-
throw operationalError(
|
|
4108
|
-
"Cannot read this Inspector's access file. Start or restart an updated Inspector as the same user, then try again."
|
|
4109
|
-
);
|
|
4110
|
-
}
|
|
4111
|
-
let response;
|
|
4112
|
-
try {
|
|
4113
|
-
response = await fetch(`${normalizedBaseUrl}/api/session-token`, {
|
|
4114
|
-
headers: {
|
|
4115
|
-
"X-MCP-Session-Auth": `Bearer ${token}`
|
|
4116
|
-
},
|
|
4117
|
-
signal: AbortSignal.timeout(SESSION_TOKEN_TIMEOUT_MS)
|
|
4118
|
-
});
|
|
4119
|
-
} catch (error) {
|
|
4120
|
-
throw operationalError(
|
|
4121
|
-
"Failed to contact the local Inspector session-token endpoint.",
|
|
4122
|
-
error instanceof Error ? error.message : String(error)
|
|
4123
|
-
);
|
|
4124
|
-
}
|
|
4125
|
-
if (!response.ok) {
|
|
4126
|
-
throw operationalError(
|
|
4127
|
-
`Inspector session-token request failed with ${response.status}.`
|
|
4128
|
-
);
|
|
4129
|
-
}
|
|
4130
|
-
const body = await response.json();
|
|
4131
|
-
if (body.ok !== true) {
|
|
4132
|
-
throw operationalError("Inspector session-token response was invalid.");
|
|
4133
|
-
}
|
|
4134
|
-
tokenCache.set(normalizedBaseUrl, {
|
|
4135
|
-
token,
|
|
4136
|
-
fetchedAt: Date.now()
|
|
4137
|
-
});
|
|
4138
|
-
return token;
|
|
4139
|
-
}
|
|
4140
3816
|
function getInspectorStartScriptPath() {
|
|
4141
3817
|
try {
|
|
4142
3818
|
const packageJsonPath = require2.resolve("@mcpjam/inspector/package.json");
|
|
@@ -4145,273 +3821,6 @@ function getInspectorStartScriptPath() {
|
|
|
4145
3821
|
return void 0;
|
|
4146
3822
|
}
|
|
4147
3823
|
}
|
|
4148
|
-
async function getInspectorHealth(baseUrl, timeoutMs = HEALTH_FETCH_TIMEOUT_MS) {
|
|
4149
|
-
try {
|
|
4150
|
-
const response = await fetch(`${baseUrl}/health`, {
|
|
4151
|
-
signal: AbortSignal.timeout(timeoutMs)
|
|
4152
|
-
});
|
|
4153
|
-
if (!response.ok) {
|
|
4154
|
-
return { healthy: false, hasActiveClient: false };
|
|
4155
|
-
}
|
|
4156
|
-
const body = await response.json();
|
|
4157
|
-
const frontendUrl = normalizeInspectorFrontendUrl(body.frontend);
|
|
4158
|
-
return {
|
|
4159
|
-
healthy: true,
|
|
4160
|
-
hasActiveClient: body.hasActiveClient === true,
|
|
4161
|
-
...frontendUrl ? { frontendUrl } : {}
|
|
4162
|
-
};
|
|
4163
|
-
} catch {
|
|
4164
|
-
return { healthy: false, hasActiveClient: false };
|
|
4165
|
-
}
|
|
4166
|
-
}
|
|
4167
|
-
async function isInspectorFrontendUrl(baseUrl) {
|
|
4168
|
-
try {
|
|
4169
|
-
const response = await fetch(`${baseUrl}/`, {
|
|
4170
|
-
signal: AbortSignal.timeout(FRONTEND_PROBE_TIMEOUT_MS)
|
|
4171
|
-
});
|
|
4172
|
-
if (!response.ok) {
|
|
4173
|
-
return false;
|
|
4174
|
-
}
|
|
4175
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
4176
|
-
if (!contentType.toLowerCase().includes("text/html")) {
|
|
4177
|
-
return false;
|
|
4178
|
-
}
|
|
4179
|
-
const body = await response.text();
|
|
4180
|
-
return hasInspectorFrontendMarker(body) || /<title>\s*MCPJam Inspector\s*<\/title>/i.test(body) || body.includes("/mcp_jam.svg");
|
|
4181
|
-
} catch {
|
|
4182
|
-
return false;
|
|
4183
|
-
}
|
|
4184
|
-
}
|
|
4185
|
-
function hasInspectorFrontendMarker(body) {
|
|
4186
|
-
return /<meta\b(?=[^>]*\bname=["']mcpjam-inspector["'])[^>]*>/i.test(body);
|
|
4187
|
-
}
|
|
4188
|
-
async function inspectInspectorFrontendCandidate(apiBaseUrl, frontendBaseUrl, source) {
|
|
4189
|
-
const [isFrontend, originStatus] = await Promise.all([
|
|
4190
|
-
isInspectorFrontendUrl(frontendBaseUrl),
|
|
4191
|
-
getInspectorApiOriginStatus(apiBaseUrl, frontendBaseUrl)
|
|
4192
|
-
]);
|
|
4193
|
-
return {
|
|
4194
|
-
isFrontend,
|
|
4195
|
-
originStatus,
|
|
4196
|
-
source,
|
|
4197
|
-
url: frontendBaseUrl
|
|
4198
|
-
};
|
|
4199
|
-
}
|
|
4200
|
-
function isUsableInspectorFrontendCandidate(candidate) {
|
|
4201
|
-
return candidate.isFrontend && candidate.originStatus !== "rejected";
|
|
4202
|
-
}
|
|
4203
|
-
async function getInspectorApiOriginStatus(apiBaseUrl, frontendBaseUrl) {
|
|
4204
|
-
try {
|
|
4205
|
-
const origin = new URL(frontendBaseUrl).origin;
|
|
4206
|
-
const response = await fetch(`${apiBaseUrl}/api/session-token`, {
|
|
4207
|
-
headers: { Origin: origin },
|
|
4208
|
-
signal: AbortSignal.timeout(ORIGIN_PROBE_TIMEOUT_MS)
|
|
4209
|
-
});
|
|
4210
|
-
return response.status === 403 ? "rejected" : "accepted";
|
|
4211
|
-
} catch {
|
|
4212
|
-
return "unknown";
|
|
4213
|
-
}
|
|
4214
|
-
}
|
|
4215
|
-
function frontendMismatchError(advertisedCandidate, rejectedLiveCandidate) {
|
|
4216
|
-
const details = {
|
|
4217
|
-
...advertisedCandidate ? {
|
|
4218
|
-
advertisedFrontendUrl: advertisedCandidate.url,
|
|
4219
|
-
advertisedFrontendReachable: advertisedCandidate.isFrontend,
|
|
4220
|
-
advertisedOriginStatus: advertisedCandidate.originStatus
|
|
4221
|
-
} : {},
|
|
4222
|
-
...rejectedLiveCandidate ? {
|
|
4223
|
-
rejectedFrontendUrl: rejectedLiveCandidate.url,
|
|
4224
|
-
rejectedOriginStatus: rejectedLiveCandidate.originStatus
|
|
4225
|
-
} : {}
|
|
4226
|
-
};
|
|
4227
|
-
if (advertisedCandidate && rejectedLiveCandidate) {
|
|
4228
|
-
return operationalError(
|
|
4229
|
-
`Inspector backend advertises ${advertisedCandidate.url}, but no Inspector frontend responded there. A frontend was found at ${rejectedLiveCandidate.url}, but the Inspector backend rejects that origin. Start Inspector's frontend on the advertised URL or restart Inspector with matching frontend/backend ports.`,
|
|
4230
|
-
details
|
|
4231
|
-
);
|
|
4232
|
-
}
|
|
4233
|
-
if (advertisedCandidate) {
|
|
4234
|
-
return operationalError(
|
|
4235
|
-
`Inspector backend advertises ${advertisedCandidate.url}, but no Inspector frontend responded there. Start Inspector's frontend on the advertised URL or restart Inspector with matching frontend/backend ports.`,
|
|
4236
|
-
details
|
|
4237
|
-
);
|
|
4238
|
-
}
|
|
4239
|
-
return operationalError(
|
|
4240
|
-
`Inspector frontend ${rejectedLiveCandidate?.url ?? "URL"} is reachable, but the Inspector backend rejects that origin. Restart Inspector with matching frontend/backend ports.`,
|
|
4241
|
-
details
|
|
4242
|
-
);
|
|
4243
|
-
}
|
|
4244
|
-
async function discoverLocalInspectorFrontendCandidates(baseUrl, frontendUrl) {
|
|
4245
|
-
const hosts = getLocalInspectorCandidateHosts(baseUrl, frontendUrl);
|
|
4246
|
-
if (hosts.length === 0) {
|
|
4247
|
-
return [];
|
|
4248
|
-
}
|
|
4249
|
-
const protocol = getUrlProtocol(frontendUrl) ?? getUrlProtocol(baseUrl) ?? "http:";
|
|
4250
|
-
const targets = [];
|
|
4251
|
-
for (const port of getFrontendProbePorts(frontendUrl)) {
|
|
4252
|
-
for (const host of hosts) {
|
|
4253
|
-
const candidate = `${protocol}//${formatUrlHostname(host)}:${port}`;
|
|
4254
|
-
if (candidate === frontendUrl || candidate === baseUrl) {
|
|
4255
|
-
continue;
|
|
4256
|
-
}
|
|
4257
|
-
targets.push(candidate);
|
|
4258
|
-
}
|
|
4259
|
-
}
|
|
4260
|
-
const inspectedCandidates = await inspectInspectorFrontendCandidates(
|
|
4261
|
-
baseUrl,
|
|
4262
|
-
targets.map((candidate) => ({
|
|
4263
|
-
source: "discovered",
|
|
4264
|
-
url: candidate
|
|
4265
|
-
}))
|
|
4266
|
-
);
|
|
4267
|
-
return inspectedCandidates.filter((candidate) => candidate.isFrontend);
|
|
4268
|
-
}
|
|
4269
|
-
function getLocalInspectorCandidateHosts(baseUrl, frontendUrl) {
|
|
4270
|
-
const hosts = /* @__PURE__ */ new Set();
|
|
4271
|
-
for (const value of [frontendUrl, baseUrl]) {
|
|
4272
|
-
const hostname = getUrlHostname(value);
|
|
4273
|
-
if (!hostname || !isLoopbackHostname(hostname)) {
|
|
4274
|
-
continue;
|
|
4275
|
-
}
|
|
4276
|
-
hosts.add(hostname);
|
|
4277
|
-
if (hostname === "localhost") {
|
|
4278
|
-
hosts.add("127.0.0.1");
|
|
4279
|
-
}
|
|
4280
|
-
if (hostname === "127.0.0.1") {
|
|
4281
|
-
hosts.add("localhost");
|
|
4282
|
-
}
|
|
4283
|
-
}
|
|
4284
|
-
return [...hosts];
|
|
4285
|
-
}
|
|
4286
|
-
function getFrontendProbePorts(frontendUrl) {
|
|
4287
|
-
const ports = /* @__PURE__ */ new Set();
|
|
4288
|
-
const hintedPort = getUrlPort(frontendUrl);
|
|
4289
|
-
if (hintedPort) {
|
|
4290
|
-
ports.add(hintedPort);
|
|
4291
|
-
for (let offset = 1; offset <= FRONTEND_PORT_SCAN_WINDOW; offset += 1) {
|
|
4292
|
-
ports.add(hintedPort + offset);
|
|
4293
|
-
}
|
|
4294
|
-
}
|
|
4295
|
-
for (const port of WELL_KNOWN_FRONTEND_PORTS) {
|
|
4296
|
-
ports.add(port);
|
|
4297
|
-
}
|
|
4298
|
-
return [...ports].filter((port) => port > 0 && port < 65536);
|
|
4299
|
-
}
|
|
4300
|
-
function getUrlHostname(value) {
|
|
4301
|
-
if (!value) {
|
|
4302
|
-
return void 0;
|
|
4303
|
-
}
|
|
4304
|
-
try {
|
|
4305
|
-
return new URL(value).hostname.toLowerCase();
|
|
4306
|
-
} catch {
|
|
4307
|
-
return void 0;
|
|
4308
|
-
}
|
|
4309
|
-
}
|
|
4310
|
-
function getUrlProtocol(value) {
|
|
4311
|
-
if (!value) {
|
|
4312
|
-
return void 0;
|
|
4313
|
-
}
|
|
4314
|
-
try {
|
|
4315
|
-
return new URL(value).protocol;
|
|
4316
|
-
} catch {
|
|
4317
|
-
return void 0;
|
|
4318
|
-
}
|
|
4319
|
-
}
|
|
4320
|
-
function getUrlPort(value) {
|
|
4321
|
-
if (!value) {
|
|
4322
|
-
return void 0;
|
|
4323
|
-
}
|
|
4324
|
-
try {
|
|
4325
|
-
const parsed = new URL(value);
|
|
4326
|
-
const port = Number(parsed.port);
|
|
4327
|
-
return Number.isInteger(port) && port > 0 ? port : void 0;
|
|
4328
|
-
} catch {
|
|
4329
|
-
return void 0;
|
|
4330
|
-
}
|
|
4331
|
-
}
|
|
4332
|
-
function isLoopbackHostname(hostname) {
|
|
4333
|
-
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname === "[::1]";
|
|
4334
|
-
}
|
|
4335
|
-
function formatUrlHostname(hostname) {
|
|
4336
|
-
return hostname.includes(":") && !hostname.startsWith("[") ? `[${hostname}]` : hostname;
|
|
4337
|
-
}
|
|
4338
|
-
async function isInspectorHealthy(baseUrl) {
|
|
4339
|
-
const status = await getInspectorHealth(baseUrl);
|
|
4340
|
-
return status.healthy;
|
|
4341
|
-
}
|
|
4342
|
-
function getNpxExecutable(platform = process.platform) {
|
|
4343
|
-
return platform === "win32" ? "npx.cmd" : "npx";
|
|
4344
|
-
}
|
|
4345
|
-
async function startInspector(baseUrl, timeoutMs) {
|
|
4346
|
-
const parsedUrl = new URL(baseUrl);
|
|
4347
|
-
const port = parsedUrl.port || "6274";
|
|
4348
|
-
const startScriptPath = getInspectorStartScriptPath();
|
|
4349
|
-
const localStartScriptPath = startScriptPath && existsSync(startScriptPath) ? startScriptPath : void 0;
|
|
4350
|
-
const args = localStartScriptPath ? [localStartScriptPath, "--port", port, "--no-open"] : ["-y", "@mcpjam/inspector@latest", "--port", port, "--no-open"];
|
|
4351
|
-
const executable = localStartScriptPath ? process.execPath : getNpxExecutable();
|
|
4352
|
-
const logPath = getInspectorStartupLogPath();
|
|
4353
|
-
const logFd = openStartupLogFile(logPath);
|
|
4354
|
-
let child;
|
|
4355
|
-
try {
|
|
4356
|
-
child = spawn(executable, args, {
|
|
4357
|
-
cwd: localStartScriptPath ? path3.dirname(localStartScriptPath) : process.cwd(),
|
|
4358
|
-
detached: true,
|
|
4359
|
-
stdio: ["ignore", logFd, logFd],
|
|
4360
|
-
env: {
|
|
4361
|
-
...process.env,
|
|
4362
|
-
MCPJAM_SESSION_TOKEN: process.env.MCPJAM_SESSION_TOKEN ?? randomBytes(24).toString("base64url"),
|
|
4363
|
-
HOST: parsedUrl.hostname,
|
|
4364
|
-
MCPJAM_INSPECTOR_SUPPRESS_AUTO_OPEN: "1"
|
|
4365
|
-
}
|
|
4366
|
-
});
|
|
4367
|
-
} finally {
|
|
4368
|
-
closeSync(logFd);
|
|
4369
|
-
}
|
|
4370
|
-
child.unref();
|
|
4371
|
-
const startedAt = Date.now();
|
|
4372
|
-
while (Date.now() - startedAt < timeoutMs) {
|
|
4373
|
-
if (await isInspectorHealthy(baseUrl)) {
|
|
4374
|
-
return;
|
|
4375
|
-
}
|
|
4376
|
-
await delay(250);
|
|
4377
|
-
}
|
|
4378
|
-
throw operationalError(
|
|
4379
|
-
`Inspector did not become ready within ${timeoutMs}ms. Startup log: ${logPath}`
|
|
4380
|
-
);
|
|
4381
|
-
}
|
|
4382
|
-
function isAuthFailure(response) {
|
|
4383
|
-
return response.status === 401 || response.status === 403;
|
|
4384
|
-
}
|
|
4385
|
-
function getInspectorStartupLogPath() {
|
|
4386
|
-
return path3.join(os.tmpdir(), "mcpjam-inspector-startup.log");
|
|
4387
|
-
}
|
|
4388
|
-
function openStartupLogFile(logPath) {
|
|
4389
|
-
try {
|
|
4390
|
-
if (existsSync(logPath) && statSync(logPath).size > STARTUP_LOG_MAX_BYTES) {
|
|
4391
|
-
renameSync(logPath, `${logPath}.1`);
|
|
4392
|
-
}
|
|
4393
|
-
} catch {
|
|
4394
|
-
}
|
|
4395
|
-
return openSync(logPath, "a");
|
|
4396
|
-
}
|
|
4397
|
-
function openUrl(url) {
|
|
4398
|
-
if (process.env.MCPJAM_CLI_DISABLE_BROWSER_OPEN === "1") {
|
|
4399
|
-
return;
|
|
4400
|
-
}
|
|
4401
|
-
const platform = process.platform;
|
|
4402
|
-
const child = platform === "darwin" ? spawn("open", [url], { detached: true, stdio: "ignore" }) : platform === "win32" ? spawn("cmd", ["/c", "start", "", url], {
|
|
4403
|
-
detached: true,
|
|
4404
|
-
stdio: "ignore"
|
|
4405
|
-
}) : spawn("xdg-open", [url], { detached: true, stdio: "ignore" });
|
|
4406
|
-
child.on("error", () => {
|
|
4407
|
-
});
|
|
4408
|
-
child.unref();
|
|
4409
|
-
}
|
|
4410
|
-
function delay(ms) {
|
|
4411
|
-
return new Promise((resolve2) => {
|
|
4412
|
-
setTimeout(resolve2, ms);
|
|
4413
|
-
});
|
|
4414
|
-
}
|
|
4415
3824
|
async function readResponsePayload(response) {
|
|
4416
3825
|
const text = await response.text();
|
|
4417
3826
|
if (!text) {
|
|
@@ -4455,15 +3864,6 @@ function isInspectorCommandResponse(value) {
|
|
|
4455
3864
|
error && typeof error === "object" && typeof error.code === "string" && typeof error.message === "string"
|
|
4456
3865
|
);
|
|
4457
3866
|
}
|
|
4458
|
-
function buildInspectorAccessUrl(url, token) {
|
|
4459
|
-
const target = new URL(url);
|
|
4460
|
-
const tab = target.hash.slice(1);
|
|
4461
|
-
target.hash = new URLSearchParams({
|
|
4462
|
-
token,
|
|
4463
|
-
...tab ? { tab } : {}
|
|
4464
|
-
}).toString();
|
|
4465
|
-
return target.href;
|
|
4466
|
-
}
|
|
4467
3867
|
|
|
4468
3868
|
// src/lib/inspector-render.ts
|
|
4469
3869
|
async function runUiRender(options) {
|
|
@@ -25562,6 +24962,8 @@ function writeTelemetryStatus(status, format) {
|
|
|
25562
24962
|
);
|
|
25563
24963
|
}
|
|
25564
24964
|
var EVENTS_PROFILE_ALIASES = {
|
|
24965
|
+
beta: BETA_PROFILE_ID,
|
|
24966
|
+
[BETA_PROFILE_ID]: BETA_PROFILE_ID,
|
|
25565
24967
|
draft: DRAFT_PROFILE_ID,
|
|
25566
24968
|
chatgpt: CHATGPT_PROFILE_ID,
|
|
25567
24969
|
[DRAFT_PROFILE_ID]: DRAFT_PROFILE_ID,
|
|
@@ -25573,7 +24975,7 @@ function parseEventsProfile(value) {
|
|
|
25573
24975
|
const id = EVENTS_PROFILE_ALIASES[key];
|
|
25574
24976
|
if (!id) {
|
|
25575
24977
|
throw usageError(
|
|
25576
|
-
`Unknown --profile "${key}". Use "draft" (${DRAFT_PROFILE_ID}) or "chatgpt" (${CHATGPT_PROFILE_ID}).`
|
|
24978
|
+
`Unknown --profile "${key}". Use "beta" (${BETA_PROFILE_ID}), "draft" (${DRAFT_PROFILE_ID}) or "chatgpt" (${CHATGPT_PROFILE_ID}).`
|
|
25577
24979
|
);
|
|
25578
24980
|
}
|
|
25579
24981
|
return getEventsProfile(id);
|
|
@@ -25606,8 +25008,8 @@ function applyEventsProtocolVersion(config, options) {
|
|
|
25606
25008
|
}
|
|
25607
25009
|
return { ...config, mcpProtocolVersion: version };
|
|
25608
25010
|
}
|
|
25609
|
-
function eventsNotDeclaredError(support, serverLabel) {
|
|
25610
|
-
const reason = support.handshakeObserved ?
|
|
25011
|
+
function eventsNotDeclaredError(support, serverLabel, placement = "capabilities.events") {
|
|
25012
|
+
const reason = support.handshakeObserved ? `the server did not declare \`${placement}\` in its handshake` : "the server's handshake was not observed on this connection, so its events capability is unknown";
|
|
25611
25013
|
return cliError(
|
|
25612
25014
|
"EVENTS_NOT_DECLARED",
|
|
25613
25015
|
`Refusing to send events/* to ${serverLabel}: ${reason}. Pass --force to send it anyway (a conformance probe of an undeclared server).`,
|
|
@@ -25617,10 +25019,11 @@ function eventsNotDeclaredError(support, serverLabel) {
|
|
|
25617
25019
|
}
|
|
25618
25020
|
function assertEventsDeclaredOrForced(manager, serverId, args) {
|
|
25619
25021
|
const support = manager.getEventsSupport(serverId);
|
|
25620
|
-
if (!support.
|
|
25621
|
-
|
|
25022
|
+
if (!hasEventsProfileCapability(support, args.profile.id)) {
|
|
25023
|
+
const placement = args.profile.capabilityPlacement.value;
|
|
25024
|
+
if (!args.force) throw eventsNotDeclaredError(support, args.serverLabel, placement);
|
|
25622
25025
|
args.warn(
|
|
25623
|
-
|
|
25026
|
+
`Warning: the server did not declare \`${placement}\`; sending events/* anyway because of --force.`
|
|
25624
25027
|
);
|
|
25625
25028
|
}
|
|
25626
25029
|
return support;
|
|
@@ -25901,6 +25304,7 @@ async function withEventsConnection(options, ctx, fn) {
|
|
|
25901
25304
|
return withEphemeralManager(
|
|
25902
25305
|
config,
|
|
25903
25306
|
async (manager, serverId) => {
|
|
25307
|
+
if (!options.profile && manager.getEventsSupport(serverId).beta) ctx.profile = parseEventsProfile("beta");
|
|
25904
25308
|
notePeerProtocol(manager, serverId, ctx);
|
|
25905
25309
|
return fn(manager, serverId);
|
|
25906
25310
|
},
|
|
@@ -25934,8 +25338,7 @@ function addEventsTargetOptions(command) {
|
|
|
25934
25338
|
addSharedServerOptions(
|
|
25935
25339
|
command.option(
|
|
25936
25340
|
"--profile <profile>",
|
|
25937
|
-
'Events profile the run is judged by: "
|
|
25938
|
-
"draft"
|
|
25341
|
+
'Events profile the run is judged by: "beta", "draft" or "chatgpt" (default: negotiated Events version)'
|
|
25939
25342
|
).option(
|
|
25940
25343
|
"--protocol-version <version>",
|
|
25941
25344
|
"Pin the MCP protocol version (e.g. 2026-07-28). HTTP targets only."
|
|
@@ -26456,6 +25859,7 @@ function registerWatch(events) {
|
|
|
26456
25859
|
const plan = planWatchReceiver(options);
|
|
26457
25860
|
const result = await withEventsConnection(options, ctx, async (manager, serverId) => {
|
|
26458
25861
|
assertEventsDeclaredOrForced(manager, serverId, {
|
|
25862
|
+
profile: ctx.profile,
|
|
26459
25863
|
force: options.force,
|
|
26460
25864
|
serverLabel: ctx.target,
|
|
26461
25865
|
warn: ctx.warn
|
|
@@ -26510,7 +25914,7 @@ function registerWatch(events) {
|
|
|
26510
25914
|
ctx.warn(insecureModeWarning("--insecure-local-receiver", publicOrigin));
|
|
26511
25915
|
}
|
|
26512
25916
|
}
|
|
26513
|
-
const inbox = new MemoryEventInbox({ publicOrigin });
|
|
25917
|
+
const inbox = new MemoryEventInbox({ publicOrigin, independentWebhookIds: ctx.profile.id === BETA_PROFILE_ID });
|
|
26514
25918
|
receiver?.attach(inbox);
|
|
26515
25919
|
const record = {
|
|
26516
25920
|
id: `esub_cli_${randomBytes(8).toString("hex")}`,
|
|
@@ -26633,6 +26037,7 @@ function registerList(events) {
|
|
|
26633
26037
|
const ctx = buildContext(options, command);
|
|
26634
26038
|
const result = await withEventsConnection(options, ctx, async (manager, serverId) => {
|
|
26635
26039
|
const support = assertEventsDeclaredOrForced(manager, serverId, {
|
|
26040
|
+
profile: ctx.profile,
|
|
26636
26041
|
force: options.force,
|
|
26637
26042
|
serverLabel: ctx.target,
|
|
26638
26043
|
warn: ctx.warn
|
|
@@ -26674,6 +26079,7 @@ function registerPoll(events) {
|
|
|
26674
26079
|
}
|
|
26675
26080
|
const result = await withEventsConnection(options, ctx, async (manager, serverId) => {
|
|
26676
26081
|
assertEventsDeclaredOrForced(manager, serverId, {
|
|
26082
|
+
profile: ctx.profile,
|
|
26677
26083
|
force: options.force,
|
|
26678
26084
|
serverLabel: ctx.target,
|
|
26679
26085
|
warn: ctx.warn
|
|
@@ -26781,6 +26187,7 @@ function registerSubscribe(events) {
|
|
|
26781
26187
|
const secret = resolveSecret(options.secretFile, ctx);
|
|
26782
26188
|
const result = await withEventsConnection(options, ctx, async (manager, serverId) => {
|
|
26783
26189
|
assertEventsDeclaredOrForced(manager, serverId, {
|
|
26190
|
+
profile: ctx.profile,
|
|
26784
26191
|
force: options.force,
|
|
26785
26192
|
serverLabel: ctx.target,
|
|
26786
26193
|
warn: ctx.warn
|
|
@@ -26826,6 +26233,7 @@ function registerUnsubscribe(events) {
|
|
|
26826
26233
|
}
|
|
26827
26234
|
const outcome = await withEventsConnection(options, ctx, async (manager, serverId) => {
|
|
26828
26235
|
assertEventsDeclaredOrForced(manager, serverId, {
|
|
26236
|
+
profile: ctx.profile,
|
|
26829
26237
|
force: options.force,
|
|
26830
26238
|
serverLabel: ctx.target,
|
|
26831
26239
|
warn: ctx.warn
|
|
@@ -26853,8 +26261,7 @@ function registerConformance(events) {
|
|
|
26853
26261
|
"Run the profile-aware MCP Events conformance checks (MUST fails, SHOULD warns). Result JSON on stdout, a table on stderr. Exit 0 passed, 1 failed, 3 incomplete."
|
|
26854
26262
|
).option(
|
|
26855
26263
|
"--profile <profile>",
|
|
26856
|
-
'Profile to judge by: "
|
|
26857
|
-
"draft"
|
|
26264
|
+
'Profile to judge by: "beta", "draft" or "chatgpt" (default: negotiated Events version)'
|
|
26858
26265
|
).option(
|
|
26859
26266
|
"--protocol-version <version>",
|
|
26860
26267
|
"Pin the MCP protocol version (e.g. 2026-07-28). HTTP targets only."
|
|
@@ -26952,7 +26359,7 @@ function registerConformance(events) {
|
|
|
26952
26359
|
}
|
|
26953
26360
|
function registerEventsCommands(program) {
|
|
26954
26361
|
const events = program.command("events").description(
|
|
26955
|
-
"List, poll, watch, subscribe to and conformance-check MCP Events (
|
|
26362
|
+
"List, poll, watch, subscribe to and conformance-check MCP Events (poll, push and webhook)"
|
|
26956
26363
|
);
|
|
26957
26364
|
registerList(events);
|
|
26958
26365
|
registerPoll(events);
|
|
@@ -27097,7 +26504,14 @@ async function runTaskAugmentedToolCall(args) {
|
|
|
27097
26504
|
request: { signal }
|
|
27098
26505
|
});
|
|
27099
26506
|
} catch (error) {
|
|
27100
|
-
if (!signal.aborted)
|
|
26507
|
+
if (!signal.aborted) {
|
|
26508
|
+
if (isMCPTasksWireError(error)) {
|
|
26509
|
+
throw cliError("TASKS_UNSUPPORTED", error.message, 1, {
|
|
26510
|
+
wire: error.wire
|
|
26511
|
+
});
|
|
26512
|
+
}
|
|
26513
|
+
throw error;
|
|
26514
|
+
}
|
|
27101
26515
|
return {
|
|
27102
26516
|
aborted: { wire: support.wire, phase: "create" },
|
|
27103
26517
|
created: null,
|