ModelContextProtocol.Core
Advanced tools
Sorry, the diff of this file is not supported yet
@@ -5,3 +5,3 @@ <?xml version="1.0" encoding="utf-8"?> | ||
| <id>ModelContextProtocol.Core</id> | ||
| <version>1.0.0</version> | ||
| <version>1.1.0</version> | ||
| <authors>ModelContextProtocol</authors> | ||
@@ -14,5 +14,5 @@ <license type="expression">Apache-2.0</license> | ||
| <description>Core .NET SDK for the Model Context Protocol (MCP)</description> | ||
| <copyright>© Anthropic and Contributors.</copyright> | ||
| <copyright>© Model Context Protocol a Series of LF Projects, LLC.</copyright> | ||
| <tags>ModelContextProtocol mcp ai llm</tags> | ||
| <repository type="git" url="https://github.com/modelcontextprotocol/csharp-sdk" commit="551db0d954ec8b23ac3c3b21470f1b1cd1ba90d3" /> | ||
| <repository type="git" url="https://github.com/modelcontextprotocol/csharp-sdk" commit="ca040d77ec885fc7ac7649487722adaf33a4fd3f" /> | ||
| <dependencies> | ||
@@ -19,0 +19,0 @@ <group targetFramework="net8.0"> |
+18
-86
@@ -1,100 +0,32 @@ | ||
| # MCP C# SDK Core | ||
| # MCP C# SDK | ||
| [](https://www.nuget.org/packages/ModelContextProtocol.Core/absoluteLatest) | ||
| [](https://www.nuget.org/packages/ModelContextProtocol) | ||
| Core .NET SDK for the [Model Context Protocol](https://modelcontextprotocol.io/), enabling .NET applications, services, and libraries to implement and interact with MCP clients and servers. Please visit our [API documentation](https://modelcontextprotocol.github.io/csharp-sdk/api/ModelContextProtocol.html) for more details on available functionality. | ||
| The official C# SDK for the [Model Context Protocol](https://modelcontextprotocol.io/), enabling .NET applications, services, and libraries to implement and interact with MCP clients and servers. Please visit the [API documentation](https://modelcontextprotocol.github.io/csharp-sdk/api/ModelContextProtocol.html) for more details on available functionality. | ||
| > [!NOTE] | ||
| > This project is in preview; breaking changes can be introduced without prior notice. | ||
| ## Packages | ||
| ## About MCP | ||
| This SDK consists of three main packages: | ||
| The Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to Large Language Models (LLMs). It enables secure integration between LLMs and various data sources and tools. | ||
| - **[ModelContextProtocol.Core](https://www.nuget.org/packages/ModelContextProtocol.Core)** [](https://www.nuget.org/packages/ModelContextProtocol.Core) - For projects that only need to use the client or low-level server APIs and want the minimum number of dependencies. | ||
| For more information about MCP: | ||
| - **[ModelContextProtocol](https://www.nuget.org/packages/ModelContextProtocol)** [](https://www.nuget.org/packages/ModelContextProtocol) - The main package with hosting and dependency injection extensions. References `ModelContextProtocol.Core`. This is the right fit for most projects that don't need HTTP server capabilities. | ||
| - [Official Documentation](https://modelcontextprotocol.io/) | ||
| - [Protocol Specification](https://modelcontextprotocol.io/specification/) | ||
| - [GitHub Organization](https://github.com/modelcontextprotocol) | ||
| - **[ModelContextProtocol.AspNetCore](https://www.nuget.org/packages/ModelContextProtocol.AspNetCore)** [](https://www.nuget.org/packages/ModelContextProtocol.AspNetCore) - The library for HTTP-based MCP servers. References `ModelContextProtocol`. | ||
| ## Installation | ||
| ## Getting Started | ||
| To get started, install the core package from NuGet | ||
| To get started, see the [Getting Started](https://modelcontextprotocol.github.io/csharp-sdk/concepts/getting-started.html) guide for installation instructions, package-selection guidance, and complete examples for both clients and servers. | ||
| ``` | ||
| dotnet add package ModelContextProtocol.Core --prerelease | ||
| ``` | ||
| You can also browse the [samples](https://github.com/modelcontextprotocol/csharp-sdk/tree/main/samples) directory and the [API documentation](https://modelcontextprotocol.github.io/csharp-sdk/api/ModelContextProtocol.html) for more details on available functionality. | ||
| ## Getting Started (Client) | ||
| ## About MCP | ||
| To get started writing a client, the `McpClient.CreateAsync` method is used to instantiate and connect an `McpClient` | ||
| to a server. Once you have an `McpClient`, you can interact with it, such as to enumerate all available tools and invoke tools. | ||
| The Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to Large Language Models (LLMs). It enables secure integration between LLMs and various data sources and tools. | ||
| ```csharp | ||
| var clientTransport = new StdioClientTransport(new StdioClientTransportOptions | ||
| { | ||
| Name = "Everything", | ||
| Command = "npx", | ||
| Arguments = ["-y", "@modelcontextprotocol/server-everything"], | ||
| }); | ||
| For more information about MCP: | ||
| var client = await McpClient.CreateAsync(clientTransport); | ||
| // Print the list of tools available from the server. | ||
| foreach (var tool in await client.ListToolsAsync()) | ||
| { | ||
| Console.WriteLine($"{tool.Name} ({tool.Description})"); | ||
| } | ||
| // Execute a tool (this would normally be driven by LLM tool invocations). | ||
| var result = await client.CallToolAsync( | ||
| "echo", | ||
| new Dictionary<string, object?>() { ["message"] = "Hello MCP!" }, | ||
| cancellationToken: CancellationToken.None); | ||
| // echo always returns one and only one text content object | ||
| 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. | ||
| Tools can be easily exposed for immediate use by `IChatClient`s, because `McpClientTool` inherits from `AIFunction`. | ||
| ```csharp | ||
| // Get available functions. | ||
| IList<McpClientTool> tools = await client.ListToolsAsync(); | ||
| // Call the chat client using the tools. | ||
| IChatClient chatClient = ...; | ||
| var response = await chatClient.GetResponseAsync( | ||
| "your prompt here", | ||
| new() { Tools = [.. tools] }); | ||
| ``` | ||
| ## Getting Started (Server) | ||
| The core package provides the basic server functionality. Here's an example of creating a simple MCP server without dependency injection: | ||
| ```csharp | ||
| using ModelContextProtocol.Server; | ||
| using System.ComponentModel; | ||
| // Create server options with tools | ||
| var serverOptions = new McpServerOptions | ||
| { | ||
| ToolCollection = [ | ||
| McpServerTool.Create((string message) => $"hello {message}", new() | ||
| { | ||
| Name = "echo", | ||
| Description = "Echoes the message back to the client." | ||
| }) | ||
| ] | ||
| }; | ||
| // Create and run server with stdio transport | ||
| 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. | ||
| - [Official MCP Documentation](https://modelcontextprotocol.io/) | ||
| - [MCP C# SDK Documentation](https://modelcontextprotocol.github.io/csharp-sdk/) | ||
| - [Protocol Specification](https://modelcontextprotocol.io/specification/) | ||
| - [GitHub Organization](https://github.com/modelcontextprotocol) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display