Add AOT compatibility publish test (#1246)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
This commit is contained in:
parent
bfd01b996f
commit
9c1538fd98
5 changed files with 69 additions and 0 deletions
4
.github/workflows/ci-build-test.yml
vendored
4
.github/workflows/ci-build-test.yml
vendored
|
|
@ -63,6 +63,10 @@ jobs:
|
||||||
- name: 🧪 Test
|
- name: 🧪 Test
|
||||||
run: make test CONFIGURATION=${{ matrix.configuration }}
|
run: make test CONFIGURATION=${{ matrix.configuration }}
|
||||||
|
|
||||||
|
- name: 🧪 AOT Compatibility
|
||||||
|
if: matrix.configuration == 'Release'
|
||||||
|
run: make test-aot CONFIGURATION=${{ matrix.configuration }}
|
||||||
|
|
||||||
- name: 📦 Pack
|
- name: 📦 Pack
|
||||||
if: matrix.configuration == 'Release'
|
if: matrix.configuration == 'Release'
|
||||||
run: make pack CONFIGURATION=${{ matrix.configuration }}
|
run: make pack CONFIGURATION=${{ matrix.configuration }}
|
||||||
|
|
|
||||||
4
Makefile
4
Makefile
|
|
@ -30,6 +30,10 @@ test: build
|
||||||
-- \
|
-- \
|
||||||
RunConfiguration.CollectSourceInformation=true
|
RunConfiguration.CollectSourceInformation=true
|
||||||
|
|
||||||
|
test-aot:
|
||||||
|
dotnet publish tests/ModelContextProtocol.AotCompatibility.TestApp/ModelContextProtocol.AotCompatibility.TestApp.csproj --configuration $(CONFIGURATION) -o $(ARTIFACT_PATH)/aot-publish
|
||||||
|
$(ARTIFACT_PATH)/aot-publish/ModelContextProtocol.AotCompatibility.TestApp
|
||||||
|
|
||||||
pack: restore
|
pack: restore
|
||||||
dotnet pack --no-restore --configuration $(CONFIGURATION)
|
dotnet pack --no-restore --configuration $(CONFIGURATION)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@
|
||||||
</Folder>
|
</Folder>
|
||||||
<Folder Name="/tests/">
|
<Folder Name="/tests/">
|
||||||
<Project Path="tests/ModelContextProtocol.Analyzers.Tests/ModelContextProtocol.Analyzers.Tests.csproj" />
|
<Project Path="tests/ModelContextProtocol.Analyzers.Tests/ModelContextProtocol.Analyzers.Tests.csproj" />
|
||||||
|
<Project Path="tests/ModelContextProtocol.AotCompatibility.TestApp/ModelContextProtocol.AotCompatibility.TestApp.csproj" />
|
||||||
<Project Path="tests/ModelContextProtocol.AspNetCore.Tests/ModelContextProtocol.AspNetCore.Tests.csproj" />
|
<Project Path="tests/ModelContextProtocol.AspNetCore.Tests/ModelContextProtocol.AspNetCore.Tests.csproj" />
|
||||||
<Project Path="tests/ModelContextProtocol.ConformanceClient/ModelContextProtocol.ConformanceClient.csproj" />
|
<Project Path="tests/ModelContextProtocol.ConformanceClient/ModelContextProtocol.ConformanceClient.csproj" />
|
||||||
<Project Path="tests/ModelContextProtocol.ConformanceServer/ModelContextProtocol.ConformanceServer.csproj" />
|
<Project Path="tests/ModelContextProtocol.ConformanceServer/ModelContextProtocol.ConformanceServer.csproj" />
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<!-- Ensure TargetFrameworks is not inherited -->
|
||||||
|
<TargetFrameworks></TargetFrameworks>
|
||||||
|
<PublishAot>true</PublishAot>
|
||||||
|
<TrimmerSingleWarn>false</TrimmerSingleWarn>
|
||||||
|
<!-- Suppress the experimental tasks warning -->
|
||||||
|
<NoWarn>$(NoWarn);MCPEXP001</NoWarn>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\src\ModelContextProtocol.Core\ModelContextProtocol.Core.csproj" />
|
||||||
|
<ProjectReference Include="..\..\src\ModelContextProtocol\ModelContextProtocol.csproj" />
|
||||||
|
<ProjectReference Include="..\..\src\ModelContextProtocol.AspNetCore\ModelContextProtocol.AspNetCore.csproj" />
|
||||||
|
|
||||||
|
<TrimmerRootAssembly Include="ModelContextProtocol.Core" />
|
||||||
|
<TrimmerRootAssembly Include="ModelContextProtocol" />
|
||||||
|
<TrimmerRootAssembly Include="ModelContextProtocol.AspNetCore" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
using ModelContextProtocol.Client;
|
||||||
|
using ModelContextProtocol.Protocol;
|
||||||
|
using ModelContextProtocol.Server;
|
||||||
|
using System.IO.Pipelines;
|
||||||
|
|
||||||
|
Pipe clientToServerPipe = new(), serverToClientPipe = new();
|
||||||
|
|
||||||
|
// Create a server using a stream-based transport over an in-memory pipe.
|
||||||
|
await using McpServer server = McpServer.Create(
|
||||||
|
new StreamServerTransport(clientToServerPipe.Reader.AsStream(), serverToClientPipe.Writer.AsStream()),
|
||||||
|
new McpServerOptions()
|
||||||
|
{
|
||||||
|
ToolCollection = [McpServerTool.Create((string arg) => $"Echo: {arg}", new() { Name = "Echo" })]
|
||||||
|
});
|
||||||
|
_ = server.RunAsync();
|
||||||
|
|
||||||
|
// Connect a client using a stream-based transport over the same in-memory pipe.
|
||||||
|
await using McpClient client = await McpClient.CreateAsync(
|
||||||
|
new StreamClientTransport(clientToServerPipe.Writer.AsStream(), serverToClientPipe.Reader.AsStream()));
|
||||||
|
|
||||||
|
// List all tools.
|
||||||
|
var tools = await client.ListToolsAsync();
|
||||||
|
if (tools.Count == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Expected at least one tool.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invoke a tool.
|
||||||
|
var echo = tools.First(t => t.Name == "Echo");
|
||||||
|
var result = await echo.InvokeAsync(new() { ["arg"] = "Hello World" });
|
||||||
|
if (result is null || !result.ToString()!.Contains("Echo: Hello World"))
|
||||||
|
{
|
||||||
|
throw new Exception($"Unexpected result: {result}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("Success!");
|
||||||
Loading…
Reference in a new issue