diff --git a/README.md b/README.md index d282e9af3..2ab5af6f9 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ IList tools = await client.ListToolsAsync(); IChatClient chatClient = ...; var response = await chatClient.GetResponseAsync( "your prompt here", - new() { Tools = [.. tools] }, + new() { Tools = [.. tools] }); ``` ## Getting Started (Server) @@ -218,7 +218,7 @@ McpServerOptions options = new() return ValueTask.FromResult(new CallToolResult { - Content = [new TextContentBlock { Text = $"Echo: {message}", Type = "text" }] + Content = [new TextContentBlock { Text = $"Echo: {message}" }] }); } diff --git a/src/ModelContextProtocol.Core/README.md b/src/ModelContextProtocol.Core/README.md index 69913a150..33cf3bcd2 100644 --- a/src/ModelContextProtocol.Core/README.md +++ b/src/ModelContextProtocol.Core/README.md @@ -53,7 +53,7 @@ var result = await client.CallToolAsync( cancellationToken: CancellationToken.None); // 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().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. @@ -68,7 +68,7 @@ IList tools = await client.ListToolsAsync(); IChatClient chatClient = ...; var response = await chatClient.GetResponseAsync( "your prompt here", - new() { Tools = [.. tools] }, + new() { Tools = [.. tools] }); ``` ## 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 System.ComponentModel; -// Create server options -var serverOptions = new McpServerOptions(); - -// Add tools directly -serverOptions.Capabilities.Tools = new() +// Create server options with tools +var serverOptions = new McpServerOptions { - ListChanged = true, ToolCollection = [ McpServerTool.Create((string message) => $"hello {message}", new() { @@ -96,9 +92,9 @@ serverOptions.Capabilities.Tools = new() }; // Create and run server with stdio transport -var server = new McpServer(serverOptions); -using var stdioTransport = new StdioServerTransport(); -await server.RunAsync(stdioTransport, CancellationToken.None); +await using var stdioTransport = new StdioServerTransport("EchoServer"); +await using var server = McpServer.Create(stdioTransport, serverOptions); +await server.RunAsync(CancellationToken.None); ``` For more advanced scenarios with dependency injection, hosting, and automatic tool discovery, see the `ModelContextProtocol` package.