Skip to content

Commit 898a6da

Browse files
authored
Add Authentication Options for MCP Client Connections (#341)
1 parent b783afa commit 898a6da

File tree

63 files changed

+2376
-628
lines changed

Some content is hidden

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

63 files changed

+2376
-628
lines changed

Directory.Build.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<Authors>Mike Alhayek</Authors>
2525
<Company>CrestApps</Company>
2626
<PackageIcon>CrestAppsLogo.png</PackageIcon>
27+
<PackageReadmeFile>README.md</PackageReadmeFile>
2728
<IsPackable>true</IsPackable>
2829
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2930
<RepositoryUrl>https://github.com/CrestApps/CrestApps.OrchardCore</RepositoryUrl>
@@ -37,6 +38,10 @@
3738
<Pack>True</Pack>
3839
<PackagePath>CrestAppsLogo.png</PackagePath>
3940
</None>
41+
<None Include="$(MSBuildThisFileDirectory)/src/README.md">
42+
<Pack>True</Pack>
43+
<PackagePath>README.md</PackagePath>
44+
</None>
4045
</ItemGroup>
4146

4247
<PropertyGroup>

src/Core/CrestApps.OrchardCore.AI.Chat.Interactions.Core/README.md

Lines changed: 0 additions & 218 deletions
This file was deleted.

src/Core/CrestApps.OrchardCore.AI.Mcp.Core/CrestApps.OrchardCore.AI.Mcp.Core.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
<PackageTags>$(PackageTags) AI MCP ModelContextProtocol</PackageTags>
1111
</PropertyGroup>
1212

13-
<ItemGroup>
14-
<Compile Remove="Handlers\**" />
15-
<EmbeddedResource Remove="Handlers\**" />
16-
<None Remove="Handlers\**" />
17-
</ItemGroup>
1813

1914
<ItemGroup>
2015
<PackageReference Include="OrchardCore.Infrastructure.Abstractions" />

src/Core/CrestApps.OrchardCore.AI.Mcp.Core/IMcpClientTransportProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ public interface IMcpClientTransportProvider
1919
/// </summary>
2020
/// <param name="connection">The MCP connection for which to obtain a transport.</param>
2121
/// <returns>An <see cref="IClientTransport"/> that can be used with the given connection.</returns>
22-
IClientTransport Get(McpConnection connection);
22+
Task<IClientTransport> GetAsync(McpConnection connection);
2323
}

src/Core/CrestApps.OrchardCore.AI.Mcp.Core/McpConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ namespace CrestApps.OrchardCore.AI.Mcp.Core;
22

33
public static class McpConstants
44
{
5+
public const string DataProtectionPurpose = "McpClientConnection";
6+
57
public static class Feature
68
{
79
public const string Area = "CrestApps.OrchardCore.AI.Mcp";

src/Core/CrestApps.OrchardCore.AI.Mcp.Core/McpService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public McpService(
1717
_logger = logger;
1818
}
1919

20-
public Task<McpClient> GetOrCreateClientAsync(McpConnection connection)
20+
public async Task<McpClient> GetOrCreateClientAsync(McpConnection connection)
2121
{
2222
ArgumentNullException.ThrowIfNull(connection);
2323

@@ -30,7 +30,7 @@ public Task<McpClient> GetOrCreateClientAsync(McpConnection connection)
3030
continue;
3131
}
3232

33-
transport = provider.Get(connection);
33+
transport = await provider.GetAsync(connection);
3434
}
3535

3636
if (transport is null)
@@ -40,6 +40,6 @@ public Task<McpClient> GetOrCreateClientAsync(McpConnection connection)
4040
return null;
4141
}
4242

43-
return McpClient.CreateAsync(transport);
43+
return await McpClient.CreateAsync(transport);
4444
}
4545
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace CrestApps.OrchardCore.AI.Mcp.Core.Models;
2+
3+
public enum McpClientAuthenticationType
4+
{
5+
Anonymous,
6+
ApiKey,
7+
Basic,
8+
OAuth2ClientCredentials,
9+
OAuth2PrivateKeyJwt,
10+
OAuth2Mtls,
11+
CustomHeaders,
12+
}

src/Core/CrestApps.OrchardCore.AI.Mcp.Core/Models/SseMcpConnectionMetadata.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,39 @@ public sealed class SseMcpConnectionMetadata
44
{
55
public Uri Endpoint { get; set; }
66

7+
public McpClientAuthenticationType AuthenticationType { get; set; }
8+
9+
// API Key authentication.
10+
public string ApiKeyHeaderName { get; set; }
11+
12+
public string ApiKeyPrefix { get; set; }
13+
14+
public string ApiKey { get; set; }
15+
16+
// Basic authentication.
17+
public string BasicUsername { get; set; }
18+
19+
public string BasicPassword { get; set; }
20+
21+
// OAuth 2.0 Client Credentials.
22+
public string OAuth2TokenEndpoint { get; set; }
23+
24+
public string OAuth2ClientId { get; set; }
25+
26+
public string OAuth2ClientSecret { get; set; }
27+
28+
public string OAuth2Scopes { get; set; }
29+
30+
// OAuth 2.0 Private Key JWT.
31+
public string OAuth2PrivateKey { get; set; }
32+
33+
public string OAuth2KeyId { get; set; }
34+
35+
// OAuth 2.0 Mutual TLS (mTLS).
36+
public string OAuth2ClientCertificate { get; set; }
37+
38+
public string OAuth2ClientCertificatePassword { get; set; }
39+
40+
// Custom headers (advanced / legacy).
741
public Dictionary<string, string> AdditionalHeaders { get; set; }
842
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace CrestApps.OrchardCore.AI.Mcp.Core.Services;
2+
3+
public interface IOAuth2TokenService
4+
{
5+
/// <summary>
6+
/// Acquires an access token using the OAuth 2.0 client credentials grant.
7+
/// </summary>
8+
Task<string> AcquireTokenAsync(string tokenEndpoint, string clientId, string clientSecret, string scopes = null, CancellationToken cancellationToken = default);
9+
10+
/// <summary>
11+
/// Acquires an access token using the OAuth 2.0 client credentials grant with a private key JWT client assertion.
12+
/// </summary>
13+
Task<string> AcquireTokenWithPrivateKeyJwtAsync(string tokenEndpoint, string clientId, string privateKeyPem, string keyId = null, string scopes = null, CancellationToken cancellationToken = default);
14+
15+
/// <summary>
16+
/// Acquires an access token using the OAuth 2.0 client credentials grant with mutual TLS (mTLS) client authentication.
17+
/// </summary>
18+
Task<string> AcquireTokenWithMtlsAsync(string tokenEndpoint, string clientId, byte[] clientCertificateBytes, string certificatePassword = null, string scopes = null, CancellationToken cancellationToken = default);
19+
}

src/Core/CrestApps.OrchardCore.AI.Mcp.Core/Services/SseClientTransportProvider.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)