Fix compilation errors in README code samples (#1369)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Jeff Handley 2026-02-23 19:32:18 -08:00 • committed by GitHub
commit 1446cd738c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 13 deletions

View file

@ -83,7 +83,7 @@ IList<McpClientTool> tools = await client.ListToolsAsync();
IChatClient chatClient = ...; IChatClient chatClient = ...;
var response = await chatClient.GetResponseAsync( var response = await chatClient.GetResponseAsync(
"your prompt here", "your prompt here",
new() { Tools = [.. tools] }, new() { Tools = [.. tools] });
``` ```
## Getting Started (Server) ## Getting Started (Server)
@ -218,7 +218,7 @@ McpServerOptions options = new()
return ValueTask.FromResult(new CallToolResult return ValueTask.FromResult(new CallToolResult
{ {
Content = [new TextContentBlock { Text = $"Echo: {message}", Type = "text" }] Content = [new TextContentBlock { Text = $"Echo: {message}" }]
}); });
} }

View file

@ -53,7 +53,7 @@ var result = await client.CallToolAsync(
cancellationToken: CancellationToken.None); cancellationToken: CancellationToken.None);
// echo always returns one and only one text content object // echo always returns one and only one text content object
Console.WriteLine(result.Content.First(c => c.Type == "text").Text); Console.WriteLine(result.Content.OfType<TextContentBlock>().First().Text);
``` ```
Clients can connect to any MCP server, not just ones created using this library. The protocol is designed to be server-agnostic, so you can use this library to connect to any compliant server. Clients can connect to any MCP server, not just ones created using this library. The protocol is designed to be server-agnostic, so you can use this library to connect to any compliant server.
@ -68,7 +68,7 @@ IList<McpClientTool> tools = await client.ListToolsAsync();
IChatClient chatClient = ...; IChatClient chatClient = ...;
var response = await chatClient.GetResponseAsync( var response = await chatClient.GetResponseAsync(
"your prompt here", "your prompt here",
new() { Tools = [.. tools] }, new() { Tools = [.. tools] });
``` ```
## Getting Started (Server) ## Getting Started (Server)
@ -79,13 +79,9 @@ The core package provides the basic server functionality. Here's an example of c
using ModelContextProtocol.Server; using ModelContextProtocol.Server;
using System.ComponentModel; using System.ComponentModel;
// Create server options // Create server options with tools
var serverOptions = new McpServerOptions(); var serverOptions = new McpServerOptions
// Add tools directly
serverOptions.Capabilities.Tools = new()
{ {
ListChanged = true,
ToolCollection = [ ToolCollection = [
McpServerTool.Create((string message) => $"hello {message}", new() McpServerTool.Create((string message) => $"hello {message}", new()
{ {
@ -96,9 +92,9 @@ serverOptions.Capabilities.Tools = new()
}; };
// Create and run server with stdio transport // Create and run server with stdio transport
var server = new McpServer(serverOptions); await using var stdioTransport = new StdioServerTransport("EchoServer");
using var stdioTransport = new StdioServerTransport(); await using var server = McpServer.Create(stdioTransport, serverOptions);
await server.RunAsync(stdioTransport, CancellationToken.None); await server.RunAsync(CancellationToken.None);
``` ```
For more advanced scenarios with dependency injection, hosting, and automatic tool discovery, see the `ModelContextProtocol` package. For more advanced scenarios with dependency injection, hosting, and automatic tool discovery, see the `ModelContextProtocol` package.