Skip to content

ModelContextProtocol

Rasmus Wulff Jensen edited this page May 20, 2026 · 1 revision

Model Context Protocol

The AgentFrameworkToolkit.Tools.ModelContextProtocol package adds helpers for consuming MCP servers as AITool instances.

Package

dotnet add package AgentFrameworkToolkit.Tools.ModelContextProtocol

Remote MCP servers

AIToolsFactory aiToolsFactory = new();

await using McpClientTools remoteMcpClient =
    await aiToolsFactory.GetToolsFromRemoteMcpAsync("https://mcp.example.com");

IList<AITool> remoteMcpTools = remoteMcpClient.Tools;

Local MCP servers

AIToolsFactory aiToolsFactory = new();

await using McpClientTools localMcpClient =
    await aiToolsFactory.GetToolsFromLocalMcpAsync("npx", ["@playwright/mcp@latest"]);

IList<AITool> localMcpTools = localMcpClient.Tools;

Usage

The returned tools can be used with Agent Framework Toolkit agents or regular Microsoft Agent Framework AIAgent instances.

OpenAIAgent agent = agentFactory.CreateAgent(new AgentOptions
{
    Model = "gpt-5",
    Tools = remoteMcpTools
});

Warning

Keep the McpClientTools instance alive while the tools are in use and dispose it with await using when finished.

Notes

Clone this wiki locally