Skip to content

Commit 50f7cd7

Browse files
PederHPgirishkvsclaude
committed
Add tests and a conformance fixture for the Skills extension
Unit tests cover serialization (including every invalid manifest shape and frontmatter pass-through), the in-memory catalog (ordering, keyset pagination, cursor validation, and each structural validation rule), McpServerSkill (manifest computation, path normalization, resource metadata, directory loading), and SkillVerifier (known digest vectors, size and digest mismatches, text versus blob, unlisted files). End-to-end tests drive the client extensions against an in-process server for both WithSkills overloads: listing and pagination, skills served but not listed, dynamic skills, verified reads including a tampered resource, the -32602 error contract, and the wire shape of resultType, ttlMs, and cacheScope on 2025-11-25 and 2026-07-28 sessions, including the defaults applied when no options are set. The conformance server gains the SEP-2640 fixture: three static skills built with McpServerSkill plus a dynamic one, paged two at a time. The SEP-2640 scenarios from modelcontextprotocol/conformance#330 pass 30/30, 6/6, 1/1 stateless and 29/29, 6/6, 1/1 on a 2025-11-25 session. The AOT compatibility app now also lists, gets, and verifies a skill. The serialization tests and the fixture's skill set are carried over from modelcontextprotocol#1856. Co-authored-by: Girish Konda <[email protected]> Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01P6omaTvQiryHtzFHRqUE3b
1 parent 9569706 commit 50f7cd7

13 files changed

Lines changed: 1446 additions & 1 deletion

‎tests/ModelContextProtocol.AotCompatibility.TestApp/ModelContextProtocol.AotCompatibility.TestApp.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<ProjectReference Include="..\..\src\ModelContextProtocol\ModelContextProtocol.csproj" />
1717
<ProjectReference Include="..\..\src\ModelContextProtocol.AspNetCore\ModelContextProtocol.AspNetCore.csproj" />
1818
<ProjectReference Include="..\..\src\ModelContextProtocol.Extensions.Apps\ModelContextProtocol.Extensions.Apps.csproj" />
19+
<ProjectReference Include="..\..\src\ModelContextProtocol.Extensions.Skills\ModelContextProtocol.Extensions.Skills.csproj" />
1920

2021
<TrimmerRootAssembly Include="ModelContextProtocol.Core" />
2122
<TrimmerRootAssembly Include="ModelContextProtocol" />

‎tests/ModelContextProtocol.AotCompatibility.TestApp/Program.cs‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using ModelContextProtocol.Client;
33
using ModelContextProtocol.Extensions.Apps;
4+
using ModelContextProtocol.Extensions.Skills;
45
using ModelContextProtocol.Protocol;
56
using ModelContextProtocol.Server;
67
using System.IO.Pipelines;
@@ -11,7 +12,14 @@
1112
services.AddMcpServer()
1213
.WithStreamServerTransport(clientToServerPipe.Reader.AsStream(), serverToClientPipe.Writer.AsStream())
1314
.WithTools<AotTools>()
14-
.WithMcpApps();
15+
.WithMcpApps()
16+
.WithSkills(
17+
[
18+
McpServerSkill.Create(
19+
"skill://aot/SKILL.md",
20+
new System.Text.Json.Nodes.JsonObject { ["name"] = "aot", ["description"] = "An AOT-published skill." },
21+
[McpServerSkillFile.FromText("SKILL.md", "---\nname: aot\ndescription: An AOT-published skill.\n---\n")]),
22+
]);
1523

1624
await using var serviceProvider = services.BuildServiceProvider();
1725
var server = serviceProvider.GetRequiredService<McpServer>();
@@ -41,6 +49,20 @@
4149
throw new Exception($"Unexpected result: {result}");
4250
}
4351

52+
// List, get, and verify a skill.
53+
var skills = await client.ListSkillsAsync();
54+
if (skills.Count != 1 || skills[0].Name != "aot")
55+
{
56+
throw new Exception($"Unexpected skills listing: {skills.Count} entries.");
57+
}
58+
59+
var skill = await client.GetSkillAsync("skill://aot/SKILL.md");
60+
var skillFile = await client.ReadSkillResourceAsync(skill, skill.Uri);
61+
if (skillFile.Contents is not [TextResourceContents { Text: var skillText }] || !skillText.Contains("name: aot"))
62+
{
63+
throw new Exception("Unexpected skill content.");
64+
}
65+
4466
Console.WriteLine("Success!");
4567

4668
[McpServerToolType]

‎tests/ModelContextProtocol.ConformanceServer/ModelContextProtocol.ConformanceServer.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
<ItemGroup>
1717
<ProjectReference Include="../../src/ModelContextProtocol.AspNetCore/ModelContextProtocol.AspNetCore.csproj" />
18+
<ProjectReference Include="../../src/ModelContextProtocol.Extensions.Skills/ModelContextProtocol.Extensions.Skills.csproj" />
1819
<ProjectReference Include="../../src/ModelContextProtocol.Extensions.Tasks/ModelContextProtocol.Extensions.Tasks.csproj" />
1920
</ItemGroup>
2021

‎tests/ModelContextProtocol.ConformanceServer/Program.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using ConformanceServer.Prompts;
22
using ConformanceServer.Resources;
33
using ConformanceServer.Tools;
4+
using ModelContextProtocol.ConformanceServer.Skills;
45
using ModelContextProtocol.Protocol;
56
using ModelContextProtocol.Server;
7+
using ModelContextProtocol.Extensions.Skills;
68
using ModelContextProtocol.Extensions.Tasks;
79
using System.Collections.Concurrent;
810
using System.Diagnostics;
@@ -53,6 +55,12 @@ private static void ConfigureConformanceMcpServer(
5355
.AddMcpServer()
5456
.WithHttpTransport(options => options.Stateless = stateless)
5557
.WithDistributedCacheEventStreamStore()
58+
.WithSkills(ConformanceSkills.CreateCatalog(), options =>
59+
{
60+
options.TimeToLive = TimeSpan.FromMinutes(5);
61+
options.CacheScope = CacheScope.Public;
62+
})
63+
.WithResources(ConformanceSkills.CreateResources())
5664
.WithTasks(
5765
new InMemoryMcpTaskStore
5866
{
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using ModelContextProtocol.Extensions.Skills;
2+
using ModelContextProtocol.Server;
3+
using System.Text.Json.Nodes;
4+
5+
namespace ModelContextProtocol.ConformanceServer.Skills;
6+
7+
/// <summary>
8+
/// Builds the SEP-2640 skill fixture the conformance scenarios run against.
9+
/// </summary>
10+
/// <remarks>
11+
/// <para>
12+
/// The three static skills are authored through <see cref="McpServerSkill"/>, so their manifests are computed
13+
/// from the same bytes their resources serve. A fourth, deliberately unenumerable skill is added to the catalog
14+
/// by hand: it is served and answerable through <c>skills/get</c>, but carries no digests and so cannot be
15+
/// content-bound.
16+
/// </para>
17+
/// <para>
18+
/// The page size is deliberately small so the scenarios exercise cursor pagination.
19+
/// </para>
20+
/// </remarks>
21+
public static class ConformanceSkills
22+
{
23+
private const string GeneratedReportUri = "skill://generated-report/SKILL.md";
24+
25+
private static readonly McpServerSkill[] s_skills =
26+
[
27+
McpServerSkill.Create(
28+
"skill://git-workflow/SKILL.md",
29+
Frontmatter("git-workflow", "Follow this team's Git conventions for branching and commits"),
30+
[
31+
SkillFile("git-workflow", "Follow this team's Git conventions for branching and commits", "# Git workflow\n"),
32+
]),
33+
34+
McpServerSkill.Create(
35+
"skill://pdf-processing/SKILL.md",
36+
Frontmatter("pdf-processing", "Extract, fill, and assemble PDF documents"),
37+
[
38+
SkillFile("pdf-processing", "Extract, fill, and assemble PDF documents", "# PDF processing\n"),
39+
McpServerSkillFile.FromText("references/FORMS.md", "# Forms\n\nField reference for PDF form filling.\n"),
40+
McpServerSkillFile.FromText("scripts/extract.py", "import sys\n\nprint('extract')\n"),
41+
McpServerSkillFile.FromText("templates/invoice.md", "# Invoice\n"),
42+
McpServerSkillFile.FromText("templates/regional/eu-invoice.md", "# EU Invoice\n"),
43+
]),
44+
45+
McpServerSkill.Create(
46+
"skill://acme/billing/refunds/SKILL.md",
47+
Frontmatter("refunds", "Process customer refund requests per company policy"),
48+
[
49+
SkillFile("refunds", "Process customer refund requests per company policy", "# Refunds\n"),
50+
McpServerSkillFile.FromText("examples/email.md", "Subject: Your refund\n"),
51+
]),
52+
];
53+
54+
private static readonly Skill s_generatedReport = new()
55+
{
56+
Uri = GeneratedReportUri,
57+
Frontmatter = Frontmatter("generated-report", "Assemble a report from live data"),
58+
Resources = SkillResources.Dynamic,
59+
};
60+
61+
/// <summary>
62+
/// Creates the catalog backing <c>skills/list</c> and <c>skills/get</c>.
63+
/// </summary>
64+
public static IMcpSkillCatalog CreateCatalog() =>
65+
new InMemoryMcpSkillCatalog([.. s_skills.Select(s => s.ProtocolSkill), s_generatedReport], pageSize: 2);
66+
67+
/// <summary>
68+
/// Creates the resources serving every skill file, so the files are enumerable through <c>resources/list</c>
69+
/// and readable through <c>resources/read</c>.
70+
/// </summary>
71+
public static IEnumerable<McpServerResource> CreateResources()
72+
{
73+
foreach (var skill in s_skills)
74+
{
75+
foreach (var resource in skill.Resources)
76+
{
77+
yield return resource;
78+
}
79+
}
80+
81+
yield return McpServerResource.Create(
82+
() => $"---\nname: generated-report\ndescription: Assemble a report from live data\n---\n\n# Generated report\n\nGenerated at {DateTimeOffset.UtcNow:O}.\n",
83+
new McpServerResourceCreateOptions
84+
{
85+
UriTemplate = GeneratedReportUri,
86+
Name = "generated-report",
87+
Description = "Assemble a report from live data",
88+
MimeType = "text/markdown",
89+
});
90+
}
91+
92+
private static JsonObject Frontmatter(string name, string description) => new()
93+
{
94+
["name"] = name,
95+
["description"] = description,
96+
};
97+
98+
private static McpServerSkillFile SkillFile(string name, string description, string body) =>
99+
McpServerSkillFile.FromText(SkillsProtocol.SkillFileName, $"---\nname: {name}\ndescription: {description}\n---\n\n{body}");
100+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
using ModelContextProtocol.Extensions.Skills;
2+
using ModelContextProtocol.Protocol;
3+
using System.Text;
4+
using System.Text.Json.Nodes;
5+
6+
namespace ModelContextProtocol.Tests.Client;
7+
8+
/// <summary>
9+
/// Tests for <see cref="SkillVerifier"/>: digest formatting and content verification against a manifest.
10+
/// </summary>
11+
public class SkillVerifierTests
12+
{
13+
private const string Uri = "skill://alpha/SKILL.md";
14+
15+
private static SkillResource Entry(byte[] content) => new()
16+
{
17+
Uri = Uri,
18+
Digest = SkillVerifier.ComputeDigest(content),
19+
Size = content.Length,
20+
};
21+
22+
[Theory]
23+
[InlineData("", "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")]
24+
[InlineData("abc", "sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad")]
25+
public void ComputeDigest_MatchesKnownVectors(string input, string expected)
26+
{
27+
Assert.Equal(expected, SkillVerifier.ComputeDigest(Encoding.UTF8.GetBytes(input)));
28+
}
29+
30+
[Fact]
31+
public void Verify_AcceptsMatchingBytes()
32+
{
33+
byte[] content = Encoding.UTF8.GetBytes("# Hello\n");
34+
35+
SkillVerifier.Verify(Entry(content), content);
36+
}
37+
38+
[Fact]
39+
public void Verify_RejectsSizeMismatch()
40+
{
41+
byte[] content = Encoding.UTF8.GetBytes("# Hello\n");
42+
var entry = Entry(content);
43+
entry.Size += 1;
44+
45+
var exception = Assert.Throws<SkillVerificationException>(() => SkillVerifier.Verify(entry, content));
46+
Assert.Contains("bytes", exception.Message);
47+
}
48+
49+
[Fact]
50+
public void Verify_RejectsDigestMismatch()
51+
{
52+
var entry = Entry(Encoding.UTF8.GetBytes("# Hello\n"));
53+
54+
var exception = Assert.Throws<SkillVerificationException>(() =>
55+
SkillVerifier.Verify(entry, Encoding.UTF8.GetBytes("# Hellp\n")));
56+
Assert.Contains("digest", exception.Message);
57+
}
58+
59+
[Fact]
60+
public void Verify_AcceptsUppercaseDigestFromServer()
61+
{
62+
byte[] content = Encoding.UTF8.GetBytes("x");
63+
var entry = Entry(content);
64+
entry.Digest = entry.Digest.ToUpperInvariant().Replace("SHA256", "sha256");
65+
66+
SkillVerifier.Verify(entry, content);
67+
}
68+
69+
[Fact]
70+
public void Verify_TextContents_HashesUtf8Encoding()
71+
{
72+
const string Text = "# Héllo\n";
73+
var entry = Entry(Encoding.UTF8.GetBytes(Text));
74+
75+
SkillVerifier.Verify(entry, new TextResourceContents { Uri = Uri, Text = Text });
76+
}
77+
78+
[Fact]
79+
public void Verify_BlobContents_HashesDecodedBytes()
80+
{
81+
byte[] content = [0x00, 0xFF, 0x10, 0x80];
82+
var entry = Entry(content);
83+
84+
SkillVerifier.Verify(entry, BlobResourceContents.FromBytes(content, Uri));
85+
}
86+
87+
[Fact]
88+
public void Verify_Contents_RejectsUriMismatch()
89+
{
90+
var entry = Entry(Encoding.UTF8.GetBytes("x"));
91+
92+
Assert.Throws<SkillVerificationException>(() =>
93+
SkillVerifier.Verify(entry, new TextResourceContents { Uri = "skill://alpha/other.md", Text = "x" }));
94+
}
95+
96+
[Fact]
97+
public void Verify_Skill_ChecksEveryContentAgainstManifest()
98+
{
99+
byte[] content = Encoding.UTF8.GetBytes("x");
100+
var skill = CreateSkill(content);
101+
102+
SkillVerifier.Verify(skill, new ReadResourceResult { Contents = [new TextResourceContents { Uri = Uri, Text = "x" }] });
103+
104+
Assert.Throws<SkillVerificationException>(() => SkillVerifier.Verify(skill,
105+
new ReadResourceResult { Contents = [new TextResourceContents { Uri = Uri, Text = "y" }] }));
106+
}
107+
108+
[Fact]
109+
public void Verify_Skill_RejectsUnlistedFile()
110+
{
111+
var skill = CreateSkill(Encoding.UTF8.GetBytes("x"));
112+
113+
var exception = Assert.Throws<SkillVerificationException>(() => SkillVerifier.Verify(skill,
114+
new ReadResourceResult { Contents = [new TextResourceContents { Uri = "skill://alpha/new.md", Text = "x" }] }));
115+
Assert.Contains("not listed", exception.Message);
116+
}
117+
118+
[Fact]
119+
public void Verify_Skill_RejectsEmptyResult()
120+
{
121+
var skill = CreateSkill(Encoding.UTF8.GetBytes("x"));
122+
123+
Assert.Throws<SkillVerificationException>(() => SkillVerifier.Verify(skill, new ReadResourceResult()));
124+
}
125+
126+
[Fact]
127+
public void Verify_Skill_ThrowsForDynamicSkill()
128+
{
129+
var skill = CreateSkill(Encoding.UTF8.GetBytes("x"));
130+
skill.Resources = SkillResources.Dynamic;
131+
132+
Assert.Throws<InvalidOperationException>(() => SkillVerifier.Verify(skill,
133+
new ReadResourceResult { Contents = [new TextResourceContents { Uri = Uri, Text = "x" }] }));
134+
}
135+
136+
private static Skill CreateSkill(byte[] skillFileContent) => new()
137+
{
138+
Uri = Uri,
139+
Frontmatter = new JsonObject { ["name"] = "alpha", ["description"] = "d" },
140+
Resources = SkillResources.FromResources([Entry(skillFileContent)]),
141+
};
142+
}

‎tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<ProjectReference Include="..\..\src\ModelContextProtocol\ModelContextProtocol.csproj" />
8585
<ProjectReference Include="..\..\src\ModelContextProtocol.Core\ModelContextProtocol.Core.csproj" />
8686
<ProjectReference Include="..\..\src\ModelContextProtocol.Extensions.Apps\ModelContextProtocol.Extensions.Apps.csproj" />
87+
<ProjectReference Include="..\..\src\ModelContextProtocol.Extensions.Skills\ModelContextProtocol.Extensions.Skills.csproj" />
8788
<ProjectReference Include="..\..\src\ModelContextProtocol.Extensions.Tasks\ModelContextProtocol.Extensions.Tasks.csproj" />
8889
<ProjectReference Include="..\ModelContextProtocol.TestServer\ModelContextProtocol.TestServer.csproj" />
8990
<ProjectReference Include="..\..\samples\TestServerWithHosting\TestServerWithHosting.csproj" />

0 commit comments

Comments
 (0)