feat: support the Skills extension (SEP-2640) with digest verification

Adds detection, enumeration, and conformance checking for the Skills
extension (`io.modelcontextprotocol/skills`) — phases 1 and 2 of #2234,
which is everything its Acceptance list names.

Skills is a *server*-declared extension, read off the connecting server's
`capabilities.extensions`, so it is deliberately absent from
`ADVERTISABLE_EXTENSIONS` — that registry is what the Inspector advertises
and the user toggles, and an entry there would be a meaningless toggle.

`skills/list` and `skills/get` are consumer-owned extension methods that
neither era codec defines, so the SDK's era gate skips them and they go out
as ordinary `client.request` calls with explicit result schemas. The
raw-wire channel modern `tasks/*` needs is not used, and the Skills tab is
not era-gated: a legacy-era server that declares the extension is serving it.

The checks are the point, not the list view. `core/mcp/skills.ts` reports
each obligation SEP-2640 states — the name/path invariant, the digest
format, the 512-entry and 16 MiB limits, and `resources: "dynamic"`, which
means integrity cannot be verified at all. Digest verification hashes the
fetched bytes with WebCrypto and returns a mismatch with both digests
attached rather than throwing, because showing a mismatch loudly is the
whole value proposition.

Files are fetched on demand: SEP-2640 is explicit that a `resources/read`
of a `SKILL.md` is not a load and confers no standing, so none of the SEP's
host machinery is implemented.

The `skills-http` fixture serves four skills over two pages, three of them
deliberately non-conforming — without those the verification code is
untestable.

Phase 3 (CLI, TUI, `resources/directory/read`, paged mode) is #2248.

Closes #2234

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018kfrH3uRNUM4JAk1reKtyY
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-09-04 20:01:13 -04:00
commit 63623b754b

View file

@ -0,0 +1,136 @@
import { useState } from "react";
import type { ComponentProps } from "react";
import type { Meta, StoryObj } from "@storybook/react-vite";
import { expect, fn, userEvent, within } from "storybook/test";
import type { SkillEntry } from "@inspector/core/mcp/skillsSchemas";
import { SkillsScreen } from "./SkillsScreen";
import type { SkillsUiState } from "./SkillsScreen";
import { EMPTY_SKILLS_UI } from "../screenUiState";
// SkillsScreen is controlled (selection and search live in the parent as one
// `ui` object — see #1417). This wrapper holds that state so the play-driven
// clicks drive the detail pane, mirroring how App owns it in the real app.
function StatefulSkillsScreen(args: ComponentProps<typeof SkillsScreen>) {
const [ui, setUi] = useState<SkillsUiState>(args.ui ?? EMPTY_SKILLS_UI);
return <SkillsScreen {...args} ui={ui} onUiChange={setUi} />;
}
const REF_TEXT = "# Column rules\n";
// The digest of REF_TEXT, so the clean skill really does verify when the
// "Verify all" story runs — a placeholder here would demo a false green.
const REF_DIGEST =
"sha256:e201429aa2684958ca1a0537ab4eb4b7eb3a81c71e7cc7a11397eb500738e015";
const sampleSkills: SkillEntry[] = [
{
uri: "skill://data-analysis/SKILL.md",
frontmatter: {
name: "data-analysis",
description: "Analyze a CSV and summarize its columns",
},
resources: [
{
uri: "skill://data-analysis/reference.md",
digest: REF_DIGEST,
size: REF_TEXT.length,
},
],
},
{
uri: "skill://tampered-notes/SKILL.md",
frontmatter: {
name: "tampered-notes",
description: "Advertises a digest its bytes do not match",
},
resources: [
{
uri: "skill://tampered-notes/notes.md",
digest: `sha256:${"b".repeat(64)}`,
size: 12,
},
],
},
{
uri: "skill://dynamic-report/SKILL.md",
frontmatter: {
name: "dynamic-report",
description: "Generated files, so integrity cannot be verified",
},
resources: "dynamic",
},
{
uri: "skill://wrong-folder/SKILL.md",
frontmatter: {
name: "right-name",
description: "URI path segment disagrees with frontmatter.name",
},
resources: [],
},
];
const meta: Meta<typeof SkillsScreen> = {
title: "Screens/SkillsScreen",
component: SkillsScreen,
parameters: { layout: "fullscreen" },
args: {
skills: sampleSkills,
pageCount: 2,
ui: EMPTY_SKILLS_UI,
onUiChange: fn(),
onRefreshList: fn(),
onReadSkillFile: fn(async (uri: string) =>
uri.endsWith("reference.md")
? { text: REF_TEXT }
: { text: `# ${uri}\n`, mimeType: "text/markdown" },
),
},
render: (args) => <StatefulSkillsScreen {...args} />,
};
export default meta;
type Story = StoryObj<typeof SkillsScreen>;
export const Default: Story = {};
export const Empty: Story = {
args: { skills: [], pageCount: 0 },
};
export const LoadFailed: Story = {
args: { loadError: new Error("skills/list failed: -32601 Method not found") },
};
export const ConformingSkill: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getByText("data-analysis"));
await expect(canvas.getByText("Conforms")).toBeInTheDocument();
},
};
export const NameMismatch: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getByText("right-name"));
await expect(canvas.getByText("name-path-mismatch")).toBeInTheDocument();
},
};
export const DynamicResources: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getByText("dynamic-report"));
await expect(canvas.getByText("Dynamic resources")).toBeInTheDocument();
},
};
export const DigestMismatch: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getByText("tampered-notes"));
await userEvent.click(canvas.getByRole("button", { name: /Verify all/ }));
await expect(
await canvas.findByText("Digest mismatch"),
).toBeInTheDocument();
},
};