-
Notifications
You must be signed in to change notification settings - Fork 619
Add AOT compatibility publish test #1246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+69
−0
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fd68bbc
Initial plan
Copilot 794092b
Add AOT compatibility test app project
Copilot ceaf0a3
Update AOT test app with client-server sanity test
Copilot 20aac0a
Merge branch 'main' into copilot/add-aot-publish-test
stephentoub b41731f
Add test-aot Makefile target for local AOT compatibility testing
Copilot 743bc18
Run AOT-published binary after publishing to verify it succeeds
Copilot 806a918
Verify AOT test app prints 'Success!' and exits with code 0
Copilot e0786bf
Remove grep from test-aot target, just run the binary directly
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...extProtocol.AotCompatibility.TestApp/ModelContextProtocol.AotCompatibility.TestApp.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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> |
36 changes: 36 additions & 0 deletions
36
tests/ModelContextProtocol.AotCompatibility.TestApp/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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!"); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.