McpDotNet.Extensions.AI 1.1.0.1

dotnet add package McpDotNet.Extensions.AI --version 1.1.0.1
                    
NuGet\Install-Package McpDotNet.Extensions.AI -Version 1.1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="McpDotNet.Extensions.AI" Version="1.1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="McpDotNet.Extensions.AI" Version="1.1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="McpDotNet.Extensions.AI" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add McpDotNet.Extensions.AI --version 1.1.0.1
                    
#r "nuget: McpDotNet.Extensions.AI, 1.1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=McpDotNet.Extensions.AI&version=1.1.0.1
                    
Install McpDotNet.Extensions.AI as a Cake Addin
#tool nuget:?package=McpDotNet.Extensions.AI&version=1.1.0.1
                    
Install McpDotNet.Extensions.AI as a Cake Tool

McpDotNet.Extensions.AI

NuGet version

Microsoft.Extensions.AI integration for the Model Context Protocol (MCP). Enables seamless use of MCP tools as AI functions in any IChatClient implementation. Built on top of mcpdotnet.

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:

Design Goals

The goal of this library is to provide a simple and efficient way to integrate MCP capabilities with Microsoft.Extensions.AI.Abstractions. It is designed to be easy to use, wrapping boilerplate code and providing a clean API for AI developers to use leverage MCP capabilities without having to worry about the underlying protocol.

Features

  • Easy lifecycle management of MCP connections
  • Seamless mapping of MCP tools to Microsoft.Extensions.AI.Abstractions AIFunction objects
  • Use convenience methods, while still having access to the full MCP protocol through the underlying mcpdotnet library
  • Compatible with .NET 8.0 and later

Getting Started (Client)

To use McpDotNet.Extensions.AI, first install it via NuGet:

dotnet add package McpDotNet.Extensions.AI

Create a configuration object for the MCP server you want to connect to:

var config = new McpServerConfig
{
    Id = "everything",
    Name = "Everything",
    TransportType = TransportTypes.StdIo,
    TransportOptions = new Dictionary<string, string>
    {
        ["command"] = "npx",
        ["arguments"] = "-y @modelcontextprotocol/server-everything",
    }
};

Then create an MCP session scope and use it with a chat client of your choice:

await using var sessionScope = await McpSessionScope.CreateAsync(config);

IChatClient openaiClient = new OpenAIClient("sk-your-key")
    .AsChatClient("gpt-4o-mini");

IChatClient chatClient = new ChatClientBuilder(openaiClient)
    .UseFunctionInvocation()
    .Build();

// Create message list
IList<ChatMessage> messages =
[
    // Add a system message
    new(ChatRole.System, "You are a helpful assistant."),
    new(ChatRole.User, "Placeholder for the actual user message.")
];

// Call the chat client
var response = await chatClient.GetResponseAsync(messages,
        new() { Tools = sessionScope.Tools });

As you can see, all you really need to do is create one or more configuration objects matching the MCP servers you want to use, create an MCP session scope, and then the tools exposed by the server(s) will be available to you through the Tools property of the McpSessionScope object.

The McpSessionScope object implements IAsyncDisposable, and managing the connection lifecycle is as simple as using the await using pattern. Note that you have to keep the McpSessionScope object alive for as long as you want to use the tools it provides.

Roadmap

  • Convenience methods for other capabilities: prompts, sampling, resources, etc.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0.1 341 24 days ago
1.0.1.3 235 a month ago
1.0.1.2 85 a month ago
1.0.1.1 65 a month ago