File tree 5 files changed +38
-7
lines changed
ModelContextProtocolClientServer
ModelContextProtocolPlugin
5 files changed +38
-7
lines changed Original file line number Diff line number Diff line change 29
29
<PackageVersion Include =" EntityFramework" Version =" 6.5.1" />
30
30
<PackageVersion Include =" FastBertTokenizer" Version =" 1.0.28" />
31
31
<PackageVersion Include =" Google.Apis.Auth" Version =" 1.69.0" />
32
- <PackageVersion Include =" ModelContextProtocol" Version =" 0.1.0-preview.1.25171.12 " />
32
+ <PackageVersion Include =" ModelContextProtocol" Version =" 0.1.0-preview.4 " />
33
33
<PackageVersion Include =" Microsoft.AspNetCore.Mvc.Testing" Version =" 8.0.13" />
34
34
<PackageVersion Include =" Microsoft.AspNetCore.OpenApi" Version =" 8.0.14" />
35
35
<PackageVersion Include =" Microsoft.ML.Tokenizers.Data.Cl100kBase" Version =" 1.0.1" />
Original file line number Diff line number Diff line change 9
9
using Microsoft . Extensions . Logging ;
10
10
using Microsoft . SemanticKernel ;
11
11
using Microsoft . SemanticKernel . Connectors . OpenAI ;
12
+ using ModelContextProtocol ;
12
13
using ModelContextProtocol . Client ;
13
- using ModelContextProtocol . Configuration ;
14
14
using ModelContextProtocol . Protocol . Transport ;
15
15
16
16
namespace MCPClient ;
@@ -52,7 +52,7 @@ public static async Task Main(string[] args)
52
52
53
53
// Retrieve and display the list of tools available on the MCP server
54
54
Console . WriteLine ( "Available MCP tools:" ) ;
55
- var tools = await mcpClient . GetAIFunctionsAsync ( ) . ConfigureAwait ( false ) ;
55
+ var tools = await mcpClient . ListToolsAsync ( ) . ConfigureAwait ( false ) ;
56
56
foreach ( var tool in tools )
57
57
{
58
58
Console . WriteLine ( $ "{ tool . Name } : { tool . Description } ") ;
Original file line number Diff line number Diff line change
1
+ // Copyright (c) Microsoft. All rights reserved.
2
+
3
+ using Microsoft . SemanticKernel ;
4
+ using ModelContextProtocol . Server ;
5
+
6
+ namespace MCPServer ;
7
+
8
+ /// <summary>
9
+ /// Extension methods for <see cref="IMcpServerBuilder"/>.
10
+ /// </summary>
11
+ public static class McpServerBuilderExtensions
12
+ {
13
+ /// <summary>
14
+ /// Adds all functions of the kernel plugins as tools to the server.
15
+ /// </summary>
16
+ /// <param name="builder">The builder instance.</param>
17
+ /// <param name="plugins">The kernel plugins to add as tools to the server.</param>
18
+ /// <returns>The builder instance.</returns>
19
+ public static IMcpServerBuilder WithTools ( this IMcpServerBuilder builder , KernelPluginCollection plugins )
20
+ {
21
+ foreach ( var plugin in plugins )
22
+ {
23
+ foreach ( var function in plugin )
24
+ {
25
+ builder . Services . AddSingleton ( services => McpServerTool . Create ( function . AsAIFunction ( ) ) ) ;
26
+ }
27
+ }
28
+
29
+ return builder ;
30
+ }
31
+ }
Original file line number Diff line number Diff line change 1
1
// Copyright (c) Microsoft. All rights reserved.
2
2
3
+ using MCPServer ;
3
4
using MCPServer . Tools ;
4
5
using Microsoft . SemanticKernel ;
5
- using ModelContextProtocol ;
6
6
7
7
// Create a kernel builder and add plugins
8
8
IKernelBuilder kernelBuilder = Kernel . CreateBuilder ( ) ;
16
16
builder . Services
17
17
. AddMcpServer ( )
18
18
. WithStdioServerTransport ( )
19
- // Add kernel functions to the MCP server as MCP tools
20
- . WithTools ( kernel . Plugins . SelectMany ( p => p . Select ( f => f . AsAIFunction ( ) ) ) ) ;
19
+ // Add all functions from the kernel plugins to the MCP server as tools
20
+ . WithTools ( kernel . Plugins ) ;
21
21
await builder . Build ( ) . RunAsync ( ) ;
Original file line number Diff line number Diff line change 34
34
new ( ) { ClientInfo = new ( ) { Name = "GitHub" , Version = "1.0.0" } } ) . ConfigureAwait ( false ) ;
35
35
36
36
// Retrieve the list of tools available on the GitHub server
37
- var tools = await mcpClient . GetAIFunctionsAsync ( ) . ConfigureAwait ( false ) ;
37
+ var tools = await mcpClient . ListToolsAsync ( ) . ConfigureAwait ( false ) ;
38
38
foreach ( var tool in tools )
39
39
{
40
40
Console . WriteLine ( $ "{ tool . Name } : { tool . Description } ") ;
You can’t perform that action at this time.
0 commit comments