Class McpServerSkillPackage
- Namespace
- ModelContextProtocol.Extensions.Skills
- Assembly
- ModelContextProtocol.Extensions.Skills.dll
Represents an authored skill and the ordinary resources serving its files.
[Experimental("MCPEXP005", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp005")]
public sealed class McpServerSkillPackage
- Inheritance
-
McpServerSkillPackage
- Inherited Members
Remarks
The specification requires a skill's manifest to carry the SHA-256 digest and size of every file, and a host refuses content whose bytes do not match. Building a skill through Create(IEnumerable<McpServerSkillFile>, McpServerSkillPackageCreateOptions?) or CreateFromDirectory(string, McpServerSkillPackageCreateOptions?) computes the manifest from the same bytes the resources serve. Applications must keep later entry mutations consistent with those resources.
Factories without explicit frontmatter read the frontmatter with the SDK's built-in reader and reject unsupported or malformed input rather than publish guessed metadata. The reader handles a bounded subset of YAML: block mappings and sequences, plain, quoted and block scalars, single-line flow collections, and comments. Explicitly supplied frontmatter supports YAML the reader does not understand; see Frontmatter for what they check and what remains the caller's responsibility.
Factories capture their options settings, but may retain supplied frontmatter, entry metadata, and local metadata references. Applications own mutations to those shared objects.
Authoring has no registration side effects. Register both components with WithSkillPackages(IMcpServerBuilder, IEnumerable<McpServerSkillPackage>), or register Skill and Resources independently. Application overrides own their resulting manifest/content agreement.
Properties
Resources
Gets the read-only collection of resources serving the authored files.
public IReadOnlyList<McpServerResource> Resources { get; }
Property Value
Remarks
The resource implementations serve the same owned bytes used to compute the skill's manifest. Textual MIME types use TextResourceContents when the bytes decode losslessly as UTF-8; other content uses BlobResourceContents. Registering or removing these resources is independent of registering or removing Skill.
Skill
Gets the authored skill primitive.
public McpServerSkill Skill { get; }
Property Value
Methods
Create(IEnumerable<McpServerSkillFile>, McpServerSkillPackageCreateOptions?)
Creates a skill from its files, computing the manifest from the bytes that its resources serve.
public static McpServerSkillPackage Create(IEnumerable<McpServerSkillFile> files, McpServerSkillPackageCreateOptions? options = null)
Parameters
filesIEnumerable<McpServerSkillFile>The skill's files. Exactly one must have the path
SKILL.md.optionsMcpServerSkillPackageCreateOptionsOptional URI, frontmatter, and metadata customization.
Returns
- McpServerSkillPackage
The authored skill package.
Remarks
By default, the SDK reads frontmatter from SKILL.md and derives the URI from its name.
Use Frontmatter for YAML the reader does not support.
File bytes are owned by the package. Keep entries consistent with the authored resources when making changes.
Exceptions
- ArgumentNullException
filesis null.- ArgumentException
filesomitsSKILL.mdor contains a duplicate or unsafe path; or theSKILL.mdfrontmatter cannot be read (it is malformed or uses YAML the reader does not support) or is missing a required field; or the options do not match the files.
CreateFromDirectory(string, McpServerSkillPackageCreateOptions?)
Creates a skill from a directory's selected files, snapshotting their bytes and computing the manifest.
public static McpServerSkillPackage CreateFromDirectory(string directoryPath, McpServerSkillPackageCreateOptions? options = null)
Parameters
directoryPathstringThe skill's root directory. It must contain a
SKILL.md.optionsMcpServerSkillPackageCreateOptionsOptional URI, frontmatter, metadata, and hidden/system-file selection.
Returns
- McpServerSkillPackage
The authored skill package.
Remarks
Files are read once, when this method is called. Changes on disk afterwards are not reflected in the manifest or the served content.
Every selected file is eagerly read and retained. This convenience API has no file-count, total-byte, or deadline budget and is intended for application-controlled directories. For bounded or untrusted inputs, perform bounded reads in application code and pass the selected files to Create(IEnumerable<McpServerSkillFile>, McpServerSkillPackageCreateOptions?). The specification recommends that servers stay within 512 files and 16 MiB per skill for portability, but the SDK does not enforce those thresholds as maximums.
Dot-prefixed, hidden, and system files and directories are excluded before reading or descending into them. Set IncludeHiddenAndSystemFiles to include them explicitly, or use Create(IEnumerable<McpServerSkillFile>, McpServerSkillPackageCreateOptions?) with an explicit file selection.
Links are not followed. A symbolic link inside the directory could point outside it and publish a file under a URI that appears to belong to the skill, so encountering one is an error. Replace the link with a regular file or directory, or build the skill with Create(IEnumerable<McpServerSkillFile>, McpServerSkillPackageCreateOptions?) and explicit files.
Exceptions
- ArgumentNullException
directoryPathis null.- DirectoryNotFoundException
directoryPathdoes not exist.- IOException
A file cannot be read or changes size while it is being snapshotted.
- ArgumentException
The directory's contents do not form a valid skill (see Create(IEnumerable<McpServerSkillFile>, McpServerSkillPackageCreateOptions?)), or the directory contains a symbolic link or other reparse point.
CreateFromSubdirectories(string, McpServerSkillPackageDiscoveryOptions?)
Authors packages from the immediate child directories containing SKILL.md.
public static IReadOnlyList<McpServerSkillPackage> CreateFromSubdirectories(string directoryPath, McpServerSkillPackageDiscoveryOptions? options = null)
Parameters
directoryPathstringThe parent directory whose immediate children are skill directories.
optionsMcpServerSkillPackageDiscoveryOptionsOptional common URI prefix, file selection, and metadata.
Returns
- IReadOnlyList<McpServerSkillPackage>
A fully authored, read-only list of packages in ordinal child-directory order.
Remarks
Discovery does not search deeper directories for additional skills. Each selected directory's files are
collected recursively, but a nested SKILL.md is a file of that skill, not an additional registration.
Shared file URIs must have agreeing digest and size across the complete batch, including duplicate skill
identities. The factories do not register services, read files again to compare packages, or mutate options.
Exceptions
- ArgumentNullException
directoryPathis null.- DirectoryNotFoundException
directoryPathdoes not exist.- ArgumentException
No skills are found, a skill is invalid, or package manifests conflict.