Table of Contents

Class SkillVerifier

Namespace
ModelContextProtocol.Extensions.Skills
Assembly
ModelContextProtocol.Extensions.Skills.dll

Verifies skill file content against a skill's manifest, and computes manifest digests.

[Experimental("MCPEXP005", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp005")]
public static class SkillVerifier
Inheritance
SkillVerifier
Inherited Members

Remarks

When a host retrieves a file listed in a skill's manifest, it must verify the content against that entry's digest and size, and must treat a read of a file the manifest does not list as a verification failure. These helpers implement those checks.

They do not verify frontmatter. Before loading a skill, the host must also parse the fetched SKILL.md itself with a full YAML parser and compare its frontmatter field by field with the held entry, for example with DeepEquals(JsonNode, JsonNode), treating any difference or any parse failure as a verification failure. The entry's own frontmatter is never a substitute for parsing the file.

Digests are unsigned and supplied by the same server that supplies the content. A match proves the manifest and the content are consistent, not that either is trustworthy.

Methods

ComputeDigest(ReadOnlySpan<byte>)

Computes the manifest digest of content: sha256: followed by the lowercase hexadecimal SHA-256 of the bytes.

public static string ComputeDigest(ReadOnlySpan<byte> content)

Parameters

content ReadOnlySpan<byte>

The raw bytes.

Returns

string

The digest.

Verify(Skill, ReadResourceResult)

Verifies the result of a resources/read for one of a skill's files against the skill's manifest.

public static void Verify(Skill skill, ReadResourceResult result)

Parameters

skill Skill

The skill entry being acted on.

result ReadResourceResult

The result of reading a file of the skill.

Exceptions

ArgumentNullException

An argument is null.

InvalidOperationException

skill's manifest is Dynamic, which cannot be verified.

InvalidDataException

The result is empty, contains a null entry or contents for a URI the manifest does not list, or contains contents whose size or digest does not match the manifest.

Verify(Skill, string, ReadResourceResult)

Verifies the result of reading a specific file of a skill through resources/read against the skill's manifest, additionally requiring that the result actually contains the requested file.

public static void Verify(Skill skill, string uri, ReadResourceResult result)

Parameters

skill Skill

The skill entry being acted on.

uri string

The URI that was requested. It must be listed in skill's manifest.

result ReadResourceResult

The result of the read.

Remarks

Checking every returned content against the manifest is not enough on its own: a server could answer a read of one file with another, correctly digested, file of the same skill. Binding the result to the requested URI closes that gap.

Exceptions

ArgumentNullException

An argument is null.

InvalidOperationException

skill's manifest is Dynamic, which cannot be verified.

InvalidDataException

uri is not listed in the manifest, the result does not contain contents for uri, or any contents in the result fail verification per Verify(Skill, ReadResourceResult).

Verify(SkillResource, ResourceContents)

Verifies the contents returned by resources/read against a manifest entry.

public static void Verify(SkillResource expected, ResourceContents contents)

Parameters

expected SkillResource

The manifest entry.

contents ResourceContents

The contents that were read.

Remarks

Text contents are hashed as their UTF-8 encoding; blob contents are hashed as their decoded bytes.

Exceptions

ArgumentNullException

An argument is null.

InvalidDataException

The contents are not for expected's URI, are neither text nor a blob, or their size or digest does not match expected.

Verify(SkillResource, ReadOnlySpan<byte>)

Verifies raw content against a manifest entry.

public static void Verify(SkillResource expected, ReadOnlySpan<byte> content)

Parameters

expected SkillResource

The manifest entry.

content ReadOnlySpan<byte>

The bytes that were read.

Exceptions

ArgumentNullException

expected is null.

InvalidDataException

The size or digest of content does not match expected.