Class McpSkillsBuilderExtensions
- Namespace
- ModelContextProtocol.Extensions.Skills
- Assembly
- ModelContextProtocol.Extensions.Skills.dll
Extension methods that enable MCP Skills (SEP-2640) support.
[Experimental("MCPEXP005", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp005")]
public static class McpSkillsBuilderExtensions
- Inheritance
-
McpSkillsBuilderExtensions
- Inherited Members
Methods
WithSkillFromDirectory(IMcpServerBuilder, string, McpServerSkillPackageCreateOptions?)
Authors and registers one skill directory and its resources.
[Experimental("MCPEXP005", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp005")]
public static IMcpServerBuilder WithSkillFromDirectory(this IMcpServerBuilder builder, string directoryPath, McpServerSkillPackageCreateOptions? options = null)
Parameters
builderIMcpServerBuilderThe server builder.
directoryPathstringA skill directory containing
SKILL.md.optionsMcpServerSkillPackageCreateOptionsOptional package-authoring settings.
Returns
- IMcpServerBuilder
The supplied builder.
Remarks
Authoring is synchronous and eager. See CreateFromDirectory(string, McpServerSkillPackageCreateOptions?).
WithSkillPackages(IMcpServerBuilder, IEnumerable<McpServerSkillPackage>)
Enables Skills and independently registers the resources of a fully validated package batch.
[Experimental("MCPEXP005", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp005")]
public static IMcpServerBuilder WithSkillPackages(this IMcpServerBuilder builder, IEnumerable<McpServerSkillPackage> packages)
Parameters
builderIMcpServerBuilderThe server builder.
packagesIEnumerable<McpServerSkillPackage>The authored packages to register.
Returns
- IMcpServerBuilder
The supplied builder.
Remarks
The input is fully materialized and its manifests validated before services are added. An empty batch enables Skills. Components use ordinary first-wins primitive/resource registration, independently of final collection membership. Separate calls and application resources have no package-provenance guard. Applications own manifest/content agreement after overrides. Configure runtime behavior with WithSkills(IMcpServerBuilder, Action<McpSkillsOptions>?).
Exceptions
- ArgumentNullException
builderorpackagesis null.- ArgumentException
A package is null or the batch contains conflicting file manifests.
WithSkills(IMcpServerBuilder, Action<McpSkillsOptions>?)
Enables Skills with registered primitives and optional custom request handlers.
[Experimental("MCPEXP005", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp005")]
public static IMcpServerBuilder WithSkills(this IMcpServerBuilder builder, Action<McpSkillsOptions>? configure = null)
Parameters
builderIMcpServerBuilderThe server builder.
configureAction<McpSkillsOptions>An optional callback configuring the collection and handlers.
Returns
- IMcpServerBuilder
The supplied builder.
Remarks
Calls contribute to the same McpSkillsOptions, configured in registration order. Each wire handler is installed once. A later callback can replace or clear an earlier handler; independent cursors are never composed automatically. The default handlers list and retrieve SkillCollection. Registered entries augment the initial custom list page. Registered get requests are answered directly; the custom get handler is a fallback. Typed Skills filters wrap both composed handlers in registration order, with get matching performed before filters run. The SDK validates and serializes their results.
This method registers Skills only. File resources are registered independently, directly or through WithSkillPackages(IMcpServerBuilder, IEnumerable<McpServerSkillPackage>). Removing or replacing a skill does not change resource availability. Applications own the agreement between entries and any independently registered or overridden resources.
Handlers and filters receive the existing request's services and principal. No provider or additional scope is created by Skills. Options-only Create(ITransport, McpServerOptions, ILoggerFactory?, IServiceProvider?) works without services when handlers need none. Skills requests do not pass through resource request filters; protect metadata and files with the same application policy. Server-local primitive metadata is not interpreted as authorization.
WithSkills(IMcpServerBuilder, IEnumerable<McpServerSkill>)
Enables Skills with the supplied server-side primitives.
[Experimental("MCPEXP005", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp005")]
public static IMcpServerBuilder WithSkills(this IMcpServerBuilder builder, IEnumerable<McpServerSkill> skills)
Parameters
builderIMcpServerBuilderThe server builder.
skillsIEnumerable<McpServerSkill>The primitives to add to the default collection.
Returns
- IMcpServerBuilder
The supplied builder.
Remarks
Repeated calls contribute primitives with TryAdd, as resources do. The first accepted identity wins,
without replacement. No file resources are registered. Configure runtime behavior separately through
WithSkills(IMcpServerBuilder, Action<McpSkillsOptions>?).
WithSkillsFromSubdirectories(IMcpServerBuilder, string, McpServerSkillPackageDiscoveryOptions?)
Authors and registers packages from immediate child directories containing SKILL.md.
[Experimental("MCPEXP005", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp005")]
public static IMcpServerBuilder WithSkillsFromSubdirectories(this IMcpServerBuilder builder, string directoryPath, McpServerSkillPackageDiscoveryOptions? options = null)
Parameters
builderIMcpServerBuilderThe server builder.
directoryPathstringThe parent directory whose immediate children are skill directories.
optionsMcpServerSkillPackageDiscoveryOptionsOptional common package-discovery settings.
Returns
- IMcpServerBuilder
The supplied builder.
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.
Authoring and batch validation finish before registration. See CreateFromSubdirectories(string, McpServerSkillPackageDiscoveryOptions?).