Repository navigation
[P25] skills: SEP-2640 on server and client - #346
Merged
Merged
Conversation
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.
This was referenced Nov 25, 2026
varun06
previously approved these changes
Nov 25, 2026
varun06
left a comment
Contributor
There was a problem hiding this comment.
Already reviewed and still looking good.
varun06
approved these changes
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rel/1.0.0in order (previous: P24 (#347) · next: P26 (#345))conformance/p25-skillsconformance/p24-tasks(stacked: GitHub retargets this PR torel/1.0.0when the previous part merges)9f743bdskills: SEP-2640 on server and client2913a8eskills: review fixesae20461skills: second round of review fixes5d2c9deskills: second-pass review fixesb6cb899skills: third-pass review fixesSummary
This PR implements the
io.modelcontextprotocol/skillsextension (SEP-2640) on both sides.Server.withSkills(_:listInResources:). The skills come from aSkillCatalog.SkillPackagechecks one skill and computes its entry.InMemorySkillCatalogserves packages.
Client.loadSkill(_:options:)reads a skill'sSKILL.mdand verifies its size, its SHA-256 digest and its YAML frontmatter against theentry. Other files are read only when the host asks for them, and each is verified.
MCPtarget depends on Yams (from: "6.0.0") to parse YAML frontmatter. The SDK readsit 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 the4
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.mdat itsroot. Each file is a resource.
skills/listandskills/getreturn entries: the URI of theSKILL.md, its frontmatter as JSON, and a manifest of every file with a digest and a size. Ahost 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
yamlnpm package (YAML 1.2, core schema).Changes
Frontmatter parsing
Sources/MCP/Base/SkillFrontmatter.swift(internal,SkillFrontmatter):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 ahand-written byte matcher, not a regular expression.
Yams.composebuilds the node tree. The SDK converts the tree toValueitself.The default schema is
.core(YAML 1.2 core schema):true/True/TRUEare booleans,null/~/empty are null,0oand0xare integers;yes,2024-01-01and1_000arestrings. A custom resolver tags plain untagged scalars, and only those get the core rules.
.yaml11reads the block as YAML 1.1 (as PyYAML does)..infand.nan, collection keys, and duplicate keys. Integer, boolean and null keys become strings,as in JavaScript.
maximumSize) and at most 10,000 nodes after alias expansion(
maximumNodes). libyaml stops at 1000 levels of nesting.800 levels. Parsing therefore runs on a new
Threadwith a 16 MiB stack(
parsingStackSize). The caller waits on a semaphore.matches,equivalent): JSON equality. Numbers compare by value (1equals1.0), key order is ignored, and adata:URL string equals theValue.datait decodes to.scripts/frontmatter-corpus.mjswritesTests/MCPTests/Generated/FrontmatterCorpus.swift. Itloads
yamlfrom 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
yamlaccepts 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 thedeclaration only when it is an object.
Skill:uri,frontmatter,resources,_meta.Skill.Resourcesis.manifest,.dynamicor.unrecognized(Value). A badresourcesvalue decodes to.unrecognized, soone bad entry does not fail a listing. The loader refuses it. The enum is frozen.
Value.Preserved): adata:URL stays astring.
SkillResource(uri,digest,size), withdigest(of:)(sha256:prefix).ListSkillsandGetSkill(bothCacheableResult),ReadResourceDirectory.Sources/MCP/Base/Value.swift:Value.Preserved, a decodable wrapper that keeps strings aswritten at any depth.
Sources/MCP/Base/Messages.swift: a typed handler's result becomes aValuethroughValue.preservingStringsinstead 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), andlistResources(cursor:)(oneSKILL.mdresource per listed skill, fromSkill.manifestResource).SkillPackage: one skill, checked when it is created. It needs a UTF-8SKILL.mdat theroot with a frontmatter
nameanddescription, a name that follows the Agent Skills ruleand 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
enforcesLimitsisfalse. It computes the entry,
SKILL.mdfirst.init(path:directory:)reads regular filesand skips names that start with
.and links that resolve outside the directory. It checksthe limits against the file count and sizes before it reads any file.
InMemorySkillCatalog(an actor): pages listings and directories, and derives directoryresources (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 asblob.SkillListingCursor: one opaqueresources/listcursor that carries the position in theapplication's listing and in the catalog's listing.
Server.withSkills(_:listInResources:).Sources/MCP/Server/Server.swift:installSkillsdeclaresextensions["io.modelcontextprotocol/skills"](withdirectoryRead: truewhen the catalog supports it) and theresourcescapability.skills/list,skills/get(-32602 for a URI that is not askill),
resources/directory/read(only with directory support; -32602 for a URI that isnot a directory),
resources/read(-32602,resourceNotFound) andresources/list(empty). The last two apply only when the application registers none.
resources/readbefore it calls the application'shandler, whatever the registration order.
resources/listwithlistInResources: the first page is the application'sfirst 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/listandskills/getare -32601 without the declaration, and
resources/directory/readwithoutdirectoryRead.skills/listandskills/getget cache hints (cacheableMethods).Client
Sources/MCP/Client/ClientSkills.swift:serverSkills,listSkills(cursor:),listAllSkills()(stops at a cursor it sawbefore),
getSkill(uri:)andreadResourceDirectory(uri:cursor:). They throw -32601locally, without a request, when the server does not declare the extension (or
directoryReadfor the directory read).loadSkill(_:options:)andloadSkill(uri:options:). The loader refuses an entry whoseuriis not aSKILL.md, whose manifest does not list it, or whoseresourcesisunrecognized. It checks the limits from the entry alone. Then it reads the
SKILL.mdonlyand 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(_:).readanddirectoryresolve a relative path against theskill root (
.,/and an empty path name the root). They refuse a path that leaves theskill, 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 against16 MiB.
SkillVerificationErrorwithReason, an open struct:sizeMismatch,digestMismatch,frontmatterMismatch,unlistedFile,invalidEntry,dynamicSkill,tooLarge,unreadable.Skill.manifestFingerprint: a SHA-256 over the sortedurianddigestpairs, so a hostcan bind an approval to the files it approved.
Fixtures
conformance/everything-server/Skills.swift,main.swift: anInMemorySkillCatalogwithpdf-processing(nestedreferences/,scripts/,templates/regional/) andacme/billing/refunds(a skill under a prefix).conformance/everything-client/Skills.swift,main.swift:sep-2640-client-no-prefetchlists skills and reads no file. The three
verify-*scenarios load each listed skill, thenread
references/FORMS.md. A skill that fails verification is refused and none of its otherfiles is read.
Fuzzing
fuzz/Sources/FuzzFrontmatter/main.swift: parses the input as aSKILL.mdwith 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 indesign/design.md.docs/src/server.src.md,docs/src/client.src.md: a Skills section each, with snippets inExamples/Snippets/{Server,Client}/Skills.swift.Examples/Testsruns them at both eras.docs/src/README.src.md,README.src.mdand the generated files follow.ROADMAP.md: skills move from "Planned" to implemented.CHANGELOG.md: the feature and theYams dependency.
docs/src/migration.src.md: Yams in the package row and skills among theopt-in features.
docs/src/rough_edges.src.md: a table of the implemented extensions, and themissing verified cache.
DEPENDENCY_POLICY.md: the Yams row and note.CLAUDE.md: the codelayout.
conformance/README.md: run the harness on Node 22, as CI does. On Node 26server-sse-multiple-streamscan end the harness with an unhandled promise rejection afterits 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 SkillVerificationErrorAPI changes
Added (no symbol is removed or changed):
ExtensionID.skills"io.modelcontextprotocol/skills"SkillsSettingsdirectoryRead;init?(_:)reads it fromextensionsSkill,Skill.Resourcesname,description,rootURI,manifestFileName,maximumResources(512),maximumTotalSize(16 MiB),manifestResource,manifestFingerprintSkillResourceuri,digest,size;init(uri:data:),digest(of:)ListSkills,GetSkillskills/list,skills/get; results areCacheableResultReadResourceDirectoryresources/directory/read;directoryMimeType(inode/directory)SkillCatalogsupportsDirectoryRead,readDirectory(uri:cursor:),listResources(cursor:)SkillPackage,SkillPackage.ValidationErrorinit(path:files:scheme:enforcesLimits:),init(path:directory:scheme:enforcesLimits:),markdownMimeTypeInMemorySkillCataloginit(_:pageSize:),skills,setSkills(_:)Server.withSkills(_:listInResources:)Client.serverSkillsnilClient.listSkills(cursor:),listAllSkills(),getSkill(uri:),readResourceDirectory(uri:cursor:)Client.loadSkill(_:options:),loadSkill(uri:options:),Client.SkillLoadingLoadedSkillskill,content,rootURI,files,uri(of:),read(_:),read(uri:),directory(_:)SkillVerificationError,SkillVerificationError.ReasonReasonis an open struct with 8 valuesDependencies
from: "6.0.0"MCPSKILL.mdstarts 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.
Yams.composeand theNodetree only. The SDK converts the tree toJSON itself with the YAML 1.2 core schema. Yams' own decoding resolves YAML 1.1 (
yesbecomestrue, dates becomeDate), which would not match other implementations.CYaml). It has no package dependencies.YamlErrorSendable. The SDK matches onYamlError.Behavior changes
Valuewith strings as written. Adata:URLstring in a result is sent as the handler made it.
withSkillsserves no skills. At 2026-07-28 it answersskills/list,skills/getandresources/directory/readwith -32601.withSkills:resourcescapability;resources/readof a skill file from the catalog, before the application'shandler;
listInResources(the default), adds the skills'SKILL.mdresources toresources/listand issues its own cursors. A cursor from the application's handler is nolonger valid on its own;
resources/readwith -32602 andresources/listwith an empty list.Conformance
--spec-version 2025-11-25--spec-version 2026-07-28sep-2640-*scenarios run only in the default leg. Before this PR they were skipped,because no fixture declared the extension.
sep-2640-skills-enumeration,sep-2640-skills-manifest,sep-2640-skills-directory(45 checks, none skipped);sep-2640-client-no-prefetch,sep-2640-client-verify-digest,sep-2640-client-verify-size,sep-2640-client-verify-frontmatter.Tests
Tests/MCPTests/SkillFrontmatterTests.swift("Skill frontmatter"): extraction against the16 recorded documents; YAML 1.2 core against the 43 recorded
yamlresults; strings andnumber kinds; missing frontmatter and non-mappings; duplicate keys; limits (block size,
expanded nodes, nesting); YAML 1.1; comparison rules.
Tests/MCPTests/SkillServerTests.swift:directory, text and blob contents.
directories, prefixes included.
server/discover;resultTypeand cache hints; -32602for an unknown skill;
resources/readorder;resources/listfirst page and later pages,and a paged catalog;
resources/directory/read; -32601 without the extension; thehandshake path.
Skill.Resourcesdecoding;SkillsSettings, which ignores adeclaration that is not an object.
read";
resources/listcursors that are not strings, and an application position withoutan application handler (in "Without an application handler, unknown resources are
-32602").
Tests/MCPTests/SkillClientTests.swift("Client skills"): listing, retrieval and directories;loading reads
SKILL.mdonly; size, digest and frontmatter failures; invalid entries, dynamicskills and limits; the root of a dynamic skill and of
directory(_:)("Inside the root: non-emptysegments 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 snippetsat both eras.
swift testpassed 1155 swift-testing tests inMCPTestsand 108 snippet tests on macOS. An earlier run ofscripts/ci-linux.sh build-testpassed 1105 tests on Linux.Review notes
resources/listpage has both listings. A client that reads only the first page(the interop drivers, and many hosts) sees the application's resources too.
SkillListingCursorcarries both positions.10,000 nodes) and happens only when a
SkillPackageis created and when a skill is loaded ora
SKILL.mdis verified.Messages.swiftchange applies to every typed handler, not only skills. Before it, aresult went through an encode and decode round trip.
resources/readagainst the catalog in the dispatch, not by wrapping theapplication's handler. So the registration order does not matter.
allowed-tools, namecollisions, nested skills) are listed in
design/skills.md. A verified cache is an openquestion there and in
docs/rough_edges.md.Verification
sep-2640-*scenarios pass.frontmatter-corpus.mjsneeds the harness install: runscripts/run-conformance.shoncefirst.
FuzzFrontmatterruns on Linux only.scripts/ci/run-jobs.sh --strictand on Linuxscripts/ci-linux.sh --strict allpass 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.