Skip to content

[P25] skills: SEP-2640 on server and client - #346

Merged
jeanmatthieu merged 5 commits into
rel/1.0.0from
conformance/p25-skills
Nov 25, 2026
Merged

jeanmatthieu merged 5 commits into
rel/1.0.0from
conformance/p25-skills

Conversation

@jeanmatthieu

@jeanmatthieu jeanmatthieu commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor
Part P25 of P0–P35, merged into rel/1.0.0 in order (previous: P24 (#347) · next: P26 (#345))
Branch conformance/p25-skills
Base conformance/p24-tasks (stacked: GitHub retargets this PR to rel/1.0.0 when the previous part merges)
Commits 9f743bd skills: SEP-2640 on server and client
2913a8e skills: review fixes
ae20461 skills: second round of review fixes
5d2c9de skills: second-pass review fixes
b6cb899 skills: third-pass review fixes
Size 48 files, +4182 / -36

Summary

This PR implements the io.modelcontextprotocol/skills extension (SEP-2640) on both sides.

  • A server serves skills with Server.withSkills(_:listInResources:). The skills come from a
    SkillCatalog. SkillPackage checks one skill and computes its entry. InMemorySkillCatalog
    serves packages.
  • A client lists and gets skill entries. Client.loadSkill(_:options:) reads a skill's
    SKILL.md and verifies its size, its SHA-256 digest and its YAML frontmatter against the
    entry. Other files are read only when the host asks for them, and each is verified.
  • The MCP target depends on Yams (from: "6.0.0") to parse YAML frontmatter. The SDK reads
    it with the YAML 1.2 core schema, as the conformance harness does.

The conformance fixtures now declare the extension. The 3 sep-2640-* server scenarios and the
4 sep-2640-* client scenarios pass. Before this PR they were skipped. All baselines stay empty.

Motivation

SEP-2640 serves Agent Skills over MCP. A skill is a directory of files with a SKILL.md at its
root. Each file is a resource. skills/list and skills/get return entries: the URI of the
SKILL.md, its frontmatter as JSON, and a manifest of every file with a digest and a size. A
host must verify what it reads against the entry before it uses the skill.

Before this PR the SDK did not implement the extension. No fixture declared it, so the harness
skipped the 7 sep-2640-* scenarios. ROADMAP listed skills as planned.

Foundation has no YAML parser. A server must turn frontmatter into JSON, and a client must
compare the file's frontmatter with the entry field by field. Both sides must read YAML the same
way as the harness, which uses the yaml npm package (YAML 1.2, core schema).

Changes

Frontmatter parsing

  • Sources/MCP/Base/SkillFrontmatter.swift (internal, SkillFrontmatter):
    • Extraction: block(in:) gives the same match as the harness's pattern
      ^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$), after a leading byte order mark. It is a
      hand-written byte matcher, not a regular expression.
    • Parsing: Yams.compose builds the node tree. The SDK converts the tree to Value itself.
      The default schema is .core (YAML 1.2 core schema): true/True/TRUE are booleans,
      null/~/empty are null, 0o and 0x are integers; yes, 2024-01-01 and 1_000 are
      strings. A custom resolver tags plain untagged scalars, and only those get the core rules.
      .yaml11 reads the block as YAML 1.1 (as PyYAML does).
    • Refused: tags other than the core tags, a core tag whose text does not fit it, .inf and
      .nan, collection keys, and duplicate keys. Integer, boolean and null keys become strings,
      as in JavaScript.
    • Bounds: at most 64 KiB (maximumSize) and at most 10,000 nodes after alias expansion
      (maximumNodes). libyaml stops at 1000 levels of nesting.
    • Yams recurses once per level. It overflows the 512 KiB stack of a secondary thread at about
      800 levels. Parsing therefore runs on a new Thread with a 16 MiB stack
      (parsingStackSize). The caller waits on a semaphore.
    • Comparison (matches, equivalent): JSON equality. Numbers compare by value (1 equals
      1.0), key order is ignored, and a data: URL string equals the Value.data it decodes to.
  • scripts/frontmatter-corpus.mjs writes Tests/MCPTests/Generated/FrontmatterCorpus.swift. It
    loads yaml from the harness install in .build/conformance-harness (2.9.1 at this branch).
    It records the JSON of 43 frontmatter blocks and the block that the harness's pattern extracts
    from 16 documents. A block that yaml accepts only with a warning is recorded as refused.
  • Package.swift, Package.resolved: the Yams dependency (see Dependencies).

Wire types

  • Sources/MCP/Base/SkillTypes.swift:
    • ExtensionID.skills, SkillsSettings (directoryRead). SkillsSettings(_:) reads the
      declaration only when it is an object.
    • Skill: uri, frontmatter, resources, _meta. Skill.Resources is .manifest,
      .dynamic or .unrecognized(Value). A bad resources value decodes to .unrecognized, so
      one bad entry does not fail a listing. The loader refuses it. The enum is frozen.
    • The frontmatter decodes with strings as written (Value.Preserved): a data: URL stays a
      string.
    • SkillResource (uri, digest, size), with digest(of:) (sha256: prefix).
    • ListSkills and GetSkill (both CacheableResult), ReadResourceDirectory.
  • Sources/MCP/Base/Value.swift: Value.Preserved, a decodable wrapper that keeps strings as
    written at any depth.
  • Sources/MCP/Base/Messages.swift: a typed handler's result becomes a Value through
    Value.preservingStrings instead of an encode and decode round trip.

Server

  • Sources/MCP/Server/Skills.swift:
    • SkillCatalog: listSkills(cursor:), skill(uri:), readResource(uri:). Defaults:
      supportsDirectoryRead (false), readDirectory(uri:cursor:) (nil), and
      listResources(cursor:) (one SKILL.md resource per listed skill, from
      Skill.manifestResource).
    • SkillPackage: one skill, checked when it is created. It needs a UTF-8 SKILL.md at the
      root with a frontmatter name and description, a name that follows the Agent Skills rule
      and equals the last path segment, unreserved characters in the path, and relative file paths
      that stay in the skill. It allows at most 512 files and 16 MiB unless enforcesLimits is
      false. It computes the entry, SKILL.md first. init(path:directory:) reads regular files
      and skips names that start with . and links that resolve outside the directory. It checks
      the limits against the file count and sizes before it reads any file.
    • InMemorySkillCatalog (an actor): pages listings and directories, and derives directory
      resources (each skill's root and subdirectories, and the prefixes such as skill://acme).
      UTF-8 text with a textual MIME type is sent as text; other content as blob.
    • SkillListingCursor: one opaque resources/list cursor that carries the position in the
      application's listing and in the catalog's listing.
    • Server.withSkills(_:listInResources:).
  • Sources/MCP/Server/Server.swift:
    • installSkills declares extensions["io.modelcontextprotocol/skills"] (with
      directoryRead: true when the catalog supports it) and the resources capability.
    • It registers default handlers: skills/list, skills/get (-32602 for a URI that is not a
      skill), resources/directory/read (only with directory support; -32602 for a URI that is
      not a directory), resources/read (-32602, resourceNotFound) and resources/list
      (empty). The last two apply only when the application registers none.
    • The dispatch asks the catalog about a resources/read before it calls the application's
      handler, whatever the registration order.
    • resources/list with listInResources: the first page is the application's
      first page followed by the catalog's first page. Later pages continue the application's
      listing, then the catalog's. A cursor that the server did not issue, or that is not a
      string, is -32602. Without an application handler, a cursor's application position is
      ignored, so the listing still ends.
  • Sources/MCP/Server/StatelessRequests.swift: at 2026-07-28, skills/list and skills/get
    are -32601 without the declaration, and resources/directory/read without directoryRead.
    skills/list and skills/get get cache hints (cacheableMethods).

Client

  • Sources/MCP/Client/ClientSkills.swift:
    • serverSkills, listSkills(cursor:), listAllSkills() (stops at a cursor it saw
      before), getSkill(uri:) and readResourceDirectory(uri:cursor:). They throw -32601
      locally, without a request, when the server does not declare the extension (or
      directoryRead for the directory read).
    • loadSkill(_:options:) and loadSkill(uri:options:). The loader refuses an entry whose
      uri is not a SKILL.md, whose manifest does not list it, or whose resources is
      unrecognized. It checks the limits from the entry alone. Then it reads the SKILL.md only
      and verifies the size, then the digest, then the frontmatter. The frontmatter is parsed
      only after the bytes pass.
    • Client.SkillLoading: allowsDynamic, acceptsYAML11Frontmatter, enforcesLimits.
    • LoadedSkill (an actor): skill, content, rootURI, files, uri(of:), read(_:),
      read(uri:), directory(_:). read and directory resolve a relative path against the
      skill root (., / and an empty path name the root). They refuse a path that leaves the
      skill, or a file the manifest does not list, without a request. A URI is inside the root
      only when every segment after it is non-empty and percent-decodes to a name other than .
      or .. without a /. Each read is verified. Reads of a dynamic skill are not verified and count against
      16 MiB.
    • SkillVerificationError with Reason, an open struct: sizeMismatch, digestMismatch,
      frontmatterMismatch, unlistedFile, invalidEntry, dynamicSkill, tooLarge,
      unreadable.
    • Skill.manifestFingerprint: a SHA-256 over the sorted uri and digest pairs, so a host
      can bind an approval to the files it approved.

Fixtures

  • conformance/everything-server/Skills.swift, main.swift: an InMemorySkillCatalog with
    pdf-processing (nested references/, scripts/, templates/regional/) and
    acme/billing/refunds (a skill under a prefix).
  • conformance/everything-client/Skills.swift, main.swift: sep-2640-client-no-prefetch
    lists skills and reads no file. The three verify-* scenarios load each listed skill, then
    read references/FORMS.md. A skill that fails verification is refused and none of its other
    files is read.

Fuzzing

  • fuzz/Sources/FuzzFrontmatter/main.swift: parses the input as a SKILL.md with both schemas.
    Neither may crash. A parsed frontmatter must encode to JSON, decode back to an equivalent
    object, and parse the same a second time.
  • fuzz/Package.swift, scripts/ci/fuzz.sh: the new target. Seed:
    fuzz/corpus/FuzzFrontmatter/skill.md (anchors, aliases, a merge key, a block scalar).

Docs

  • design/skills.md (new), indexed in design/design.md.
  • docs/src/server.src.md, docs/src/client.src.md: a Skills section each, with snippets in
    Examples/Snippets/{Server,Client}/Skills.swift. Examples/Tests runs them at both eras.
    docs/src/README.src.md, README.src.md and the generated files follow.
  • ROADMAP.md: skills move from "Planned" to implemented. CHANGELOG.md: the feature and the
    Yams dependency. docs/src/migration.src.md: Yams in the package row and skills among the
    opt-in features. docs/src/rough_edges.src.md: a table of the implemented extensions, and the
    missing verified cache. DEPENDENCY_POLICY.md: the Yams row and note. CLAUDE.md: the code
    layout.
  • conformance/README.md: run the harness on Node 22, as CI does. On Node 26
    server-sse-multiple-streams can end the harness with an unhandled promise rejection after
    its checks pass.

Diagram

sequenceDiagram
    participant H as Host
    participant C as Client
    participant S as Server
    H->>C: loadSkill(entry)
    Note over C: check uri, manifest and limits from the entry
    C->>S: resources/read SKILL.md
    S-->>C: contents, answered from the catalog
    Note over C: size, then digest, then frontmatter
    C-->>H: LoadedSkill, or SkillVerificationError
    H->>C: read("references/FORMS.md")
    Note over C: path in the skill and listed in the manifest
    C->>S: resources/read FORMS.md
    S-->>C: contents
    Note over C: size, then digest
    C-->>H: Data, or SkillVerificationError
Loading

API changes

Added (no symbol is removed or changed):

Symbol Notes
ExtensionID.skills "io.modelcontextprotocol/skills"
SkillsSettings directoryRead; init?(_:) reads it from extensions
Skill, Skill.Resources Entry; name, description, rootURI, manifestFileName, maximumResources (512), maximumTotalSize (16 MiB), manifestResource, manifestFingerprint
SkillResource uri, digest, size; init(uri:data:), digest(of:)
ListSkills, GetSkill skills/list, skills/get; results are CacheableResult
ReadResourceDirectory resources/directory/read; directoryMimeType (inode/directory)
SkillCatalog Protocol, with defaults for supportsDirectoryRead, readDirectory(uri:cursor:), listResources(cursor:)
SkillPackage, SkillPackage.ValidationError init(path:files:scheme:enforcesLimits:), init(path:directory:scheme:enforcesLimits:), markdownMimeType
InMemorySkillCatalog Actor; init(_:pageSize:), skills, setSkills(_:)
Server.withSkills(_:listInResources:) Call before the server starts
Client.serverSkills The declared settings, or nil
Client.listSkills(cursor:), listAllSkills(), getSkill(uri:), readResourceDirectory(uri:cursor:) -32601 locally when undeclared
Client.loadSkill(_:options:), loadSkill(uri:options:), Client.SkillLoading Verified loading
LoadedSkill Actor; skill, content, rootURI, files, uri(of:), read(_:), read(uri:), directory(_:)
SkillVerificationError, SkillVerificationError.Reason Reason is an open struct with 8 values

Dependencies

Package Constraint Resolved Used by
Yams from: "6.0.0" 6.2.2 MCP
  • Why: a SKILL.md starts with YAML frontmatter. A server turns it into the JSON of an entry,
    and a client compares it with the entry before it loads the skill. Foundation has no YAML
    parser.
  • What it is used for: Yams.compose and the Node tree only. The SDK converts the tree to
    JSON itself with the YAML 1.2 core schema. Yams' own decoding resolves YAML 1.1 (yes becomes
    true, dates become Date), which would not match other implementations.
  • Yams wraps libyaml, which it compiles in as C (CYaml). It has no package dependencies.
  • 6.0.0 is the floor because it made YamlError Sendable. The SDK matches on YamlError.
  • Yams types do not appear in the public API.

Behavior changes

  • The package depends on Yams. Applications resolve packages again.
  • A typed handler's result is converted to a Value with strings as written. A data: URL
    string in a result is sent as the handler made it.
  • A server without withSkills serves no skills. At 2026-07-28 it answers skills/list,
    skills/get and resources/directory/read with -32601.
  • A server with withSkills:
    • declares the extension and the resources capability;
    • answers resources/read of a skill file from the catalog, before the application's
      handler;
    • with listInResources (the default), adds the skills' SKILL.md resources to
      resources/list and issues its own cursors. A cursor from the application's handler is no
      longer valid on its own;
    • without an application handler, answers an unknown resources/read with -32602 and
      resources/list with an empty list.

Conformance

Leg Before (P24 (#347)) server / client After server / client
--spec-version 2025-11-25 0 / 0 0 / 0
--spec-version 2026-07-28 0 / 0 0 / 0
default 0 / 0 0 / 0
  • The sep-2640-* scenarios run only in the default leg. Before this PR they were skipped,
    because no fixture declared the extension.
  • After this PR these scenarios pass:
    • server: sep-2640-skills-enumeration, sep-2640-skills-manifest,
      sep-2640-skills-directory (45 checks, none skipped);
    • client: sep-2640-client-no-prefetch, sep-2640-client-verify-digest,
      sep-2640-client-verify-size, sep-2640-client-verify-frontmatter.
  • Extension scenarios do not count toward a tier. The tier score does not change.

Tests

  • Tests/MCPTests/SkillFrontmatterTests.swift ("Skill frontmatter"): extraction against the
    16 recorded documents; YAML 1.2 core against the 43 recorded yaml results; strings and
    number kinds; missing frontmatter and non-mappings; duplicate keys; limits (block size,
    expanded nodes, nesting); YAML 1.1; comparison rules.
  • Tests/MCPTests/SkillServerTests.swift:
    • "Skill packages": the computed entry, the validation rules, limits and scheme, reading a
      directory, text and blob contents.
    • "In-memory skill catalog": pages, an invalid cursor, replacing skills; files and
      directories, prefixes included.
    • "Serving skills": the declaration in server/discover; resultType and cache hints; -32602
      for an unknown skill; resources/read order; resources/list first page and later pages,
      and a paged catalog; resources/directory/read; -32601 without the extension; the
      handshake path.
    • "Skill wire types": Skill.Resources decoding; SkillsSettings, which ignores a
      declaration that is not an object.
    • Second round of review fixes: "A directory over the limits is refused before its files are
      read"; resources/list cursors that are not strings, and an application position without
      an application handler (in "Without an application handler, unknown resources are
      -32602").
  • Tests/MCPTests/SkillClientTests.swift ("Client skills"): listing, retrieval and directories;
    loading reads SKILL.md only; size, digest and frontmatter failures; invalid entries, dynamic
    skills and limits; the root of a dynamic skill and of directory(_:) ("Inside the root: non-empty
    segments that decode, without an encoded slash or dot segment"); YAML 1.1 only when accepted; local -32601 without a request; the manifest
    fingerprint.
  • Examples/Tests: "Skill snippets" and "Client skill snippets" run the documentation snippets
    at both eras.
  • Before the last restack of the stack, swift test passed 1155 swift-testing tests in MCPTests and 108 snippet tests on macOS. An earlier run of scripts/ci-linux.sh build-test passed 1105 tests on Linux.

Review notes

  • The first resources/list page has both listings. A client that reads only the first page
    (the interop drivers, and many hosts) sees the application's resources too.
    SkillListingCursor carries both positions.
  • Each parse starts a thread and blocks the caller until it ends. The work is bounded (64 KiB,
    10,000 nodes) and happens only when a SkillPackage is created and when a skill is loaded or
    a SKILL.md is verified.
  • The Messages.swift change applies to every typed handler, not only skills. Before it, a
    result went through an encode and decode round trip.
  • The server checks resources/read against the catalog in the dispatch, not by wrapping the
    application's handler. So the registration order does not matter.
  • No other SDK implements the extension, so there is no interop profile for it.
  • Duties left to the host (approval and its revocation, the origin label, allowed-tools, name
    collisions, nested skills) are listed in design/skills.md. A verified cache is an open
    question there and in docs/rough_edges.md.

Verification

swift build
swift test
swift package generate-documentation --target MCP --warnings-as-errors
swift scripts/doc-coverage.swift
swift scripts/weave.swift --check
scripts/run-conformance.sh --spec-version 2025-11-25 --bin-path $(swift build --show-bin-path)
scripts/run-conformance.sh --spec-version 2026-07-28 --bin-path $(swift build --show-bin-path)
scripts/run-conformance.sh --bin-path $(swift build --show-bin-path)
node scripts/frontmatter-corpus.mjs && git diff --exit-code Tests/MCPTests/Generated/FrontmatterCorpus.swift
scripts/ci-linux.sh fuzz 60
  • The three conformance legs pass at their baselines (all empty). In the default leg the 7
    sep-2640-* scenarios pass.
  • frontmatter-corpus.mjs needs the harness install: run scripts/run-conformance.sh once
    first.
  • FuzzFrontmatter runs on Linux only.
  • On macOS (Node 22) scripts/ci/run-jobs.sh --strict and on Linux scripts/ci-linux.sh --strict all pass every job.

AI usage disclosure: the changes, the tests, the commit messages and this description were written with Claude Opus 5.5 and reviewed by the authors.

The io.modelcontextprotocol/skills extension. A server serves skills
from a SkillCatalog with withSkills(_:listInResources:). SkillPackage
checks one skill and computes its entry, and InMemorySkillCatalog
serves packages, with directory reads. A resources/read of a skill file
is answered before the application's handler, and the first
resources/list page has the application's first page and the skills'
first page. Typed handler results keep their strings as written.

A client lists and gets skill entries. loadSkill reads SKILL.md and
verifies its size, digest and frontmatter against the entry, and
LoadedSkill reads the other files when asked, each verified.

The MCP target depends on Yams (from 6.0.0) to parse YAML frontmatter.
The SDK reads it with the YAML 1.2 core schema, as the conformance
harness does, with bounds on size and nodes, on a thread with a 16 MiB
stack. The fixtures declare the extension, and the sep-2640-* server
and client scenarios pass. A frontmatter corpus generated from the
harness's yaml package, a fuzz target, design/skills.md and the guides.
- InMemorySkillCatalog: a cursor past the end of the listing or of a
  directory is -32602, and the page end is computed without overflow;
  a client could stop the server with skills/list cursor "1000".
- loadSkill checks the manifest's file count first, refuses a negative
  size, and sums the sizes with overflow detection, so an entry with
  huge sizes is tooLarge instead of trapping the client.
- Frontmatter: a pass over libyaml's events refuses a mapping key that
  is a collection, or an alias of one, before Yams composes; Yams
  hashed such keys with aliases expanded, so a few hundred bytes ran
  for hours.
- Frontmatter: YAML 1.1 << merges count against the node limit, so
  chained merges stop at 10,000 nodes.
- Frontmatter: an integer literal beyond a double is refused instead
  of becoming infinity, which has no JSON form.
- loadSkill parses the frontmatter in the background: the parsing
  thread resumes a continuation instead of the client actor blocking
  on a semaphore.
- InMemorySkillCatalog keeps the last package of each skill URI in
  init as in setSkills, and indexes the deduplicated list, so the
  entry, the bytes and the directories come from one package.
- SkillPackage refuses a file that is also the directory of another.
- loadSkill refuses a manifest that lists a file outside the skill's
  root, and a dynamic skill's read(uri:) refuses a URI with a . or ..
  segment, percent-encoded or not.
- Document that skill files are answered before the application's
  resources/read handler, so access checks belong in the catalog or
  the start hooks.
- Tests for each, fuzz seeds, design/skills.md and the guides.
- SkillPackage(path:files:) builds the entries from the sorted files
  instead of looking each one up again with a force unwrap.
- SkillPackage(path:directory:) lists the files and their sizes first
  and checks the 512-file and 16 MiB limits before it reads any file.
  Test: "A directory over the limits is refused before its files are
  read".
- Client.isInside refuses an empty segment (a trailing or doubled /),
  a segment that does not percent-decode, and an encoded / (%2F), as
  well as `.` and `..`. Test: "Inside the root: non-empty segments that
  decode, without an encoded slash or dot segment".
- resources/list with a cursor that is not a string (or null) is
  -32602 instead of the first page, and a cursor that names a page of
  an application listing the server does not have continues with the
  skills instead of returning the same cursor.
- SkillsSettings(_:) requires an object: an extension value of null,
  a boolean or a string declares nothing.
- LoadedSkill.directory(_:) reads ".", "/" and paths that resolve to
  the root as the root instead of throwing unlistedFile.
- loadSkill refuses an entry whose root is not a skill path: an empty,
  dot or encoded-slash segment in the root itself (invalidEntry).
- read(_:), read(uri:), uri(of:) and directory(_:) match manifest
  entries on percent-decoded segments below the root, and fetch the URI
  as the manifest lists it: servers percent-encode differently.
- listAllSkills stops after 1000 pages.
- The InMemorySkillCatalog docs and the server guide say to declare
  resources.listChanged with the list-changed notification.

- DEPENDENCY_POLICY.md: the swift-crypto note says OAuth uses it for DPoP
  proofs too, as the table row does. The note was raised on #59; it lands
  here because this branch is the last to change the lines around it.
- SkillPackage(path:directory:) applies the hidden-name rule to the
  resolved path of a link as well as to the link's own path: a link
  inside the directory to a name that starts with `.`, or to a file
  below one, is skipped like the file itself, so it is neither packaged
  nor served. Only the part below the skill directory is checked.
- file(at:) percent-decodes each URI segment on its own, and a segment
  that is empty or decodes to text with a `/` names no file, as the
  manifest encodes each component and Client.isInside(_:root:) refuses
  such a URI.
- The background-parse test tries up to 20 parses for one seen
  unfinished, so a parse that ends before the next actor hop on a loaded
  runner does not fail it. A parse that held the actor is still never
  seen unfinished.
varun06
varun06 previously approved these changes Nov 25, 2026

@varun06 varun06 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already reviewed and still looking good.

Base automatically changed from conformance/p24-tasks to rel/1.0.0 November 25, 2026 12:50
@jeanmatthieu
jeanmatthieu dismissed varun06’s stale review November 25, 2026 12:50

The base branch was changed.

@jeanmatthieu
jeanmatthieu merged commit 8acf842 into rel/1.0.0 Nov 25, 2026
@jeanmatthieu
jeanmatthieu deleted the conformance/p25-skills branch November 25, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants