Pin the MCP conformance tester package (#1176)

This commit is contained in:
Eirik Tsarpalis 2026-01-26 22:35:31 +02:00 • committed by GitHub
commit a1e9e4102e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 4 deletions

View file

@ -51,6 +51,13 @@
<PackageReference Include="System.Linq.AsyncEnumerable" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>McpConformanceVersion</_Parameter1>
<_Parameter2>$(McpConformanceVersion)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\samples\TestServerWithHosting\TestServerWithHosting.csproj" />
<ProjectReference Include="..\..\src\ModelContextProtocol.Core\ModelContextProtocol.Core.csproj" />

View file

@ -115,9 +115,21 @@ public class ServerConformanceTests : IAsyncLifetime
_serverTask = Task.Run(() => ConformanceServer.Program.MainAsync(["--urls", _serverUrl], new XunitLoggerProvider(_output), cancellationToken: _serverCts.Token));
}
private static string GetConformanceVersion()
{
var assembly = typeof(ServerConformanceTests).Assembly;
var attribute = assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyMetadataAttribute), false)
.Cast<System.Reflection.AssemblyMetadataAttribute>()
.FirstOrDefault(a => a.Key == "McpConformanceVersion");
return attribute?.Value ?? throw new InvalidOperationException("McpConformanceVersion not found in assembly metadata");
}
private async Task<(bool Success, string Output, string Error)> RunNpxConformanceTests()
{
var startInfo = NodeHelpers.NpxStartInfo($"-y @modelcontextprotocol/conformance server --url {_serverUrl}");
// Version is configured in Directory.Packages.props for central management
var version = GetConformanceVersion();
var startInfo = NodeHelpers.NpxStartInfo($"-y @modelcontextprotocol/conformance@{version} server --url {_serverUrl}");
var outputBuilder = new StringBuilder();
var errorBuilder = new StringBuilder();

View file

@ -94,7 +94,7 @@ public class Program
app.MapMcp();
app.MapGet("/health", () => TypedResults.Ok("Healthy"));
app.MapGet("/health", () => "Healthy");
await app.RunAsync(cancellationToken);
}