Era-aware connection model & capability gating (#1626) (#1697)
Some checks failed
Run install, format, lint, build, and test on every push / build (push) Has been cancelled
Run install, format, lint, build, and test on every push / publish (push) Has been cancelled
Run install, format, lint, build, and test on every push / publish-github-container-registry (push) Has been cancelled
Some checks failed
Run install, format, lint, build, and test on every push / build (push) Has been cancelled
Run install, format, lint, build, and test on every push / publish (push) Has been cancelled
Run install, format, lint, build, and test on every push / publish-github-container-registry (push) Has been cancelled
* Era-aware connection model & capability gating (#1626) Make protocol era (SEP §7.8) a first-class, per-server connection dimension, orthogonal to the transport type, and drive the SDK Client's versionNegotiation from it. Config - Add `ServerProtocolEra` ("legacy" | "auto" | "modern"), `DEFAULT_PROTOCOL_ERA` (legacy, per the SDK's don't-auto-probe guidance), `MODERN_PROTOCOL_VERSION`, and `eraToVersionNegotiation()` in core/mcp/types.ts. - Persist `protocolEra` on `StoredMCPServer` / `InspectorServerSettings`, round-tripping through serverList.ts (omitting the default on disk) and the `/api/servers` read + write validators. InspectorClient / state - Thread `versionNegotiation` through `InspectorClientOptions` (default legacy), replacing the hardcoded pin. After connect, read `getProtocolEra()` / `getDiscoverResult()` / `getNegotiatedProtocolVersion()`, expose them via getters, dispatch `protocolEraChange` / `discoverResultChange`, and clear on disconnect. `useInspectorClient` surfaces `protocolEra` / `discoverResult`. Web UI - ServerSettingsForm: a Protocol Era selector bound to the per-server setting. - ConnectionInfoContent: era-aware — Era badge, Session ("Sessionless" on modern), and a Discovery section (supported versions + extensions) from the `server/discover` result. CLI/TUI also map the mcp.json `protocolEra` into versionNegotiation so the field applies uniformly. Version negotiation stays fully client-side; modern connect works over the existing remote tunnel and disconnect is sessionless (the SDK skips DELETE when there is no session id). Mcp-* header fidelity is left to the History/Network card. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Address @claude review: era docstrings, era validation, stdio session label, AGENTS.md rule - Fix stale docstrings/comments in inspectorClient.ts, useInspectorClient.ts, inspectorClientEventTarget.ts, and ConnectionInfoContent.tsx: getProtocolEra() returns "legacy" (not undefined) on a plain legacy connect; it is undefined only when not connected. - Validate protocolEra at the storedFieldsToInspectorSettings read boundary (new shared isProtocolEra guard) so a hand-edited mcp.json read directly by the CLI/TUI drops an unknown era instead of passing it to eraToVersionNegotiation. Keeps the exhaustive switch intact. - ConnectionInfoContent: the Session row is HTTP-only — show "N/A (stdio)" for stdio instead of the misleading "Session-based". - AGENTS.md: add a rule against unjustified `as unknown as` double casts, and drop the one such cast introduced in the serverList test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Address re-review: dedupe isProtocolEra guard in remote server Replace the local isProtocolEra in remote/node/server.ts with the shared guard now exported from serverList.ts (already imported here), so the era literal set lives in one place and can't drift. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7fecebed5e
commit
e026051b47
1 changed files with 808 additions and 16 deletions
|
|
@ -84,6 +84,8 @@ import type {
|
|||
RequestOptions,
|
||||
ProgressCallback,
|
||||
VersionNegotiationOptions,
|
||||
ProtocolEra,
|
||||
DiscoverResult,
|
||||
} from "@modelcontextprotocol/client";
|
||||
import { ProtocolError, ProtocolErrorCode } from "@modelcontextprotocol/client";
|
||||
import {
|
||||
|
|
@ -247,6 +249,7 @@ export class InspectorClient extends InspectorClientEventTarget {
|
|||
private requestTimeout: number | undefined;
|
||||
private defaultMetadata: Record<string, string> | undefined;
|
||||
private serverSettings: InspectorServerSettings | undefined;
|
||||
private versionNegotiation: VersionNegotiationOptions;
|
||||
private status: ConnectionStatus = "disconnected";
|
||||
// True only while an explicit disconnect() owns the teardown. close() can
|
||||
// trigger the transport's onclose synchronously, so this lets onclose defer
|
||||
|
|
@ -258,6 +261,12 @@ export class InspectorClient extends InspectorClientEventTarget {
|
|||
private serverInfo?: Implementation;
|
||||
private instructions?: string;
|
||||
private protocolVersion?: string;
|
||||
// Era model (SEP §7.8). Populated after connect from the SDK Client's
|
||||
// negotiation accessors. `protocolEra` is the negotiated era ("legacy" |
|
||||
// "modern"); `discoverResult` is the `server/discover` payload on a
|
||||
// probed/pinned connection (undefined on a plain legacy connect).
|
||||
private protocolEra?: ProtocolEra;
|
||||
private discoverResult?: DiscoverResult;
|
||||
// The capabilities this Inspector client advertises to the server during the
|
||||
// initialize handshake. Built once in setupClient() and snapshotted here so
|
||||
// UI surfaces (Server Info modal) can display them without poking at the
|
||||
|
|
@ -341,6 +350,9 @@ export class InspectorClient extends InspectorClientEventTarget {
|
|||
? options.defaultMetadata
|
||||
: undefined;
|
||||
this.serverSettings = options.serverSettings;
|
||||
// Default to the legacy 2025-11-25 era when the caller doesn't pin one, per
|
||||
// the SDK guidance that a debugging tool must not auto-probe (#1626).
|
||||
this.versionNegotiation = options.versionNegotiation ?? { mode: "legacy" };
|
||||
this.directAuthRecovery = options.directAuthRecovery ?? false;
|
||||
// Only set roots if explicitly provided (even if empty array) - this enables roots capability
|
||||
this.roots = options.roots;
|
||||
|
|
@ -392,10 +404,11 @@ export class InspectorClient extends InspectorClientEventTarget {
|
|||
capabilities?: ClientCapabilities;
|
||||
versionNegotiation?: VersionNegotiationOptions;
|
||||
} = {
|
||||
// Pin to the legacy (2025-11-25) protocol so this migration stays
|
||||
// behavior-neutral: nothing 2026-era goes on the wire. Era/version
|
||||
// selection becomes per-server configuration in a later card.
|
||||
versionNegotiation: { mode: "legacy" },
|
||||
// Per-server protocol era (SEP §7.8), threaded from config via
|
||||
// `eraToVersionNegotiation` and defaulted to `{ mode: "legacy" }` in the
|
||||
// constructor. "legacy" keeps the wire byte-identical to a 2025 client;
|
||||
// "auto"/"modern" opt into 2026-era negotiation (#1626).
|
||||
versionNegotiation: this.versionNegotiation,
|
||||
};
|
||||
const capabilities: ClientCapabilities = {};
|
||||
if (this.sample) {
|
||||
|
|
@ -1450,6 +1463,8 @@ export class InspectorClient extends InspectorClientEventTarget {
|
|||
this.serverInfo = undefined;
|
||||
this.instructions = undefined;
|
||||
this.protocolVersion = undefined;
|
||||
this.protocolEra = undefined;
|
||||
this.discoverResult = undefined;
|
||||
this.dispatchTypedEvent("pendingSamplesChange", this.pendingSamples);
|
||||
this.dispatchTypedEvent(
|
||||
"pendingElicitationsChange",
|
||||
|
|
@ -1459,6 +1474,8 @@ export class InspectorClient extends InspectorClientEventTarget {
|
|||
this.dispatchTypedEvent("serverInfoChange", this.serverInfo);
|
||||
this.dispatchTypedEvent("instructionsChange", this.instructions);
|
||||
this.dispatchTypedEvent("protocolVersionChange", this.protocolVersion);
|
||||
this.dispatchTypedEvent("protocolEraChange", this.protocolEra);
|
||||
this.dispatchTypedEvent("discoverResultChange", this.discoverResult);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1757,13 +1774,38 @@ export class InspectorClient extends InspectorClientEventTarget {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the MCP protocol version negotiated with the server during the
|
||||
* initialize handshake (e.g. "2025-06-18"). Undefined when not connected.
|
||||
* Get the MCP protocol version negotiated with the server. On a legacy
|
||||
* connect this is the version from the initialize handshake (e.g.
|
||||
* "2025-06-18"); on a modern connect it's the negotiated modern revision.
|
||||
* Undefined when not connected.
|
||||
*/
|
||||
getProtocolVersion(): string | undefined {
|
||||
return this.protocolVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* The protocol era negotiated with the server (SEP §7.8): `"legacy"` for the
|
||||
* 2025-11-25 initialize handshake, `"modern"` for the 2026-era sessionless
|
||||
* model. Populated for every era once connected — including a plain legacy
|
||||
* (`mode: "legacy"`) connect, which the SDK reports as `"legacy"`. Undefined
|
||||
* only when not connected (before connect / after disconnect). (#1626)
|
||||
*/
|
||||
getProtocolEra(): ProtocolEra | undefined {
|
||||
return this.protocolEra;
|
||||
}
|
||||
|
||||
/**
|
||||
* The `server/discover` result captured on a probed (`"auto"`) or pinned
|
||||
* (`"modern"`) connect — server identity, capabilities, and supported
|
||||
* versions learned up front without an initialize handshake. Undefined when
|
||||
* not connected or on a plain legacy connect. Persistable and feedable back
|
||||
* to the SDK as `connect(transport, { prior })` for a zero-round-trip
|
||||
* reconnect. (#1626)
|
||||
*/
|
||||
getDiscoverResult(): DiscoverResult | undefined {
|
||||
return this.discoverResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* The per-server settings this client was constructed with (headers,
|
||||
* timeouts, roots, OAuth, the auto-refresh-on-list-changed option, etc.).
|
||||
|
|
@ -2914,13 +2956,20 @@ export class InspectorClient extends InspectorClientEventTarget {
|
|||
this.dispatchTypedEvent("instructionsChange", this.instructions);
|
||||
}
|
||||
|
||||
// The negotiated protocol version isn't exposed by the SDK Client; it's
|
||||
// stamped onto the transport during initialize. MessageTrackingTransport
|
||||
// captures it (see its setProtocolVersion) so we can surface it here.
|
||||
if (this.transport instanceof MessageTrackingTransport) {
|
||||
this.protocolVersion = this.transport.protocolVersion;
|
||||
this.dispatchTypedEvent("protocolVersionChange", this.protocolVersion);
|
||||
}
|
||||
// Era model (SEP §7.8): the SDK Client owns negotiation and exposes the
|
||||
// outcome. `getProtocolEra()` is populated for every era once connected —
|
||||
// a plain legacy connect reports `"legacy"`. `getDiscoverResult()` is
|
||||
// populated only when "auto"/"modern" actually probed server/discover.
|
||||
this.protocolEra = this.client.getProtocolEra();
|
||||
this.dispatchTypedEvent("protocolEraChange", this.protocolEra);
|
||||
this.discoverResult = this.client.getDiscoverResult();
|
||||
this.dispatchTypedEvent("discoverResultChange", this.discoverResult);
|
||||
|
||||
// The SDK's negotiated-version accessor works for both eras (the
|
||||
// initialize handshake on legacy, the discover/pin on modern), so it
|
||||
// supersedes the older MessageTrackingTransport capture.
|
||||
this.protocolVersion = this.client.getNegotiatedProtocolVersion();
|
||||
this.dispatchTypedEvent("protocolVersionChange", this.protocolVersion);
|
||||
} catch {
|
||||
// Ignore errors in fetching server info
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue