File tree Expand file tree Collapse file tree 4 files changed +46
-4
lines changed
samples/WeihanLi.Web.Extensions.Samples Expand file tree Collapse file tree 4 files changed +46
-4
lines changed Original file line number Diff line number Diff line change 2
2
<PropertyGroup >
3
3
<ManagePackageVersionsCentrally >true</ManagePackageVersionsCentrally >
4
4
<CentralPackageFloatingVersionsEnabled >true</CentralPackageFloatingVersionsEnabled >
5
- <!-- https://learn.microsoft.com/en-us/nuget/concepts/auditing-packages -->
6
- <NuGetAudit >true</NuGetAudit >
5
+ <!-- https://learn.microsoft.com/en-us/nuget/concepts/auditing-packages -->
6
+ <NuGetAudit >true</NuGetAudit >
7
7
<NuGetAuditMode >all</NuGetAuditMode >
8
8
<!-- https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1901-nu1904 -->
9
9
<WarningsAsErrors >NU1901;NU1902;NU1903;NU1904</WarningsAsErrors >
16
16
<PackageVersion Condition =" '$(TargetFramework)'=='net9.0'" Include =" Microsoft.AspNetCore.Authentication.JwtBearer" Version =" $(AspNet9PackageVersion)" />
17
17
<PackageVersion Condition =" '$(TargetFramework)'=='net10.0'" Include =" Microsoft.AspNetCore.Authentication.JwtBearer" Version =" $(AspNet10PackageVersion)" />
18
18
<PackageVersion Include =" Microsoft.AspNetCore.OpenApi" Version =" $(AspNet10PackageVersion)" />
19
+ <PackageVersion Include =" ModelContextProtocol.AspNetCore" Version =" 0.1.0-preview.10" />
19
20
<PackageVersion Include =" Scalar.AspNetCore" Version =" 2.1.17" />
20
21
<PackageVersion Include =" WeihanLi.Common" Version =" 1.0.77" />
21
22
</ItemGroup >
22
- </Project >
23
+ </Project >
Original file line number Diff line number Diff line change
1
+ // Copyright (c) Weihan Li. All rights reserved.
2
+ // Licensed under the MIT license.
3
+
4
+ namespace WeihanLi . Web . Extensions . Samples ;
5
+
6
+ public interface IMcpToolEndpointMetadata
7
+ {
8
+ string Name { get ; set ; }
9
+ string Description { get ; set ; }
10
+ }
11
+
12
+ public class McpToolEndpointMetadata : IMcpToolEndpointMetadata
13
+ {
14
+ public string Name { get ; set ; } = string . Empty ;
15
+ public string Description { get ; set ; } = string . Empty ;
16
+ }
17
+
18
+ public static class McpToolExtension
19
+ {
20
+ public static IEndpointConventionBuilder AsMcpTool < TBuilder > ( this TBuilder builder , Action < McpToolEndpointMetadata > ? toolConfigure = null )
21
+ where TBuilder : IEndpointConventionBuilder
22
+ {
23
+ ArgumentNullException . ThrowIfNull ( builder ) ;
24
+ var metadata = new McpToolEndpointMetadata ( ) ;
25
+ toolConfigure ? . Invoke ( metadata ) ;
26
+ builder . Add ( c =>
27
+ {
28
+ if ( string . IsNullOrEmpty ( metadata . Name ) )
29
+ {
30
+ metadata . Name = c . DisplayName ! ;
31
+ }
32
+ if ( string . IsNullOrEmpty ( metadata . Description ) )
33
+ {
34
+ metadata . Description = c . DisplayName ! ;
35
+ }
36
+ c . Metadata . Add ( metadata ) ;
37
+ } ) ;
38
+ return builder ;
39
+ }
40
+ }
Original file line number Diff line number Diff line change 87
87
options . UserIdFactory = static context => $ "{ context . GetUserIP ( ) } ";
88
88
} ) ;
89
89
90
- // builder.Services.AddEndpointsApiExplorer();
90
+ builder . Services . AddEndpointsApiExplorer ( ) ;
91
91
builder . Services . AddOpenApi ( ) ;
92
92
93
93
builder . Host . UseFluentAspectsServiceProviderFactory ( options =>
Original file line number Diff line number Diff line change 11
11
12
12
<ItemGroup >
13
13
<PackageReference Include =" Microsoft.AspNetCore.OpenApi" />
14
+ <PackageReference Include =" ModelContextProtocol.AspNetCore" />
14
15
<PackageReference Include =" Scalar.AspNetCore" />
15
16
</ItemGroup >
16
17
</Project >
You can’t perform that action at this time.
0 commit comments