Class McpServerSkill
- Namespace
- ModelContextProtocol.Extensions.Skills
- Assembly
- ModelContextProtocol.Extensions.Skills.dll
Represents a registered skill with an optional listing entry and a get operation.
[Experimental("MCPEXP005", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp005")]
public abstract class McpServerSkill : IMcpServerPrimitive
- Inheritance
-
McpServerSkill
- Implements
- Inherited Members
Remarks
File authoring is provided by McpServerSkillPackage. Register skills and file resources independently, or register both components with WithSkillPackages(IMcpServerBuilder, IEnumerable<McpServerSkillPackage>).
Constructors
McpServerSkill(string)
Initializes a registration with a stable skill URI.
protected McpServerSkill(string uri)
Parameters
uristringThe URI of the skill's
SKILL.md.
Exceptions
- ArgumentNullException
uriis null.- ArgumentException
uriis not a valid skill URI.
Properties
Id
Gets the skill's immutable identity: the exact URI text of its SKILL.md.
public string Id { get; }
Property Value
Metadata
Gets the server-local metadata associated with this primitive.
public virtual IReadOnlyList<object> Metadata { get; }
Property Value
Remarks
Metadata is not serialized, copied to file resources, or interpreted as authorization. Applications can inspect it on the collection and through the matched primitive in GetSkillFilters.
ProtocolSkill
Gets the complete entry contributed to listings, or null to omit this registration.
public virtual Skill? ProtocolSkill { get; }
Property Value
Remarks
Listing reads this property without invoking GetAsync(RequestContext<GetSkillRequestParams>, CancellationToken). A null value does not prevent direct retrieval. Use ListSkillsHandler for request-dependent listings.
Methods
Create(Skill, IReadOnlyList<object>?)
Creates a fixed primitive by validating an existing entry.
public static McpServerSkill Create(Skill protocolSkill, IReadOnlyList<object>? metadata = null)
Parameters
protocolSkillSkillThe protocol entry.
metadataIReadOnlyList<object>Optional server-local metadata.
Returns
- McpServerSkill
The fixed skill primitive.
Remarks
Keep the entry's URI consistent with the immutable registration identity. No file resources are created; the application serves them separately.
Exceptions
- ArgumentNullException
protocolSkillis null.- ArgumentException
protocolSkillis invalid.
GetAsync(RequestContext<GetSkillRequestParams>, CancellationToken)
Retrieves the skill's complete entry for the current get request.
public abstract ValueTask<GetSkillResult> GetAsync(RequestContext<GetSkillRequestParams> request, CancellationToken cancellationToken = default)
Parameters
requestRequestContext<GetSkillRequestParams>The actual get context, including matched primitive, caller, services, and metadata.
cancellationTokenCancellationTokenThe token to monitor for cancellation.
Returns
- ValueTask<GetSkillResult>
The complete result, including optional metadata and cache hints.
Remarks
The SDK invokes this method only for matched get requests, after get filters. It never invokes it during listing or initialization. The final result is validated and bound to the original requested URI, and shaped for the negotiated protocol after all filters.
Exceptions
- ArgumentNullException
requestis null.- OperationCanceledException
cancellationTokenis canceled.- InvalidOperationException
The request URI does not match this registration.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.