Skip to content

Commit bdee0e3

Browse files
committed
Update to make sure naming is consistent
1 parent d339973 commit bdee0e3

File tree

12 files changed

+36
-38
lines changed

12 files changed

+36
-38
lines changed

samples/AuthorizationExample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static async Task Main(string[] args)
2424
var transportOptions = new SseClientTransportOptions
2525
{
2626
Endpoint = serverEndpoint,
27-
AuthorizationOptions = new McpAuthorizationOptions
27+
AuthorizationOptions = new AuthorizationOptions
2828
{
2929
// Pre-registered client credentials (if applicable)
3030
ClientId = "04f79824-ab56-4511-a7cb-d7deaea92dc0",
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using Microsoft.AspNetCore.Builder;
2-
using Microsoft.Extensions.DependencyInjection;
32

43
namespace ModelContextProtocol.AspNetCore;
54

65
/// <summary>
76
/// Extension methods for using MCP authorization in ASP.NET Core applications.
87
/// </summary>
9-
public static class McpAuthorizationExtensions
8+
public static class AuthorizationExtensions
109
{
1110
/// <summary>
1211
/// Adds MCP authorization middleware to the specified <see cref="IApplicationBuilder"/>, which enables
@@ -16,6 +15,6 @@ public static class McpAuthorizationExtensions
1615
/// <returns>A reference to this instance after the operation has completed.</returns>
1716
public static IApplicationBuilder UseMcpAuthorization(this IApplicationBuilder builder)
1817
{
19-
return builder.UseMiddleware<McpAuthorizationMiddleware>();
18+
return builder.UseMiddleware<AuthorizationMiddleware>();
2019
}
2120
}

src/ModelContextProtocol.AspNetCore/McpAuthorizationMiddleware.cs renamed to src/ModelContextProtocol.AspNetCore/AuthorizationMiddleware.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Microsoft.Extensions.Logging;
33
using Microsoft.Extensions.Options;
44
using ModelContextProtocol.Protocol.Auth;
5-
using ModelContextProtocol.Protocol.Types;
65
using ModelContextProtocol.Server;
76
using ModelContextProtocol.Utils.Json;
87
using System.Text.Json;
@@ -12,17 +11,17 @@ namespace ModelContextProtocol.AspNetCore;
1211
/// <summary>
1312
/// Middleware that handles authorization for MCP servers.
1413
/// </summary>
15-
internal class McpAuthorizationMiddleware
14+
internal class AuthorizationMiddleware
1615
{
1716
private readonly RequestDelegate _next;
18-
private readonly ILogger<McpAuthorizationMiddleware> _logger;
17+
private readonly ILogger<AuthorizationMiddleware> _logger;
1918

2019
/// <summary>
21-
/// Initializes a new instance of the <see cref="McpAuthorizationMiddleware"/> class.
20+
/// Initializes a new instance of the <see cref="AuthorizationMiddleware"/> class.
2221
/// </summary>
2322
/// <param name="next">The next middleware in the pipeline.</param>
2423
/// <param name="logger">The logger factory.</param>
25-
public McpAuthorizationMiddleware(RequestDelegate next, ILogger<McpAuthorizationMiddleware> logger)
24+
public AuthorizationMiddleware(RequestDelegate next, ILogger<AuthorizationMiddleware> logger)
2625
{
2726
_next = next ?? throw new ArgumentNullException(nameof(next));
2827
_logger = logger ?? throw new ArgumentNullException(nameof(logger));

src/ModelContextProtocol/McpAuthorizationException.cs renamed to src/ModelContextProtocol/AuthorizationException.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,52 @@ namespace ModelContextProtocol;
77
/// This exception is thrown when the client fails to authenticate with an MCP server that requires
88
/// authentication, such as when the OAuth authorization flow fails or when the server rejects the provided credentials.
99
/// </remarks>
10-
public class McpAuthorizationException : McpException
10+
public class AuthorizationException : McpException
1111
{
1212
/// <summary>
13-
/// Initializes a new instance of the <see cref="McpAuthorizationException"/> class.
13+
/// Initializes a new instance of the <see cref="AuthorizationException"/> class.
1414
/// </summary>
15-
public McpAuthorizationException()
15+
public AuthorizationException()
1616
: base("Authorization failed", McpErrorCode.InvalidRequest)
1717
{
1818
}
1919

2020
/// <summary>
21-
/// Initializes a new instance of the <see cref="McpAuthorizationException"/> class with a specified error message.
21+
/// Initializes a new instance of the <see cref="AuthorizationException"/> class with a specified error message.
2222
/// </summary>
2323
/// <param name="message">The message that describes the error.</param>
24-
public McpAuthorizationException(string message)
24+
public AuthorizationException(string message)
2525
: base(message, McpErrorCode.InvalidRequest)
2626
{
2727
}
2828

2929
/// <summary>
30-
/// Initializes a new instance of the <see cref="McpAuthorizationException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
30+
/// Initializes a new instance of the <see cref="AuthorizationException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
3131
/// </summary>
3232
/// <param name="message">The message that describes the error.</param>
3333
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
34-
public McpAuthorizationException(string message, Exception? innerException)
34+
public AuthorizationException(string message, Exception? innerException)
3535
: base(message, innerException, McpErrorCode.InvalidRequest)
3636
{
3737
}
3838

3939
/// <summary>
40-
/// Initializes a new instance of the <see cref="McpAuthorizationException"/> class with a specified error message and error code.
40+
/// Initializes a new instance of the <see cref="AuthorizationException"/> class with a specified error message and error code.
4141
/// </summary>
4242
/// <param name="message">The message that describes the error.</param>
4343
/// <param name="errorCode">The MCP error code. Should use one of the standard error codes.</param>
44-
public McpAuthorizationException(string message, McpErrorCode errorCode)
44+
public AuthorizationException(string message, McpErrorCode errorCode)
4545
: base(message, errorCode)
4646
{
4747
}
4848

4949
/// <summary>
50-
/// Initializes a new instance of the <see cref="McpAuthorizationException"/> class with a specified error message, inner exception, and error code.
50+
/// Initializes a new instance of the <see cref="AuthorizationException"/> class with a specified error message, inner exception, and error code.
5151
/// </summary>
5252
/// <param name="message">The message that describes the error.</param>
5353
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
5454
/// <param name="errorCode">The MCP error code. Should use one of the standard error codes.</param>
55-
public McpAuthorizationException(string message, Exception? innerException, McpErrorCode errorCode)
55+
public AuthorizationException(string message, Exception? innerException, McpErrorCode errorCode)
5656
: base(message, innerException, errorCode)
5757
{
5858
}

src/ModelContextProtocol/Configuration/McpServerAuthorizationExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class McpServerAuthorizationExtensions
1919
/// <exception cref="ArgumentNullException"><paramref name="builder"/> or <paramref name="authorizationProvider"/> is <see langword="null"/>.</exception>
2020
public static IMcpServerBuilder WithAuthorization(
2121
this IMcpServerBuilder builder,
22-
IMcpServerAuthorizationProvider authorizationProvider)
22+
IServerAuthorizationProvider authorizationProvider)
2323
{
2424
Throw.IfNull(builder);
2525
Throw.IfNull(authorizationProvider);

src/ModelContextProtocol/Protocol/Auth/McpAuthorizationOptions.cs renamed to src/ModelContextProtocol/Protocol/Auth/AuthorizationOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace ModelContextProtocol.Protocol.Auth;
66
/// <summary>
77
/// Provides authorization options for MCP clients.
88
/// </summary>
9-
public class McpAuthorizationOptions
9+
public class AuthorizationOptions
1010
{
1111
/// <summary>
1212
/// Gets or sets a delegate that handles the OAuth 2.0 authorization code flow.

src/ModelContextProtocol/Protocol/Auth/DefaultAuthorizationHandler.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal class DefaultAuthorizationHandler : IAuthorizationHandler
2525
/// </summary>
2626
/// <param name="loggerFactory">The logger factory.</param>
2727
/// <param name="options">The authorization options.</param>
28-
public DefaultAuthorizationHandler(ILoggerFactory? loggerFactory = null, McpAuthorizationOptions? options = null)
28+
public DefaultAuthorizationHandler(ILoggerFactory? loggerFactory = null, AuthorizationOptions? options = null)
2929
{
3030
_logger = loggerFactory != null
3131
? loggerFactory.CreateLogger<DefaultAuthorizationHandler>()
@@ -47,7 +47,7 @@ public DefaultAuthorizationHandler(ILoggerFactory? loggerFactory = null, McpAuth
4747
/// <param name="loggerFactory">The logger factory.</param>
4848
/// <param name="authorizeCallback">A callback function that handles the authorization code flow.</param>
4949
public DefaultAuthorizationHandler(ILoggerFactory? loggerFactory = null, Func<ClientMetadata, Task<(string RedirectUri, string Code)>>? authorizeCallback = null)
50-
: this(loggerFactory, new McpAuthorizationOptions { AuthorizeCallback = authorizeCallback })
50+
: this(loggerFactory, new AuthorizationOptions { AuthorizeCallback = authorizeCallback })
5151
{
5252
}
5353

@@ -90,7 +90,7 @@ public async Task<bool> HandleUnauthorizedResponseAsync(HttpResponseMessage resp
9090
_logger.LogWarning("Failed to extract resource metadata from 401 response");
9191

9292
// Create a more specific exception
93-
var exception = new McpAuthorizationException("Authorization required but no resource metadata available")
93+
var exception = new AuthorizationException("Authorization required but no resource metadata available")
9494
{
9595
ResourceUri = serverUri.ToString()
9696
};
@@ -106,7 +106,7 @@ public async Task<bool> HandleUnauthorizedResponseAsync(HttpResponseMessage resp
106106
_logger.LogWarning("Resource URL mismatch: expected {Expected}, got {Actual}",
107107
serverUri, resourceMetadata.Resource);
108108

109-
var exception = new McpAuthorizationException($"Resource URL mismatch: expected {serverUri}, got {resourceMetadata.Resource}");
109+
var exception = new AuthorizationException($"Resource URL mismatch: expected {serverUri}, got {resourceMetadata.Resource}");
110110
exception.ResourceUri = resourceMetadata.Resource;
111111
throw exception;
112112
}
@@ -116,7 +116,7 @@ public async Task<bool> HandleUnauthorizedResponseAsync(HttpResponseMessage resp
116116
{
117117
_logger.LogWarning("No authorization servers found in resource metadata");
118118

119-
var exception = new McpAuthorizationException("No authorization servers available");
119+
var exception = new AuthorizationException("No authorization servers available");
120120
exception.ResourceUri = resourceMetadata.Resource;
121121
throw exception;
122122
}
@@ -166,7 +166,7 @@ public async Task<bool> HandleUnauthorizedResponseAsync(HttpResponseMessage resp
166166
{
167167
_logger.LogWarning("Authorization server does not support dynamic client registration and no client ID was provided");
168168

169-
var exception = new McpAuthorizationException(
169+
var exception = new AuthorizationException(
170170
"Authorization server does not support dynamic client registration and no client ID was provided. " +
171171
"Use McpAuthorizationOptions.ClientId to provide a pre-registered client ID.");
172172
exception.ResourceUri = resourceMetadata.Resource;
@@ -179,7 +179,7 @@ public async Task<bool> HandleUnauthorizedResponseAsync(HttpResponseMessage resp
179179
{
180180
_logger.LogWarning("No authorization callback provided, can't proceed with OAuth flow");
181181

182-
var exception = new McpAuthorizationException(
182+
var exception = new AuthorizationException(
183183
"Authentication is required but no authorization callback was provided. " +
184184
"Use McpAuthorizationOptions.AuthorizeCallback to provide a callback function.");
185185
exception.ResourceUri = resourceMetadata.Resource;
@@ -227,11 +227,11 @@ public async Task<bool> HandleUnauthorizedResponseAsync(HttpResponseMessage resp
227227
_logger.LogDebug("Successfully obtained access token");
228228
return true;
229229
}
230-
catch (Exception ex) when (ex is not McpAuthorizationException)
230+
catch (Exception ex) when (ex is not AuthorizationException)
231231
{
232232
_logger.LogError(ex, "Failed to complete authorization flow");
233233

234-
var authException = new McpAuthorizationException(
234+
var authException = new AuthorizationException(
235235
$"Failed to complete authorization flow: {ex.Message}", ex, McpErrorCode.InvalidRequest);
236236

237237
authException.ResourceUri = resourceMetadata.Resource;

src/ModelContextProtocol/Protocol/Auth/IMcpServerAuthorizationProvider.cs renamed to src/ModelContextProtocol/Protocol/Auth/IServerAuthorizationProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ModelContextProtocol.Protocol.Auth;
99
/// This interface is implemented by authorization providers that enable MCP servers to validate tokens
1010
/// and control access to protected resources.
1111
/// </remarks>
12-
public interface IMcpServerAuthorizationProvider
12+
public interface IServerAuthorizationProvider
1313
{
1414
/// <summary>
1515
/// Gets the Protected Resource Metadata (PRM) for the server.

src/ModelContextProtocol/Protocol/Transport/SseClientTransport.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public SseClientTransport(SseClientTransportOptions transportOptions, HttpClient
6969
/// <param name="redirectPath">The path for the redirect URI. Default is "/callback".</param>
7070
/// <param name="successHtml">The HTML content to display on successful authorization. If null, a default message is shown.</param>
7171
/// <param name="errorHtml">The HTML template to display on failed authorization. If null, a default message is shown. Use {0} as a placeholder for the error message.</param>
72-
/// <returns>A delegate that can be used for the <see cref="McpAuthorizationOptions.AuthorizeCallback"/> property.</returns>
72+
/// <returns>A delegate that can be used for the <see cref="AuthorizationOptions.AuthorizeCallback"/> property.</returns>
7373
/// <remarks>
7474
/// <para>
7575
/// This method creates a delegate that implements a complete OAuth 2.0 authorization code flow using an HTTP listener.
@@ -211,7 +211,7 @@ public SseClientTransport(SseClientTransportOptions transportOptions, HttpClient
211211
/// <param name="openBrowser">A function that opens a URL in the browser.</param>
212212
/// <param name="listenPort">The local port to listen on for the redirect URI.</param>
213213
/// <param name="redirectPath">The path for the redirect URI.</param>
214-
/// <returns>A delegate that can be used for the <see cref="McpAuthorizationOptions.AuthorizeCallback"/> property.</returns>
214+
/// <returns>A delegate that can be used for the <see cref="AuthorizationOptions.AuthorizeCallback"/> property.</returns>
215215
/// <remarks>
216216
/// This is a convenience method that calls <see cref="CreateHttpListenerAuthorizeCallback"/> with "localhost" as the hostname.
217217
/// </remarks>

src/ModelContextProtocol/Protocol/Transport/SseClientTransportOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ public required Uri Endpoint
8888
/// </code>
8989
/// </para>
9090
/// </remarks>
91-
public McpAuthorizationOptions? AuthorizationOptions { get; init; }
91+
public AuthorizationOptions? AuthorizationOptions { get; init; }
9292
}

0 commit comments

Comments
 (0)