Skip to content

Commit 32a03c8

Browse files
jeffhandleyCopilot
andcommitted
Fix compilation errors in README code samples
- Core README client sample: Use .OfType<TextContentBlock>() instead of .First(c => c.Type == "text").Text since ContentBlock base class lacks Text - Core README server sample: Use McpServerOptions.ToolCollection, McpServer.Create(), StdioServerTransport(name), and await using - Root README advanced server: Remove read-only Type property from TextContentBlock initializer - Both IChatClient snippets: Fix trailing comma and missing closing paren Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 124b43b commit 32a03c8

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ IList<McpClientTool> tools = await client.ListToolsAsync();
8383
IChatClient chatClient = ...;
8484
var response = await chatClient.GetResponseAsync(
8585
"your prompt here",
86-
new() { Tools = [.. tools] },
86+
new() { Tools = [.. tools] });
8787
```
8888

8989
## Getting Started (Server)
@@ -218,7 +218,7 @@ McpServerOptions options = new()
218218

219219
return ValueTask.FromResult(new CallToolResult
220220
{
221-
Content = [new TextContentBlock { Text = $"Echo: {message}", Type = "text" }]
221+
Content = [new TextContentBlock { Text = $"Echo: {message}" }]
222222
});
223223
}
224224

src/ModelContextProtocol.Core/README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var result = await client.CallToolAsync(
5353
cancellationToken: CancellationToken.None);
5454

5555
// echo always returns one and only one text content object
56-
Console.WriteLine(result.Content.First(c => c.Type == "text").Text);
56+
Console.WriteLine(result.Content.OfType<TextContentBlock>().First().Text);
5757
```
5858

5959
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();
6868
IChatClient chatClient = ...;
6969
var response = await chatClient.GetResponseAsync(
7070
"your prompt here",
71-
new() { Tools = [.. tools] },
71+
new() { Tools = [.. tools] });
7272
```
7373

7474
## Getting Started (Server)
@@ -79,13 +79,9 @@ The core package provides the basic server functionality. Here's an example of c
7979
using ModelContextProtocol.Server;
8080
using System.ComponentModel;
8181

82-
// Create server options
83-
var serverOptions = new McpServerOptions();
84-
85-
// Add tools directly
86-
serverOptions.Capabilities.Tools = new()
82+
// Create server options with tools
83+
var serverOptions = new McpServerOptions
8784
{
88-
ListChanged = true,
8985
ToolCollection = [
9086
McpServerTool.Create((string message) => $"hello {message}", new()
9187
{
@@ -96,9 +92,9 @@ serverOptions.Capabilities.Tools = new()
9692
};
9793

9894
// Create and run server with stdio transport
99-
var server = new McpServer(serverOptions);
100-
using var stdioTransport = new StdioServerTransport();
101-
await server.RunAsync(stdioTransport, CancellationToken.None);
95+
await using var stdioTransport = new StdioServerTransport("EchoServer");
96+
await using var server = McpServer.Create(stdioTransport, serverOptions);
97+
await server.RunAsync(CancellationToken.None);
10298
```
10399

104100
For more advanced scenarios with dependency injection, hosting, and automatic tool discovery, see the `ModelContextProtocol` package.

0 commit comments

Comments
 (0)