Simplify and update package README.md files for stable release (#1388)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: jeffhandley <1031940+jeffhandley@users.noreply.github.com> Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: Jeff Handley <jeffhandley@users.noreply.github.com>
This commit is contained in:
parent
a7df4254af
commit
1108117d6f
7 changed files with 40 additions and 159 deletions
|
|
@ -8,11 +8,11 @@ The official C# SDK for the [Model Context Protocol](https://modelcontextprotoco
|
||||||
|
|
||||||
This SDK consists of three main packages:
|
This SDK consists of three main packages:
|
||||||
|
|
||||||
- **[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. [Documentation](src/ModelContextProtocol.Core/README.md)
|
- **[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.
|
||||||
|
|
||||||
- **[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. [Documentation](src/ModelContextProtocol/README.md)
|
- **[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.
|
||||||
|
|
||||||
- **[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`. [Documentation](src/ModelContextProtocol.AspNetCore/README.md)
|
- **[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`.
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
|
|
@ -26,7 +26,8 @@ The Model Context Protocol (MCP) is an open protocol that standardizes how appli
|
||||||
|
|
||||||
For more information about MCP:
|
For more information about MCP:
|
||||||
|
|
||||||
- [Official Documentation](https://modelcontextprotocol.io/)
|
- [Official MCP Documentation](https://modelcontextprotocol.io/)
|
||||||
|
- [MCP C# SDK Documentation](https://modelcontextprotocol.github.io/csharp-sdk/)
|
||||||
- [Protocol Specification](https://modelcontextprotocol.io/specification/)
|
- [Protocol Specification](https://modelcontextprotocol.io/specification/)
|
||||||
- [GitHub Organization](https://github.com/modelcontextprotocol)
|
- [GitHub Organization](https://github.com/modelcontextprotocol)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="README.md" pack="true" PackagePath="\" />
|
<None Include="..\PACKAGE.md" Pack="true" PackagePath="\README.md" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
# ASP.NET Core extensions for the MCP C# SDK
|
|
||||||
|
|
||||||
[](https://www.nuget.org/packages/ModelContextProtocol/absoluteLatest)
|
|
||||||
|
|
||||||
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 our [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.
|
|
||||||
|
|
||||||
## About MCP
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
For more information about MCP:
|
|
||||||
|
|
||||||
- [Official Documentation](https://modelcontextprotocol.io/)
|
|
||||||
- [Protocol Specification](https://modelcontextprotocol.io/specification/)
|
|
||||||
- [GitHub Organization](https://github.com/modelcontextprotocol)
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
To get started, install the package from NuGet
|
|
||||||
|
|
||||||
```
|
|
||||||
dotnet new web
|
|
||||||
dotnet add package ModelContextProtocol.AspNetCore --prerelease
|
|
||||||
```
|
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
// Program.cs
|
|
||||||
using ModelContextProtocol.Server;
|
|
||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
|
||||||
builder.Services.AddMcpServer()
|
|
||||||
.WithHttpTransport()
|
|
||||||
.WithToolsFromAssembly();
|
|
||||||
var app = builder.Build();
|
|
||||||
|
|
||||||
app.MapMcp();
|
|
||||||
|
|
||||||
app.Run("http://localhost:3001");
|
|
||||||
|
|
||||||
[McpServerToolType]
|
|
||||||
public static class EchoTool
|
|
||||||
{
|
|
||||||
[McpServerTool, Description("Echoes the message back to the client.")]
|
|
||||||
public static string Echo(string message) => $"hello {message}";
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
@ -73,7 +73,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="README.md" pack="true" PackagePath="\" />
|
<None Include="..\PACKAGE.md" Pack="true" PackagePath="\README.md" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -1,100 +0,0 @@
|
||||||
# MCP C# SDK Core
|
|
||||||
|
|
||||||
[](https://www.nuget.org/packages/ModelContextProtocol.Core/absoluteLatest)
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
> [!NOTE]
|
|
||||||
> This project is in preview; breaking changes can be introduced without prior notice.
|
|
||||||
|
|
||||||
## About MCP
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
For more information about MCP:
|
|
||||||
|
|
||||||
- [Official Documentation](https://modelcontextprotocol.io/)
|
|
||||||
- [Protocol Specification](https://modelcontextprotocol.io/specification/)
|
|
||||||
- [GitHub Organization](https://github.com/modelcontextprotocol)
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
To get started, install the core package from NuGet
|
|
||||||
|
|
||||||
```
|
|
||||||
dotnet add package ModelContextProtocol.Core --prerelease
|
|
||||||
```
|
|
||||||
|
|
||||||
## Getting Started (Client)
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
var clientTransport = new StdioClientTransport(new StdioClientTransportOptions
|
|
||||||
{
|
|
||||||
Name = "Everything",
|
|
||||||
Command = "npx",
|
|
||||||
Arguments = ["-y", "@modelcontextprotocol/server-everything"],
|
|
||||||
});
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\README.md" pack="true" PackagePath="\" />
|
<None Include="..\PACKAGE.md" Pack="true" PackagePath="\README.md" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
32
src/PACKAGE.md
Normal file
32
src/PACKAGE.md
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
# MCP C# SDK
|
||||||
|
|
||||||
|
[](https://www.nuget.org/packages/ModelContextProtocol)
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Packages
|
||||||
|
|
||||||
|
This SDK consists of three main packages:
|
||||||
|
|
||||||
|
- **[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.
|
||||||
|
|
||||||
|
- **[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.
|
||||||
|
|
||||||
|
- **[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`.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## About MCP
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
For more information about MCP:
|
||||||
|
|
||||||
|
- [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)
|
||||||
Loading…
Reference in a new issue