feat(web): display negotiated MCP protocol version on ServerCard (#1324) (#1442)

* feat(web): show negotiated MCP protocol version on ServerCard (#1324)

Add optional protocolVersion to ConnectionState and render it as a
dimmed "MCP <version>" label at the end of the transport-badge/
description row on ServerCard, shown only when connected. The value
is plumbed through useInspectorClient as part of #1324.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(core,web): surface negotiated protocolVersion end-to-end (#1324)

Plumb the MCP protocol version negotiated during initialize from the
InspectorClient through to the ServerCard so the active connected card
displays "MCP <version>".

The SDK Client doesn't expose protocolVersion; it stamps it onto the
transport via setProtocolVersion. MessageTrackingTransport now captures
it (and forwards to the base transport when present), so it works for
stdio too — whose base transport has no setProtocolVersion.

- core: MessageTrackingTransport captures + exposes protocolVersion;
  InspectorClient stores it, exposes getProtocolVersion(), dispatches a
  protocolVersionChange event, and clears it on disconnect.
- core: useInspectorClient subscribes and returns protocolVersion.
- web: App reads it from the hook (drops the hard-coded "2025-06-18")
  and InspectorView splices it onto the active server's connection.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* refactor(web): decouple initializeResult from protocolVersion (#1324 review)

Gate the initializeResult memo on serverInfo only, not protocolVersion.
initializeResult also drives the connected ViewHeader and Connection Info
modal, so requiring the version risked hiding the whole connected surface
in the edge case where it's absent. protocolVersion now flows through as
the optional field it already is everywhere downstream ('' reads as
unknown; the ServerCard label and modal value both tolerate it).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* refactor(web): drop redundant connected-check in InspectorView splice (#1324 review)

initializeResult is derived from connectionStatus in App's memo, so a
truthy initializeResult.protocolVersion already implies a live
connection — the extra connectionStatus === 'connected' guard in the
splice was redundant. ServerCard keeps its own status guard (dumb-
component robustness). No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cliff Hall 2026-06-08 07:40:02 -04:00 • committed by GitHub
commit 9b558afee1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 273 additions and 12 deletions

View file

@ -9,6 +9,8 @@ class FakeTransport implements Transport {
onmessage?: (message: JSONRPCMessage) => void;
onclose?: () => void;
onerror?: (error: Error) => void;
// Optional on the SDK Transport interface; stdio omits it, HTTP defines it.
setProtocolVersion?: (version: string) => void;
async start(): Promise<void> {}
async send(message: JSONRPCMessage): Promise<void> {
this.sent.push(message);
@ -120,3 +122,32 @@ describe("MessageTrackingTransport.onmessage", () => {
expect(handler).toHaveBeenCalledTimes(3);
});
});
describe("MessageTrackingTransport.setProtocolVersion", () => {
it("captures the negotiated version and exposes it via protocolVersion", () => {
const { tracked } = makeTracked();
expect(tracked.protocolVersion).toBeUndefined();
tracked.setProtocolVersion("2025-06-18");
expect(tracked.protocolVersion).toBe("2025-06-18");
});
it("forwards to the base transport's setProtocolVersion when present", () => {
const base = new FakeTransport();
const baseSet = vi.fn();
// stdio-style transports omit setProtocolVersion; HTTP transports define
// it to stamp the version into later request headers — forward to those.
base.setProtocolVersion = baseSet;
const tracked = new MessageTrackingTransport(base, {});
tracked.setProtocolVersion("2025-06-18");
expect(baseSet).toHaveBeenCalledWith("2025-06-18");
expect(tracked.protocolVersion).toBe("2025-06-18");
});
it("captures even when the base transport has no setProtocolVersion", () => {
// FakeTransport (like stdio) has no setProtocolVersion — must not throw.
const { tracked, base } = makeTracked();
expect(base.setProtocolVersion).toBeUndefined();
expect(() => tracked.setProtocolVersion("2025-06-18")).not.toThrow();
expect(tracked.protocolVersion).toBe("2025-06-18");
});
});

View file

@ -19,12 +19,14 @@ describe("useInspectorClient", () => {
capabilities: CAPABILITIES,
serverInfo: SERVER_INFO,
instructions: "hello",
protocolVersion: "2025-06-18",
});
const { result } = renderHook(() => useInspectorClient(client));
expect(result.current.status).toBe("connected");
expect(result.current.capabilities).toEqual(CAPABILITIES);
expect(result.current.serverInfo).toEqual(SERVER_INFO);
expect(result.current.instructions).toBe("hello");
expect(result.current.protocolVersion).toBe("2025-06-18");
expect(result.current.appRendererClient).toBeNull();
});
@ -34,6 +36,7 @@ describe("useInspectorClient", () => {
expect(result.current.capabilities).toBeUndefined();
expect(result.current.serverInfo).toBeUndefined();
expect(result.current.instructions).toBeUndefined();
expect(result.current.protocolVersion).toBeUndefined();
expect(result.current.appRendererClient).toBeNull();
});
@ -64,6 +67,16 @@ describe("useInspectorClient", () => {
expect(result.current.instructions).toBe("after");
});
it("subscribes to protocolVersionChange and updates", () => {
const client = new FakeInspectorClient();
const { result } = renderHook(() => useInspectorClient(client));
expect(result.current.protocolVersion).toBeUndefined();
act(() => {
client.setProtocolVersion("2025-06-18");
});
expect(result.current.protocolVersion).toBe("2025-06-18");
});
it("connect() and disconnect() proxy to the client and update status", async () => {
const client = new FakeInspectorClient();
const { result } = renderHook(() => useInspectorClient(client));

View file

@ -673,6 +673,28 @@ describe("InspectorClient", () => {
expect(client.getServerInfo()).toBeDefined();
});
it("exposes the negotiated protocol version after connect (stdio)", async () => {
client = new InspectorClient(
{
type: "stdio",
command: serverCommand.command,
args: serverCommand.args,
},
{
environment: { transport: createTransportNode },
},
);
expect(client.getProtocolVersion()).toBeUndefined();
await client.connect();
// stdio transports don't store the version themselves; the capture
// happens in MessageTrackingTransport, so this also guards that path.
expect(client.getProtocolVersion()).toMatch(/^\d{4}-\d{2}-\d{2}$/);
await client.disconnect();
expect(client.getProtocolVersion()).toBeUndefined();
});
it("should not auto-fetch server contents when disabled", async () => {
client = new InspectorClient(
{