Skip to content

AIToolsFactory

Rasmus Wulff Jensen edited this page Feb 10, 2026 · 5 revisions

Note

AIToolsFactory is shared among all the providers (provider-independent) and can be used directly with AIAgent in Microsoft Agent Framework, should you not wish to use the AgentFactories.

Packages

  • Core: dotnet add package AgentFrameworkToolkit.Tools
  • MCP support: dotnet add package AgentFrameworkToolkit.Tools.ModelContextProtocol

Define your tools with the [AITool] attribute

In order to use the AIToolsFactory you need to add the [AITool] attribute to the methods you consider as Tools

public class MyTools
{
    [AITool("get_weather", "Get the current weather for a city")]
    public string GetWeather(string city)
    {
        //Real implementation goes here...
        return $"Weather for {city}";
    }

    [AITool] //Name/description are optional
    private static string Ping()
    {
        return "pong";
    }
}

AIToolsFactory scans for methods with the [AITool] attribute, including public/private and static/instance methods. Tool names default to the method name if not set.

Create tools from instances or types

Once the [AITool] attributes are in place, you can get your tools in the following way.

AIToolsFactory toolsFactory = new();

//From instance
IList<AITool> tools1 = toolsFactory.GetTools(new MyTools());

//From type (requires a parameterless constructor unless the type is abstract)
IList<AITool> tools2 = toolsFactory.GetTools(typeof(MyTools));

//From multiple types or instances
IList<AITool> tools3 = toolsFactory.GetTools(typeof(MyTools), typeof(OtherTools));
IList<AITool> tools4 = toolsFactory.GetTools(new MyTools(), new OtherTools());

Dependency Injection

You can Dependency Inject the AIToolsFactory if you wish instead of creating own instance.

builder.Services.AddAIToolFactory();

Common tools

Agent Framework Toolkit includes a set of provider-independent, ready-to-use tools for common scenarios (file system, HTTP, time, random number generation, weather, website content, and SMTP email).

See CommonTools.

Tools from Model Context Protocol (MCP)

To pull tools from MCP servers, reference the AgentFrameworkToolkit.Tools.ModelContextProtocol package and use the extension methods in AgentFrameworkToolkit.Tools.ModelContextProtocol.

AIToolsFactory toolsFactory = new();

// Remote MCP server
await using McpClientTools remoteTools = await toolsFactory.GetToolsFromRemoteMcpAsync(
    "https://mcp.example.com");
IList<AITool> mcpTools = remoteTools.Tools;

// Local MCP server
await using McpClientTools localTools = await toolsFactory.GetToolsFromLocalMcpAsync(
    "npx",
    ["@playwright/mcp@latest"]);
IList<AITool> localMcpTools = localTools.Tools;

Warning

McpClientTools should be kept while the tools are in use and disposed (await using) to shut down the underlying MCP client when not needed anymore.

Tools from AgentSkills (https://agentskills.io/)

Get tools from AgentSkills (see dedicated ReadMe on AgentSkillsDotNet for more information)

AIToolsFactory toolsFactory = new AIToolsFactory();
AgentSkills agentSkills = toolsFactory.GetToolsFromAgentSkills("<FolderToAgentSkills>");
IList<AITool> tools = agentSkills.GetAsTools();

Clone this wiki locally