Nexttag.Ai.Mcp 1.0.0

dotnet add package Nexttag.Ai.Mcp --version 1.0.0
                    
NuGet\Install-Package Nexttag.Ai.Mcp -Version 1.0.0
                    
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="Nexttag.Ai.Mcp" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nexttag.Ai.Mcp" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Nexttag.Ai.Mcp" />
                    
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 Nexttag.Ai.Mcp --version 1.0.0
                    
#r "nuget: Nexttag.Ai.Mcp, 1.0.0"
                    
#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.
#:package Nexttag.Ai.Mcp@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nexttag.Ai.Mcp&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Nexttag.Ai.Mcp&version=1.0.0
                    
Install as a Cake Tool

Nexttag.Ai.Mcp

Conecta a servidores MCP (stdio ou HTTP) e expõe as tools deles como AITool prontos para o Nexttag.Ai.Agents.

Instalar

dotnet add package Nexttag.Ai.Mcp

Requer .NET 10. Depende de: ModelContextProtocol 1.4.0.

Registrar (Program.cs)

McpToolset é criado de forma assíncrona — use como singleton de sessão ou await using por execução:

// Program.cs — singleton de longa vida (conexões mantidas)
builder.Services.AddSingleton(sp =>
    McpToolset.ConnectAsync(
        sp.GetRequiredService<IEnumerable<McpServerConfig>>(),
        onError: (cfg, ex) => sp.GetRequiredService<ILogger<Program>>()
            .LogWarning(ex, "MCP {Servidor} indisponivel", cfg.Name))
    .GetAwaiter().GetResult());

Configurar

{
  "Mcp": {
    "Servers": [
      {
        "Name": "github",
        "Transport": "Http",
        "Url": "https://mcp.exemplo.com/github",
        "Headers": { "Authorization": "Bearer ghp_..." }
      },
      {
        "Name": "filesystem",
        "Transport": "Stdio",
        "Command": "npx",
        "Args": ["-y", "@modelcontextprotocol/server-filesystem", "/dados"]
      }
    ]
  }
}

Sem configuração obrigatória de variáveis de ambiente — as credenciais entram por Headers (HTTP) ou Env (stdio).

Usar

using Nexttag.Ai.Mcp;
using Nexttag.Ai.Agents;

// Conecta nos servidores e agrega as tools
await using var mcp = await McpToolset.ConnectAsync(
[
    new McpServerConfig
    {
        Name      = "github",
        Transport = McpTransport.Http,
        Url       = "https://mcp.exemplo.com/github",
        Headers   = new Dictionary<string, string> { ["Authorization"] = "Bearer ghp_..." }
    },
    new McpServerConfig
    {
        Name      = "filesystem",
        Transport = McpTransport.Stdio,
        Command   = "npx",
        Args      = ["-y", "@modelcontextprotocol/server-filesystem", "/dados"],
        Env       = new Dictionary<string, string> { ["HOME"] = "/tmp" }
    },
],
onError: (cfg, ex) => logger.LogWarning(ex, "MCP {Servidor} falhou", cfg.Name));

// Soma as tools MCP com as tools do host e executa o agente
IReadOnlyList<AITool> tools = [.. minhasTools, .. mcp.Tools];

var runner  = new AgentRunner(chatClient);
var context = new AgentRunContext();
AgentRunResult r = await runner.RunAsync(systemPrompt, task, tools, context);

Receitas

Combinar MCP com AgentToolset:

await using var mcp = await McpToolset.ConnectAsync(configs);

var tools = new AgentToolset(http, context)
    .ComWebFetch()
    .ComCalculadora()
    .Mais(mcp.Tools)
    .Build();

await using por requisição (sessão curta):

// Em vez de singleton — útil quando as tools mudam por tenant/usuário
await using var mcp = await McpToolset.ConnectAsync(ConfigsDoTenant(tenantId),
    onError: (cfg, ex) => logger.LogWarning(ex, "MCP {s} indisponivel", cfg.Name));

await runner.RunStreamingAsync(systemPrompt, task, mcp.Tools, context);

Servidor stdio com variáveis de ambiente:

new McpServerConfig
{
    Name      = "meu-servidor",
    Transport = McpTransport.Stdio,
    Command   = "dotnet",
    Args      = ["run", "--project", "/srv/meu-mcp"],
    Env       = new Dictionary<string, string>
    {
        ["DATABASE_URL"] = connectionString,
        ["API_KEY"]      = apiKey,
    }
}

Notas

  • Use await using — McpToolset implementa IAsyncDisposable e fecha todas as conexões ao sair do escopo.
  • Servidor que falha na conexão é ignorado (chama onError); os outros continuam funcionando.
  • Transporte Http usa streamable HTTP (SSE); Stdio lança o processo filho e fala via stdin/stdout.
  • Para McpTransport.Stdio: Command é obrigatório. Para McpTransport.Http: Url é obrigatório.
  • O número de tools disponíveis depende do que cada servidor MCP declara — use mcp.Tools.Count para inspecionar.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.0 204 6/17/2026