Extensions: advertised-extensions toggle in Server Settings (Phase 2 of #1633) (#1743)

* Extensions: advertised-extensions toggle in Server Settings (Phase 2 of #1633)

Adds the debugging knob from #1633: users choose which extensions the
Inspector advertises to a server, and a server may register different tools
in response. Builds on Phase 1's registry + advertisedExtensions option (#1738).

Settings + persistence (core):
- InspectorServerSettings.advertisedExtensions + StoredMCPServer field, wired
  through serverList's read/write converters and INSPECTOR_FIELD_KEY_MAP
  (omit-when-empty, byte-stable round-trip).
- validateSettings (remote PUT route): isBooleanRecord guard + carry a
  non-empty map; unknown/malformed rejected.
- App.tsx threads savedSettings.advertisedExtensions into the client options.

UI:
- ServerSettingsForm renders an "Advertised Extensions" group of checkboxes
  driven by ADVERTISABLE_EXTENSIONS; a per-server override wins over the
  registry default. Modal folds a toggle into settings.advertisedExtensions.

Test server + proof:
- composable-test-server extensionGatedTools: a tool registered disabled and
  enabled on `initialized` iff the client declared the mapped extension
  (getClientCapabilities). Legacy stateful leg. Threaded through
  load-config/resolve-config; advertised-extensions-http.json showcase + README.
- Integration test connects legacy with/without the tasks extension advertised
  and asserts the gated tool appears/disappears in tools/list — the acceptance
  criterion, proven end to end, not asserted.

Tests: serverList round-trip (non-empty/absent/empty), ServerSettingsForm
toggle rows, ServerSettingsModal fold, validateSettings accept/reject, and the
integration gating test. npm run ci green (per-file ≥90 gate held).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5

* Extensions: add #1739 proof screenshots (advertised-extensions toggle)

End-to-end smoke test in the web client against the legacy
advertised-extensions-http.json test server (port 3220): connecting with the
Tasks extension advertised (default) lists echo + get_weather, unchecking the
Advertised Extensions → Tasks toggle and reconnecting lists only echo — the
server's tool registration changing on the client-declared extension.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5

* Extensions: reconverge advertisedExtensions to no-override on default (review)

Address Phase 2 review observation #1: toggling an extension back to its
registry default now deletes the override key (and drops the whole map to
undefined when it empties), so the on-disk `advertisedExtensions` reconverges
to the byte-stable "no override" state instead of persisting a redundant
`{ key: <default> }`. Matches the omit-when-default policy the other settings
use. Only a value that differs from the default is persisted.

Adds a modal test asserting the reconvergence (re-checking the sole disabling
override drops advertisedExtensions to undefined).

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:
Cliff Hall 2026-07-22 16:23:43 -04:00 • committed by GitHub
commit fe295396af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 585 additions and 0 deletions

View file

@ -2271,6 +2271,12 @@ function App() {
savedSettings.protocolEra,
),
}),
// Per-server advertised-extension overrides (#1739). Absent/empty falls
// back to the registry defaults in the InspectorClient constructor.
...(savedSettings?.advertisedExtensions &&
Object.keys(savedSettings.advertisedExtensions).length > 0 && {
advertisedExtensions: savedSettings.advertisedExtensions,
}),
// Set on the `/oauth/callback` rebuild so the client's `saveSession`
// events (and any later persistence) key off the same OAuth authId
// the pre-redirect page saved under.

View file

@ -137,6 +137,18 @@ function InteractiveRender(args: ServerSettingsFormProps) {
settings: { ...args.settings, paginatedLists: value },
});
}}
onAdvertisedExtensionChange={(key, checked) => {
args.onAdvertisedExtensionChange(key, checked);
updateArgs({
settings: {
...args.settings,
advertisedExtensions: {
...args.settings.advertisedExtensions,
[key]: checked,
},
},
});
}}
onMaxFetchRequestsChange={(value) => {
args.onMaxFetchRequestsChange(value);
updateArgs({
@ -191,6 +203,7 @@ const meta: Meta<typeof ServerSettingsForm> = {
onTimeoutChange: fn(),
onAutoRefreshChange: fn(),
onPaginatedListsChange: fn(),
onAdvertisedExtensionChange: fn(),
onMaxFetchRequestsChange: fn(),
onProtocolEraChange: fn(),
onModernLogLevelChange: fn(),

View file

@ -66,6 +66,7 @@ const baseHandlers = {
onTimeoutChange: vi.fn(),
onAutoRefreshChange: vi.fn(),
onPaginatedListsChange: vi.fn(),
onAdvertisedExtensionChange: vi.fn(),
onMaxFetchRequestsChange: vi.fn(),
onProtocolEraChange: vi.fn(),
onModernLogLevelChange: vi.fn(),
@ -452,6 +453,62 @@ describe("ServerSettingsForm", () => {
expect(onAutoRefreshChange).toHaveBeenCalledWith(true);
});
it("renders the Advertised Extensions section with Tasks checked by default", () => {
renderWithMantine(
<ServerSettingsForm
{...baseHandlers}
settings={emptySettings}
expandedSections={["options"]}
/>,
);
const tasks = screen.getByRole("checkbox", {
name: /Tasks \(io\.modelcontextprotocol\/tasks\)/,
});
// No override present → the registry default (advertised) shows checked.
expect(tasks).toBeChecked();
});
it("reflects an advertisedExtensions override that disables Tasks", () => {
renderWithMantine(
<ServerSettingsForm
{...baseHandlers}
settings={{
...emptySettings,
advertisedExtensions: { "io.modelcontextprotocol/tasks": false },
}}
expandedSections={["options"]}
/>,
);
expect(
screen.getByRole("checkbox", {
name: /Tasks \(io\.modelcontextprotocol\/tasks\)/,
}),
).not.toBeChecked();
});
it("invokes onAdvertisedExtensionChange when a Tasks toggle is clicked", async () => {
const user = userEvent.setup();
const onAdvertisedExtensionChange = vi.fn();
renderWithMantine(
<ServerSettingsForm
{...baseHandlers}
onAdvertisedExtensionChange={onAdvertisedExtensionChange}
settings={emptySettings}
expandedSections={["options"]}
/>,
);
// Default is checked; clicking flips it to unadvertised.
await user.click(
screen.getByRole("checkbox", {
name: /Tasks \(io\.modelcontextprotocol\/tasks\)/,
}),
);
expect(onAdvertisedExtensionChange).toHaveBeenCalledWith(
"io.modelcontextprotocol/tasks",
false,
);
});
it("renders the Network Log Size field reflecting maxFetchRequests", () => {
renderWithMantine(
<ServerSettingsForm

View file

@ -26,8 +26,22 @@ import {
MODERN_LOG_LEVELS,
} from "@inspector/core/mcp/types.js";
import { isOAuthCapableServerType } from "@inspector/core/mcp/config.js";
import { ADVERTISABLE_EXTENSIONS } from "@inspector/core/mcp/extensions.js";
import type { Root } from "@modelcontextprotocol/client";
/**
* Resolve the advertised state of an extension for the form: the per-server
* override wins, else the registry default. Mirrors `buildClientExtensions`'s
* resolution so the switches show exactly what the client will advertise.
*/
function isExtensionAdvertised(
settings: InspectorServerSettings,
key: string,
defaultAdvertised: boolean,
): boolean {
return settings.advertisedExtensions?.[key] ?? defaultAdvertised;
}
export type ServerSettingsSection =
| "options"
| "environment"
@ -65,6 +79,12 @@ export interface ServerSettingsFormProps {
) => void;
onAutoRefreshChange: (value: boolean) => void;
onPaginatedListsChange: (value: boolean) => void;
/**
* Toggle whether the Inspector advertises the extension `key` to this server.
* `checked` is the new advertise state; the modal folds it into
* `settings.advertisedExtensions`. (#1739)
*/
onAdvertisedExtensionChange: (key: string, checked: boolean) => void;
onMaxFetchRequestsChange: (value: number) => void;
onProtocolEraChange: (value: ServerProtocolEra) => void;
onModernLogLevelChange: (value: ModernLogLevel) => void;
@ -272,6 +292,7 @@ export function ServerSettingsForm({
onTimeoutChange,
onAutoRefreshChange,
onPaginatedListsChange,
onAdvertisedExtensionChange,
onMaxFetchRequestsChange,
onProtocolEraChange,
onModernLogLevelChange,
@ -380,6 +401,34 @@ export function ServerSettingsForm({
checked={settings.paginatedLists ?? false}
onChange={(e) => onPaginatedListsChange(e.currentTarget.checked)}
/>
<Stack gap="xs">
<Text size="sm" fw={500}>
Advertised Extensions
</Text>
<Text size="xs" c="var(--inspector-text-secondary)">
Which extensions the Inspector declares to this server in its
client capabilities. A server may register different tools
depending on what the client advertises — toggle these to debug
that. Takes effect on the next connect.
</Text>
{ADVERTISABLE_EXTENSIONS.map((ext) => (
<Checkbox
key={ext.key}
label={ext.label}
checked={isExtensionAdvertised(
settings,
ext.key,
ext.defaultAdvertised,
)}
onChange={(e) =>
onAdvertisedExtensionChange(
ext.key,
e.currentTarget.checked,
)
}
/>
))}
</Stack>
<NumberInput
label="Network Log Size"
description="Maximum number of HTTP requests kept in the Network log for this server. Older entries rotate out past this limit; a response body that arrives after its entry rotated out is dropped. Use 0 for unlimited (not recommended). Applies immediately to the active connection."

View file

@ -162,6 +162,63 @@ describe("ServerSettingsModal", () => {
);
});
it("folds an advertised-extension toggle into settings.advertisedExtensions (#1739)", async () => {
const user = userEvent.setup();
const onSettingsChange = vi.fn();
renderWithMantine(
<ServerSettingsModal
opened
settings={emptySettings}
serverType="streamable-http"
isStdio={false}
onClose={vi.fn()}
onSettingsChange={onSettingsChange}
/>,
);
// The Options section is expanded by default; Tasks is checked (registry
// default), so clicking it toggles the override off.
await user.click(
screen.getByRole("checkbox", {
name: /Tasks \(io\.modelcontextprotocol\/tasks\)/,
}),
);
expect(onSettingsChange).toHaveBeenCalledWith(
expect.objectContaining({
advertisedExtensions: { "io.modelcontextprotocol/tasks": false },
}),
);
});
it("reconverges to no override when an extension toggle returns to its default (#1739)", async () => {
const user = userEvent.setup();
const onSettingsChange = vi.fn();
renderWithMantine(
<ServerSettingsModal
opened
// Start from a disabling override so re-checking Tasks returns it to the
// registry default (advertised) and should drop the key entirely.
settings={{
...emptySettings,
advertisedExtensions: { "io.modelcontextprotocol/tasks": false },
}}
serverType="streamable-http"
isStdio={false}
onClose={vi.fn()}
onSettingsChange={onSettingsChange}
/>,
);
await user.click(
screen.getByRole("checkbox", {
name: /Tasks \(io\.modelcontextprotocol\/tasks\)/,
}),
);
// The only override returned to its default → the whole map drops to
// undefined (no-override), keeping the on-disk round-trip minimal.
expect(onSettingsChange).toHaveBeenCalledWith(
expect.objectContaining({ advertisedExtensions: undefined }),
);
});
it("hides the modern log-level control when this server negotiated legacy under 'auto' (#1629)", () => {
renderWithMantine(
<ServerSettingsModal

View file

@ -9,6 +9,7 @@ import type {
ServerType,
} from "@inspector/core/mcp/types.js";
import { isOAuthCapableServerType } from "@inspector/core/mcp/config.js";
import { ADVERTISABLE_EXTENSIONS } from "@inspector/core/mcp/extensions.js";
import { ListToggle } from "../../elements/ListToggle/ListToggle";
import {
ServerSettingsForm,
@ -176,6 +177,24 @@ export function ServerSettingsModal({
onSettingsChange({ ...settings, paginatedLists: value });
}
function handleAdvertisedExtensionChange(key: string, checked: boolean) {
const next = { ...settings.advertisedExtensions };
const ext = ADVERTISABLE_EXTENSIONS.find((e) => e.key === key);
// Reconverge to "no override" when the toggle returns to the registry
// default, so the on-disk map (and its byte-stable round-trip) stays minimal
// — matching the omit-when-default policy used for the other settings. Only
// a value that actually differs from the default is persisted.
if (ext && checked === ext.defaultAdvertised) {
delete next[key];
} else {
next[key] = checked;
}
onSettingsChange({
...settings,
advertisedExtensions: Object.keys(next).length > 0 ? next : undefined,
});
}
function handleMaxFetchRequestsChange(value: number) {
onSettingsChange({ ...settings, maxFetchRequests: value });
}
@ -251,6 +270,7 @@ export function ServerSettingsModal({
onTimeoutChange={handleTimeoutChange}
onAutoRefreshChange={handleAutoRefreshChange}
onPaginatedListsChange={handlePaginatedListsChange}
onAdvertisedExtensionChange={handleAdvertisedExtensionChange}
onMaxFetchRequestsChange={handleMaxFetchRequestsChange}
onProtocolEraChange={handleProtocolEraChange}
onModernLogLevelChange={handleModernLogLevelChange}

View file

@ -284,6 +284,63 @@ describe("serverEntriesToMcpConfig", () => {
expect(round).toEqual(original);
});
it("round-trips advertisedExtensions: lifts a non-empty map to settings and back to disk", () => {
const original: MCPConfig = {
mcpServers: {
exttest: {
type: "streamable-http",
url: "https://x.test/mcp",
advertisedExtensions: { "io.modelcontextprotocol/tasks": false },
},
},
};
const [entry] = mcpConfigToServerEntries(original);
expect(entry?.settings?.advertisedExtensions).toEqual({
"io.modelcontextprotocol/tasks": false,
});
const round = serverEntriesToMcpConfig(mcpConfigToServerEntries(original));
expect(round).toEqual(original);
});
it("omits advertisedExtensions from disk when unset, and leaves settings unset", () => {
const original: MCPConfig = {
mcpServers: {
extnone: {
type: "streamable-http",
url: "https://x.test/mcp",
connectionTimeout: 5000,
},
},
};
const [entry] = mcpConfigToServerEntries(original);
expect(entry?.settings?.advertisedExtensions).toBeUndefined();
const round = serverEntriesToMcpConfig(mcpConfigToServerEntries(original));
expect("advertisedExtensions" in (round.mcpServers.extnone ?? {})).toBe(
false,
);
expect(round).toEqual(original);
});
it("treats an empty advertisedExtensions map on disk as unset (omitted on write)", () => {
const original: MCPConfig = {
mcpServers: {
extempty: {
type: "streamable-http",
url: "https://x.test/mcp",
advertisedExtensions: {},
},
},
};
const [entry] = mcpConfigToServerEntries(original);
// An empty map reads back as unset for the form...
expect(entry?.settings?.advertisedExtensions).toBeUndefined();
// ...and the write side omits it, so the empty map does not round-trip.
const round = serverEntriesToMcpConfig(mcpConfigToServerEntries(original));
expect("advertisedExtensions" in (round.mcpServers.extempty ?? {})).toBe(
false,
);
});
it("round-trips maxFetchRequests: lifts a non-default value to settings and back to disk", () => {
const original: MCPConfig = {
mcpServers: {

View file

@ -0,0 +1,129 @@
import { describe, it, expect, afterEach } from "vitest";
import * as z from "zod/v4";
import { InspectorClient } from "@inspector/core/mcp/inspectorClient.js";
import { createTransportNode } from "@inspector/core/mcp/node/transport.js";
import { TASKS_EXTENSION_KEY } from "@inspector/core/mcp/modernTaskSchemas.js";
import {
createTestServerHttp,
type TestServerHttp,
createTestServerInfo,
} from "@modelcontextprotocol/inspector-test-server";
/**
* Live coverage of advertised-extension gating (#1739). The Inspector advertises
* a per-server `capabilities.extensions` map (Phase 1, #1738), and a server may
* register different tools depending on what the client declared. Here a legacy
* stateful server gates a tool on the `io.modelcontextprotocol/tasks` extension:
* with the extension advertised the tool appears in `tools/list`; with it
* disabled via `advertisedExtensions` the same tool is absent. Driven against a
* real server over a real transport.
*
* A FRESH server is started per scenario on purpose: the gate's `oninitialized`
* hook only enables the tool, so a server that already saw a tasks-advertising
* client would keep it enabled for a later connection.
*/
describe("advertised-extension gating (#1739)", () => {
const GATED_TOOL = "gated_tool";
const ALWAYS_TOOL = "always_tool";
let client: InspectorClient | null = null;
const servers: TestServerHttp[] = [];
afterEach(async () => {
if (client) {
try {
await client.disconnect();
} catch {
// ignore
}
client = null;
}
while (servers.length) {
const s = servers.pop();
try {
await s?.stop();
} catch {
// ignore
}
}
});
async function startGatedServer(): Promise<TestServerHttp> {
const started = createTestServerHttp({
serverInfo: createTestServerInfo("advertised-ext-test", "1.0.0"),
tools: [
{
name: ALWAYS_TOOL,
description: "Always registered",
inputSchema: { message: z.string().optional() },
handler: async () => ({
content: [{ type: "text" as const, text: "always" }],
}),
},
{
name: GATED_TOOL,
description: "Registered only when the client declares tasks",
inputSchema: { message: z.string().optional() },
handler: async () => ({
content: [{ type: "text" as const, text: "gated" }],
}),
},
],
extensionGatedTools: { [TASKS_EXTENSION_KEY]: GATED_TOOL },
});
await started.start();
servers.push(started);
return started;
}
async function connect(
url: string,
advertisedExtensions?: Record<string, boolean>,
): Promise<InspectorClient> {
const connected = new InspectorClient(
{ type: "streamable-http", url },
{
environment: { transport: createTransportNode },
...(advertisedExtensions && { advertisedExtensions }),
},
);
await connected.connect();
client = connected;
return connected;
}
async function toolNames(connected: InspectorClient): Promise<string[]> {
const { tools } = await connected.listTools();
return tools.map((t) => t.name);
}
it("registers the gated tool when the client advertises the extension (default)", async () => {
const started = await startGatedServer();
// Default config: the Tasks extension is advertised by the registry default.
const connected = await connect(started.url);
const names = await toolNames(connected);
expect(names).toContain(ALWAYS_TOOL);
expect(names).toContain(GATED_TOOL);
});
it("registers the gated tool when the extension is explicitly advertised", async () => {
const started = await startGatedServer();
const connected = await connect(started.url, {
[TASKS_EXTENSION_KEY]: true,
});
const names = await toolNames(connected);
expect(names).toContain(GATED_TOOL);
});
it("omits the gated tool when the extension is not advertised", async () => {
const started = await startGatedServer();
// Disable the only registry extension → the client sends no extensions,
// so the server never enables the gated tool.
const connected = await connect(started.url, {
[TASKS_EXTENSION_KEY]: false,
});
const names = await toolNames(connected);
expect(names).toContain(ALWAYS_TOOL);
expect(names).not.toContain(GATED_TOOL);
});
});

View file

@ -513,6 +513,27 @@ describe("server.ts supplemental coverage", () => {
expect((await res.json()).error).toMatch(/modernLogLevel/);
});
it("rejects a non-boolean-valued advertisedExtensions (#1739)", async () => {
const res = await postSettings({
...base,
advertisedExtensions: { "io.modelcontextprotocol/tasks": "yes" },
});
expect((await res.json()).error).toMatch(/advertisedExtensions/);
});
it("rejects a non-object advertisedExtensions (#1739)", async () => {
const res = await postSettings({
...base,
advertisedExtensions: ["io.modelcontextprotocol/tasks"],
});
expect((await res.json()).error).toMatch(/advertisedExtensions/);
});
it("accepts an empty advertisedExtensions map without persisting it (#1739)", async () => {
const res = await postSettings({ ...base, advertisedExtensions: {} });
expect(res.status).toBe(200);
});
it("accepts a fully-populated valid settings payload", async () => {
const res = await postSettings({
...base,
@ -521,6 +542,7 @@ describe("server.ts supplemental coverage", () => {
taskTtl: 1000,
autoRefreshOnListChanged: true,
paginatedLists: true,
advertisedExtensions: { "io.modelcontextprotocol/tasks": false },
maxFetchRequests: 5,
protocolEra: "modern",
modernLogLevel: "off",