McpDotNet.Extensions.AI 1.0.1.3

dotnet add package McpDotNet.Extensions.AI --version 1.0.1.3                
NuGet\Install-Package McpDotNet.Extensions.AI -Version 1.0.1.3                
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.0.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add McpDotNet.Extensions.AI --version 1.0.1.3                
#r "nuget: McpDotNet.Extensions.AI, 1.0.1.3"                
#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.
// Install McpDotNet.Extensions.AI as a Cake Addin
#addin nuget:?package=McpDotNet.Extensions.AI&version=1.0.1.3

// Install McpDotNet.Extensions.AI as a Cake Tool
#tool nuget:?package=McpDotNet.Extensions.AI&version=1.0.1.3                

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 = "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 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. 
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.0.1.3 87 2/27/2025
1.0.1.2 81 2/23/2025
1.0.1.1 58 2/23/2025