File tree Expand file tree Collapse file tree 5 files changed +38
-7
lines changed
ModelContextProtocolClientServer
ModelContextProtocolPlugin Expand file tree Collapse file tree 5 files changed +38
-7
lines changed Original file line number Diff line number Diff line change 2929 <PackageVersion Include =" EntityFramework" Version =" 6.5.1" />
3030 <PackageVersion Include =" FastBertTokenizer" Version =" 1.0.28" />
3131 <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 " />
3333 <PackageVersion Include =" Microsoft.AspNetCore.Mvc.Testing" Version =" 8.0.13" />
3434 <PackageVersion Include =" Microsoft.AspNetCore.OpenApi" Version =" 8.0.14" />
3535 <PackageVersion Include =" Microsoft.ML.Tokenizers.Data.Cl100kBase" Version =" 1.0.1" />
Original file line number Diff line number Diff line change 99using Microsoft . Extensions . Logging ;
1010using Microsoft . SemanticKernel ;
1111using Microsoft . SemanticKernel . Connectors . OpenAI ;
12+ using ModelContextProtocol ;
1213using ModelContextProtocol . Client ;
13- using ModelContextProtocol . Configuration ;
1414using ModelContextProtocol . Protocol . Transport ;
1515
1616namespace MCPClient ;
@@ -52,7 +52,7 @@ public static async Task Main(string[] args)
5252
5353 // Retrieve and display the list of tools available on the MCP server
5454 Console . WriteLine ( "Available MCP tools:" ) ;
55- var tools = await mcpClient . GetAIFunctionsAsync ( ) . ConfigureAwait ( false ) ;
55+ var tools = await mcpClient . ListToolsAsync ( ) . ConfigureAwait ( false ) ;
5656 foreach ( var tool in tools )
5757 {
5858 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 11// Copyright (c) Microsoft. All rights reserved.
22
3+ using MCPServer ;
34using MCPServer . Tools ;
45using Microsoft . SemanticKernel ;
5- using ModelContextProtocol ;
66
77// Create a kernel builder and add plugins
88IKernelBuilder kernelBuilder = Kernel . CreateBuilder ( ) ;
1616builder . Services
1717 . AddMcpServer ( )
1818 . 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 ) ;
2121await builder . Build ( ) . RunAsync ( ) ;
Original file line number Diff line number Diff line change 3434 new ( ) { ClientInfo = new ( ) { Name = "GitHub" , Version = "1.0.0" } } ) . ConfigureAwait ( false ) ;
3535
3636// 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 ) ;
3838foreach ( var tool in tools )
3939{
4040 Console . WriteLine ( $ "{ tool . Name } : { tool . Description } ") ;
You can’t perform that action at this time.
0 commit comments