Skip to content

Commit 2815ee9

Browse files
committed
Merge branch 'main' into halter73/sessionless
# Conflicts: # src/ModelContextProtocol.AspNetCore/StreamableHttpHandler.cs # src/ModelContextProtocol.Core/Server/McpServerExtensions.cs
2 parents a3b519b + 740a7d0 commit 2815ee9

File tree

191 files changed

+10130
-4781
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+10130
-4781
lines changed

.devcontainer/devcontainer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "C# (.NET SDK)",
3+
"image": "mcr.microsoft.com/devcontainers/dotnet:1-8.0-jammy",
4+
"features": {
5+
"ghcr.io/devcontainers/features/dotnet:2": {
6+
"version": "10.0"
7+
},
8+
"ghcr.io/devcontainers/features/node:1": {}
9+
},
10+
"customizations": {
11+
"vscode": {
12+
"extensions": [
13+
"ms-dotnettools.csharp",
14+
"ms-dotnettools.csdevkit"
15+
],
16+
"settings": {
17+
"dotnet.defaultSolution": "ModelContextProtocol.slnx"
18+
}
19+
}
20+
},
21+
"postCreateCommand": "dotnet --list-sdks && echo 'Available .NET SDKs installed successfully!'"
22+
}

.github/workflows/ci-build-test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ jobs:
4343
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
4444
with:
4545
dotnet-version: |
46+
10.0.x
4647
9.0.x
47-
8.0.x
4848
4949
# NetFX testing on non-Windows requires mono
5050
- name: Setup Mono
@@ -78,7 +78,6 @@ jobs:
7878
--filter '(Execution!=Manual)'
7979
--no-build
8080
--configuration ${{ matrix.configuration }}
81-
--logger "console;verbosity=normal"
8281
--logger "trx"
8382
--logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true"
8483
--blame

.github/workflows/ci-code-coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ jobs:
1515
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
1616
with:
1717
dotnet-version: |
18+
10.0.x
1819
9.0.x
19-
8.0.x
2020
2121
- name: Download test results
2222
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1

.github/workflows/docs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ jobs:
3232
- name: .NET Setup
3333
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
3434
with:
35-
dotnet-version: 9.x
35+
dotnet-version: |
36+
10.0.x
37+
9.0.x
3638
3739
- name: Generate documentation
3840
run: make generate-docs

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ jobs:
5252
- name: Set up .NET
5353
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
5454
with:
55-
dotnet-version: 9.0.x
55+
dotnet-version: |
56+
10.0.x
57+
9.0.x
5658
5759
- name: Build
5860
run: dotnet build --configuration ${{ matrix.configuration }}

Directory.Packages.props

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
<System9Version>9.0.5</System9Version>
55
<System10Version>10.0.0-preview.4.25258.110</System10Version>
6-
<MicrosoftExtensionsAIVersion>9.8.0</MicrosoftExtensionsAIVersion>
6+
<MicrosoftExtensionsAIVersion>9.9.1</MicrosoftExtensionsAIVersion>
77
</PropertyGroup>
88

99
<!-- Product dependencies netstandard -->
@@ -34,6 +34,15 @@
3434
<PackageVersion Include="System.IO.Pipelines" Version="$(System9Version)" />
3535
</ItemGroup>
3636

37+
<!-- Product dependencies .NET 10 -->
38+
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
39+
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(System10Version)" />
40+
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="8.9.0" />
41+
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(System10Version)" />
42+
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="$(System10Version)" />
43+
<PackageVersion Include="System.IO.Pipelines" Version="$(System10Version)" />
44+
</ItemGroup>
45+
3746
<!-- Product dependencies shared -->
3847
<ItemGroup>
3948
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="$(MicrosoftExtensionsAIVersion)" />
@@ -53,7 +62,7 @@
5362
<PrivateAssets>all</PrivateAssets>
5463
</PackageVersion>
5564
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
56-
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.8.0-preview.1.25412.6" />
65+
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.9.1-preview.1.25474.6" />
5766
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="$(System9Version)" />
5867
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="$(System9Version)" />
5968
<PackageVersion Include="Microsoft.Extensions.Logging" Version="$(System9Version)" />

ModelContextProtocol.slnx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<Folder Name="/docs/concepts/elicitation/samples/server/">
1919
<Project Path="docs/concepts/elicitation/samples/server/Elicitation.csproj" />
2020
</Folder>
21+
<Folder Name="/docs/concepts/httpcontext/" />
22+
<Folder Name="/docs/concepts/httpcontext/samples/">
23+
<Project Path="docs/concepts/httpcontext/samples/HttpContext.csproj" />
24+
</Folder>
2125
<Folder Name="/docs/concepts/logging/" />
2226
<Folder Name="/docs/concepts/logging/samples/" />
2327
<Folder Name="/docs/concepts/logging/samples/client/">
@@ -52,6 +56,7 @@
5256
<File Path="global.json" />
5357
<File Path="LICENSE" />
5458
<File Path="logo.png" />
59+
<File Path="Makefile" />
5560
<File Path="nuget.config" />
5661
<File Path="README.MD" />
5762
</Folder>

README.md

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ dotnet add package ModelContextProtocol --prerelease
3737

3838
## Getting Started (Client)
3939

40-
To get started writing a client, the `McpClientFactory.CreateAsync` method is used to instantiate and connect an `IMcpClient`
41-
to a server. Once you have an `IMcpClient`, you can interact with it, such as to enumerate all available tools and invoke tools.
40+
To get started writing a client, the `McpClient.CreateAsync` method is used to instantiate and connect an `McpClient`
41+
to a server. Once you have an `McpClient`, you can interact with it, such as to enumerate all available tools and invoke tools.
4242

4343
```csharp
4444
var clientTransport = new StdioClientTransport(new StdioClientTransportOptions
@@ -48,7 +48,7 @@ var clientTransport = new StdioClientTransport(new StdioClientTransportOptions
4848
Arguments = ["-y", "@modelcontextprotocol/server-everything"],
4949
});
5050

51-
var client = await McpClientFactory.CreateAsync(clientTransport);
51+
var client = await McpClient.CreateAsync(clientTransport);
5252

5353
// Print the list of tools available from the server.
5454
foreach (var tool in await client.ListToolsAsync())
@@ -88,7 +88,7 @@ var response = await chatClient.GetResponseAsync(
8888
Here is an example of how to create an MCP server and register all tools from the current application.
8989
It includes a simple echo tool as an example (this is included in the same file here for easy of copy and paste, but it needn't be in the same file...
9090
the employed overload of `WithTools` examines the current assembly for classes with the `McpServerToolType` attribute, and registers all methods with the
91-
`McpTool` attribute as tools.)
91+
`McpServerTool` attribute as tools.)
9292

9393
```
9494
dotnet add package ModelContextProtocol --prerelease
@@ -122,14 +122,14 @@ public static class EchoTool
122122
}
123123
```
124124

125-
Tools can have the `IMcpServer` representing the server injected via a parameter to the method, and can use that for interaction with
125+
Tools can have the `McpServer` representing the server injected via a parameter to the method, and can use that for interaction with
126126
the connected client. Similarly, arguments may be injected via dependency injection. For example, this tool will use the supplied
127-
`IMcpServer` to make sampling requests back to the client in order to summarize content it downloads from the specified url via
127+
`McpServer` to make sampling requests back to the client in order to summarize content it downloads from the specified url via
128128
an `HttpClient` injected via dependency injection.
129129
```csharp
130130
[McpServerTool(Name = "SummarizeContentFromUrl"), Description("Summarizes content downloaded from a specific URI")]
131131
public static async Task<string> SummarizeDownloadedContent(
132-
IMcpServer thisServer,
132+
McpServer thisServer,
133133
HttpClient httpClient,
134134
[Description("The url from which to download the content to summarize")] string url,
135135
CancellationToken cancellationToken)
@@ -174,57 +174,54 @@ using System.Text.Json;
174174
McpServerOptions options = new()
175175
{
176176
ServerInfo = new Implementation { Name = "MyServer", Version = "1.0.0" },
177-
Capabilities = new ServerCapabilities
177+
Handlers = new McpServerHandlers()
178178
{
179-
Tools = new ToolsCapability
180-
{
181-
ListToolsHandler = (request, cancellationToken) =>
182-
ValueTask.FromResult(new ListToolsResult
183-
{
184-
Tools =
185-
[
186-
new Tool
187-
{
188-
Name = "echo",
189-
Description = "Echoes the input back to the client.",
190-
InputSchema = JsonSerializer.Deserialize<JsonElement>("""
191-
{
192-
"type": "object",
193-
"properties": {
194-
"message": {
195-
"type": "string",
196-
"description": "The input to echo back"
197-
}
198-
},
199-
"required": ["message"]
200-
}
201-
"""),
202-
}
203-
]
204-
}),
205-
206-
CallToolHandler = (request, cancellationToken) =>
179+
ListToolsHandler = (request, cancellationToken) =>
180+
ValueTask.FromResult(new ListToolsResult
207181
{
208-
if (request.Params?.Name == "echo")
209-
{
210-
if (request.Params.Arguments?.TryGetValue("message", out var message) is not true)
182+
Tools =
183+
[
184+
new Tool
211185
{
212-
throw new McpException("Missing required argument 'message'");
186+
Name = "echo",
187+
Description = "Echoes the input back to the client.",
188+
InputSchema = JsonSerializer.Deserialize<JsonElement>("""
189+
{
190+
"type": "object",
191+
"properties": {
192+
"message": {
193+
"type": "string",
194+
"description": "The input to echo back"
195+
}
196+
},
197+
"required": ["message"]
198+
}
199+
"""),
213200
}
201+
]
202+
}),
214203

215-
return ValueTask.FromResult(new CallToolResult
216-
{
217-
Content = [new TextContentBlock { Text = $"Echo: {message}", Type = "text" }]
218-
});
204+
CallToolHandler = (request, cancellationToken) =>
205+
{
206+
if (request.Params?.Name == "echo")
207+
{
208+
if (request.Params.Arguments?.TryGetValue("message", out var message) is not true)
209+
{
210+
throw new McpException("Missing required argument 'message'");
219211
}
220212

221-
throw new McpException($"Unknown tool: '{request.Params?.Name}'");
222-
},
213+
return ValueTask.FromResult(new CallToolResult
214+
{
215+
Content = [new TextContentBlock { Text = $"Echo: {message}", Type = "text" }]
216+
});
217+
}
218+
219+
throw new McpException($"Unknown tool: '{request.Params?.Name}'");
223220
}
224-
},
221+
}
225222
};
226223

227-
await using IMcpServer server = McpServerFactory.Create(new StdioServerTransport("MyServer"), options);
224+
await using McpServer server = McpServer.Create(new StdioServerTransport("MyServer"), options);
228225
await server.RunAsync();
229226
```
230227

docs/concepts/elicitation/samples/client/ElicitationClient.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
9+
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
810
</PropertyGroup>
911

1012
<ItemGroup>

docs/concepts/elicitation/samples/client/Program.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
var endpoint = Environment.GetEnvironmentVariable("ENDPOINT") ?? "http://localhost:3001";
66

7-
var clientTransport = new SseClientTransport(new()
7+
var clientTransport = new HttpClientTransport(new()
88
{
99
Endpoint = new Uri(endpoint),
1010
TransportMode = HttpTransportMode.StreamableHttp,
@@ -18,16 +18,13 @@
1818
Name = "ElicitationClient",
1919
Version = "1.0.0"
2020
},
21-
Capabilities = new()
21+
Handlers = new()
2222
{
23-
Elicitation = new()
24-
{
25-
ElicitationHandler = HandleElicitationAsync
26-
}
23+
ElicitationHandler = HandleElicitationAsync
2724
}
2825
};
2926

30-
await using var mcpClient = await McpClientFactory.CreateAsync(clientTransport, options);
27+
await using var mcpClient = await McpClient.CreateAsync(clientTransport, options);
3128
// </snippet_McpInitialize>
3229

3330
var tools = await mcpClient.ListToolsAsync();

0 commit comments

Comments
 (0)