Skip to content

Commit 07d7268

Browse files
authored
Merge branch 'main' into stvansolano/add-more-tests
2 parents e9bb15f + b9bb871 commit 07d7268

File tree

19 files changed

+697
-716
lines changed

19 files changed

+697
-716
lines changed

samples/AspNetCoreSseServer/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using ModelContextProtocol.AspNetCore;
2-
31
var builder = WebApplication.CreateBuilder(args);
42
builder.Services.AddMcpServer().WithToolsFromAssembly();
53
var app = builder.Build();

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<RepositoryUrl>https://github.com/modelcontextprotocol/csharp-sdk</RepositoryUrl>
77
<RepositoryType>git</RepositoryType>
88
<VersionPrefix>0.1.0</VersionPrefix>
9-
<VersionSuffix>preview.4</VersionSuffix>
9+
<VersionSuffix>preview.5</VersionSuffix>
1010
<Authors>ModelContextProtocolOfficial</Authors>
1111
<Copyright>© Anthropic and Contributors.</Copyright>
1212
<PackageTags>ModelContextProtocol;mcp;ai;llm</PackageTags>

src/ModelContextProtocol.AspNetCore/McpEndpointRouteBuilderExtensions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Microsoft.AspNetCore.Builder;
2-
using Microsoft.AspNetCore.Http;
1+
using Microsoft.AspNetCore.Http;
32
using Microsoft.AspNetCore.Routing;
43
using Microsoft.AspNetCore.WebUtilities;
54
using Microsoft.Extensions.DependencyInjection;
@@ -12,7 +11,7 @@
1211
using System.Collections.Concurrent;
1312
using System.Security.Cryptography;
1413

15-
namespace ModelContextProtocol.AspNetCore;
14+
namespace Microsoft.AspNetCore.Builder;
1615

1716
/// <summary>
1817
/// Extension methods for <see cref="IEndpointRouteBuilder"/> to add MCP endpoints.
@@ -40,7 +39,7 @@ public static IEndpointConventionBuilder MapMcp(this IEndpointRouteBuilder endpo
4039
var requestAborted = context.RequestAborted;
4140

4241
response.Headers.ContentType = "text/event-stream";
43-
response.Headers.CacheControl = "no-cache";
42+
response.Headers.CacheControl = "no-store";
4443

4544
var sessionId = MakeNewSessionId();
4645
await using var transport = new SseResponseStreamTransport(response.Body, $"/message?sessionId={sessionId}");
@@ -53,10 +52,10 @@ public static IEndpointConventionBuilder MapMcp(this IEndpointRouteBuilder endpo
5352
try
5453
{
5554
var transportTask = transport.RunAsync(cancellationToken: requestAborted);
56-
runSession ??= RunSession;
5755

5856
try
5957
{
58+
runSession ??= RunSession;
6059
await runSession(context, server, requestAborted);
6160
}
6261
finally

src/ModelContextProtocol.AspNetCore/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ To get started, install the package from NuGet
2323

2424
```
2525
dotnet new web
26-
dotnet add package ModelContextProtocol.AspNetcore --prerelease
26+
dotnet add package ModelContextProtocol.AspNetCore --prerelease
2727
```
2828

2929
## Getting Started
3030

3131
```csharp
3232
// Program.cs
33-
using ModelContextProtocol;
34-
using ModelContextProtocol.AspNetCore;
33+
using ModelContextProtocol.Server;
34+
using System.ComponentModel;
3535

3636
var builder = WebApplication.CreateBuilder(args);
3737
builder.WebHost.ConfigureKestrel(options =>

src/ModelContextProtocol/Configuration/McpServerBuilderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public static IMcpServerBuilder WithPrompts(this IMcpServerBuilder builder, para
176176
}
177177

178178
/// <summary>
179-
/// Adds types marked with the <see cref="McpServerToolTypeAttribute"/> attribute from the given assembly as prompts to the server.
179+
/// Adds types marked with the <see cref="McpServerPromptTypeAttribute"/> attribute from the given assembly as prompts to the server.
180180
/// </summary>
181181
/// <param name="builder">The builder instance.</param>
182182
/// <param name="promptAssembly">The assembly to load the types from. Null to get the current assembly</param>
@@ -190,7 +190,7 @@ public static IMcpServerBuilder WithPromptsFromAssembly(this IMcpServerBuilder b
190190

191191
return builder.WithPrompts(
192192
from t in promptAssembly.GetTypes()
193-
where t.GetCustomAttribute<McpServerToolTypeAttribute>() is not null
193+
where t.GetCustomAttribute<McpServerPromptTypeAttribute>() is not null
194194
select t);
195195
}
196196
#endregion
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Microsoft.Extensions.Logging;
2+
using ModelContextProtocol.Logging;
3+
using ModelContextProtocol.Protocol.Messages;
4+
using System.Diagnostics;
5+
6+
namespace ModelContextProtocol.Protocol.Transport;
7+
8+
/// <summary>Provides the client side of a stdio-based session transport.</summary>
9+
internal sealed class StdioClientSessionTransport : StreamClientSessionTransport
10+
{
11+
private readonly StdioClientTransportOptions _options;
12+
private readonly Process _process;
13+
14+
public StdioClientSessionTransport(StdioClientTransportOptions options, Process process, string endpointName, ILoggerFactory? loggerFactory)
15+
: base(process.StandardInput, process.StandardOutput, endpointName, loggerFactory)
16+
{
17+
_process = process;
18+
_options = options;
19+
}
20+
21+
/// <inheritdoc/>
22+
public override async Task SendMessageAsync(IJsonRpcMessage message, CancellationToken cancellationToken = default)
23+
{
24+
if (_process.HasExited)
25+
{
26+
Logger.TransportNotConnected(EndpointName);
27+
throw new McpTransportException("Transport is not connected");
28+
}
29+
30+
await base.SendMessageAsync(message, cancellationToken).ConfigureAwait(false);
31+
}
32+
33+
/// <inheritdoc/>
34+
protected override ValueTask CleanupAsync(CancellationToken cancellationToken)
35+
{
36+
StdioClientTransport.DisposeProcess(_process, processStarted: true, Logger, _options.ShutdownTimeout, EndpointName);
37+
38+
return base.CleanupAsync(cancellationToken);
39+
}
40+
}

0 commit comments

Comments
 (0)