@@ -37,8 +37,8 @@ dotnet add package ModelContextProtocol --prerelease
3737
3838## Getting Started (Client)
3939
40- To get started writing a client, the ` McpClientFactory .CreateAsync` method is used to instantiate and connect an ` IMcpClient `
41- to a server. Once you have an ` IMcpClient ` , you can interact with it, such as to enumerate all available tools and invoke tools.
40+ To get started writing a client, the ` McpClient .CreateAsync` method is used to instantiate and connect an ` McpClient `
41+ to a server. Once you have an ` McpClient ` , you can interact with it, such as to enumerate all available tools and invoke tools.
4242
4343``` csharp
4444var clientTransport = new StdioClientTransport (new StdioClientTransportOptions
@@ -48,7 +48,7 @@ var clientTransport = new StdioClientTransport(new StdioClientTransportOptions
4848 Arguments = [" -y" , " @modelcontextprotocol/server-everything" ],
4949});
5050
51- var client = await McpClientFactory .CreateAsync (clientTransport );
51+ var client = await McpClient .CreateAsync (clientTransport );
5252
5353// Print the list of tools available from the server.
5454foreach (var tool in await client .ListToolsAsync ())
@@ -88,7 +88,7 @@ var response = await chatClient.GetResponseAsync(
8888Here is an example of how to create an MCP server and register all tools from the current application .
8989It includes a simple echo tool as an example (this is included in the same file here for easy of copy and paste , but it needn 't be in the same file ...
9090the employed overload of `WithTools ` examines the current assembly for classes with the `McpServerToolType ` attribute , and registers all methods with the
91- `McpTool ` attribute as tools .)
91+ `McpServerTool ` attribute as tools .)
9292
9393```
9494dotnet add package ModelContextProtocol --prerelease
@@ -122,14 +122,14 @@ public static class EchoTool
122122}
123123```
124124
125- Tools can have the `IMcpServer ` representing the server injected via a parameter to the method , and can use that for interaction with
125+ Tools can have the `McpServer ` representing the server injected via a parameter to the method , and can use that for interaction with
126126the connected client. Similarly, arguments may be injected via dependency injection. For example, this tool will use the supplied
127- `IMcpServer ` to make sampling requests back to the client in order to summarize content it downloads from the specified url via
127+ `McpServer ` to make sampling requests back to the client in order to summarize content it downloads from the specified url via
128128an `HttpClient` injected via dependency injection.
129129```csharp
130130[McpServerTool(Name = "SummarizeContentFromUrl"), Description("Summarizes content downloaded from a specific URI")]
131131public static async Task<string> SummarizeDownloadedContent(
132- IMcpServer thisServer,
132+ McpServer thisServer,
133133 HttpClient httpClient,
134134 [Description("The url from which to download the content to summarize")] string url,
135135 CancellationToken cancellationToken)
@@ -174,57 +174,54 @@ using System.Text.Json;
174174McpServerOptions options = new ()
175175{
176176 ServerInfo = new Implementation { Name = " MyServer" , Version = " 1.0.0" },
177- Capabilities = new ServerCapabilities
177+ Handlers = new McpServerHandlers ()
178178 {
179- Tools = new ToolsCapability
180- {
181- ListToolsHandler = (request , cancellationToken ) =>
182- ValueTask .FromResult (new ListToolsResult
183- {
184- Tools =
185- [
186- new Tool
187- {
188- Name = " echo" ,
189- Description = " Echoes the input back to the client." ,
190- InputSchema = JsonSerializer .Deserialize <JsonElement >("""
191- {
192- "type": "object",
193- "properties": {
194- "message": {
195- "type": "string",
196- "description": "The input to echo back"
197- }
198- },
199- "required": ["message"]
200- }
201- """ ),
202- }
203- ]
204- }),
205-
206- CallToolHandler = (request , cancellationToken ) =>
179+ ListToolsHandler = (request , cancellationToken ) =>
180+ ValueTask .FromResult (new ListToolsResult
207181 {
208- if ( request . Params ? . Name == " echo " )
209- {
210- if ( request . Params . Arguments ? . TryGetValue ( " message " , out var message ) is not true )
182+ Tools =
183+ [
184+ new Tool
211185 {
212- throw new McpException (" Missing required argument 'message'" );
186+ Name = " echo" ,
187+ Description = " Echoes the input back to the client." ,
188+ InputSchema = JsonSerializer .Deserialize <JsonElement >("""
189+ {
190+ "type": "object",
191+ "properties": {
192+ "message": {
193+ "type": "string",
194+ "description": "The input to echo back"
195+ }
196+ },
197+ "required": ["message"]
198+ }
199+ """ ),
213200 }
201+ ]
202+ }),
214203
215- return ValueTask .FromResult (new CallToolResult
216- {
217- Content = [new TextContentBlock { Text = $" Echo: {message }" , Type = " text" }]
218- });
204+ CallToolHandler = (request , cancellationToken ) =>
205+ {
206+ if (request .Params ? .Name == " echo" )
207+ {
208+ if (request .Params .Arguments ? .TryGetValue (" message" , out var message ) is not true )
209+ {
210+ throw new McpException (" Missing required argument 'message'" );
219211 }
220212
221- throw new McpException ($" Unknown tool: '{request .Params ? .Name }'" );
222- },
213+ return ValueTask .FromResult (new CallToolResult
214+ {
215+ Content = [new TextContentBlock { Text = $" Echo: {message }" , Type = " text" }]
216+ });
217+ }
218+
219+ throw new McpException ($" Unknown tool: '{request .Params ? .Name }'" );
223220 }
224- },
221+ }
225222};
226223
227- await using IMcpServer server = McpServerFactory .Create (new StdioServerTransport (" MyServer" ), options );
224+ await using McpServer server = McpServer .Create (new StdioServerTransport (" MyServer" ), options );
228225await server .RunAsync ();
229226```
230227
0 commit comments