Restructure IMcpEndpoint, IMcpClient, and IMcpServer (#723)
* Remove `McpEndpoint` & `IMcpClient` * Revise naming, add abstract classes * Fix missing renames * Move extension methods to instance methods * Add back old API, but obsoleted * Add back obsoleted factory classes * Move deprecation attributes * `SseClientTransport` -> `HttpClientTransport` * Update src/ModelContextProtocol.Core/Server/AugmentedServiceProvider.cs Co-authored-by: Stephen Halter <halter73@gmail.com> * PR feedback * PR feedback * Add back dispose lock * Fix docs projects * PR feedback * Undo `docs/*.md` changes --------- Co-authored-by: Stephen Halter <halter73@gmail.com>
This commit is contained in:
parent
fe2ce2bc60
commit
38b4a26998
5 changed files with 5169 additions and 3786 deletions
|
|
@ -292,7 +292,7 @@ internal sealed class AuthorizationFilterSetup(IAuthorizationPolicyProvider? pol
|
|||
if (requestServices is null)
|
||||
{
|
||||
// The IAuthorizationPolicyProvider service must be non-null to get to this line, so it's very unexpected for RequestContext.Services to not be set.
|
||||
throw new InvalidOperationException("RequestContext.Services is not set! The IMcpServer must be initialized with a non-null IServiceProvider.");
|
||||
throw new InvalidOperationException("RequestContext.Services is not set! The McpServer must be initialized with a non-null IServiceProvider.");
|
||||
}
|
||||
|
||||
// ASP.NET Core's AuthorizationMiddleware resolves the IAuthorizationService from scoped request services, so we do the same.
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class HttpServerTransportOptions
|
|||
/// Gets or sets an optional asynchronous callback for running new MCP sessions manually.
|
||||
/// This is useful for running logic before a sessions starts and after it completes.
|
||||
/// </summary>
|
||||
public Func<HttpContext, IMcpServer, CancellationToken, Task>? RunSessionHandler { get; set; }
|
||||
public Func<HttpContext, McpServer, CancellationToken, Task>? RunSessionHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the server should run in a stateless mode that does not require all requests for a given session
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ internal sealed class SseHandler(
|
|||
|
||||
try
|
||||
{
|
||||
await using var mcpServer = McpServerFactory.Create(transport, mcpServerOptions, loggerFactory, context.RequestServices);
|
||||
await using var mcpServer = McpServer.Create(transport, mcpServerOptions, loggerFactory, context.RequestServices);
|
||||
context.Features.Set(mcpServer);
|
||||
|
||||
var runSessionAsync = httpMcpServerOptions.Value.RunSessionHandler ?? StreamableHttpHandler.RunSessionAsync;
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ internal sealed class StreamableHttpHandler(
|
|||
}
|
||||
}
|
||||
|
||||
var server = McpServerFactory.Create(transport, mcpServerOptions, loggerFactory, mcpServerServices);
|
||||
var server = McpServer.Create(transport, mcpServerOptions, loggerFactory, mcpServerServices);
|
||||
context.Features.Set(server);
|
||||
|
||||
var userIdClaim = statelessId?.UserIdClaim ?? GetUserIdClaim(context.User);
|
||||
|
|
@ -307,7 +307,7 @@ internal sealed class StreamableHttpHandler(
|
|||
};
|
||||
}
|
||||
|
||||
internal static Task RunSessionAsync(HttpContext httpContext, IMcpServer session, CancellationToken requestAborted)
|
||||
internal static Task RunSessionAsync(HttpContext httpContext, McpServer session, CancellationToken requestAborted)
|
||||
=> session.RunAsync(requestAborted);
|
||||
|
||||
// SignalR only checks for ClaimTypes.NameIdentifier in HttpConnectionDispatcher, but AspNetCore.Antiforgery checks that plus the sub and UPN claims.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace ModelContextProtocol.AspNetCore;
|
|||
internal sealed class StreamableHttpSession(
|
||||
string sessionId,
|
||||
StreamableHttpServerTransport transport,
|
||||
IMcpServer server,
|
||||
McpServer server,
|
||||
UserIdClaim? userId,
|
||||
StatefulSessionManager sessionManager) : IAsyncDisposable
|
||||
{
|
||||
|
|
@ -20,7 +20,7 @@ internal sealed class StreamableHttpSession(
|
|||
|
||||
public string Id => sessionId;
|
||||
public StreamableHttpServerTransport Transport => transport;
|
||||
public IMcpServer Server => server;
|
||||
public McpServer Server => server;
|
||||
private StatefulSessionManager SessionManager => sessionManager;
|
||||
|
||||
public CancellationToken SessionClosed => _disposeCts.Token;
|
||||
|
|
|
|||
Loading…
Reference in a new issue