48 CZ-PRG (GMT+1)
US-NYC (GMT-5)
Blazor Web App (Server rendered)
AI AGENTS · EXTENSIBILITY

Tools & Plugins

Tools let an LLM ask your application to retrieve information or perform a narrowly defined operation. This guide covers .NET function calling, plugins, external APIs, and MCP—and ends with a live tool-using assistant backed by configured .NET model clients.

AT A GLANCE

What a tool adds to an LLM application

  • Fresh information from approved APIs
  • Typed, application-owned .NET functions
  • Reusable plugins and MCP integrations
  • Explicit policy around every operation
HOW TOOL CALLING WORKS

The model proposes; your application decides

Function calling is a structured request/response protocol—not code execution inside the model. The model receives a description and input schema for each available function. It may return a request to call one. Your application maps that request to an allowlisted function, validates its arguments, checks the caller's permissions, executes it, and sends the result back so the model can produce a user-facing response.

  1. Describe: expose only approved function names, descriptions, and typed arguments.
  2. Decide: let the model request a tool call, or disable tools for that request.
  3. Validate: validate input shape, bounds, caller identity, and authorization in .NET.
  4. Execute: call a narrow local method or fixed external API with a timeout.
  5. Respond: return a bounded result to the model and show sources or actions to the user.
.NET AND NUGET

Packages and integration choices

Package / API Role Choose it for
Microsoft.Extensions.AI Shared IChatClient, AIFunction, AIFunctionFactory, tool-call content types, and function-invocation middleware. Provider-independent function calling and .NET application services.
Microsoft.Extensions.AI.OpenAI + OpenAI OpenAI .NET client adapter for IChatClient; provider APIs can expose different hosted and function tools. OpenAI chat clients and supported OpenAI-compatible endpoints.
Azure.AI.OpenAI Azure OpenAI SDK; adapt a chat client to the common interface and supply Azure credentials or identity. Applications using an Azure resource and model deployment.
Anthropic / Google.GenAI Official provider SDKs with .NET chat client adapters. Tool schemas and supported features remain provider/model specific. Claude or Gemini models; check the selected API/model's function-calling support.
Microsoft.SemanticKernel Kernel functions, plugins, prompt functions, and higher-level orchestration. Applications already built around Semantic Kernel or needing its plugin and orchestration model.
Microsoft.Agents.AI Agent Framework abstractions for tool-using agents, sessions, middleware, and workflows. When the application needs a managed agent loop or workflow beyond one chat request.
ModelContextProtocol C# client and server SDK for Model Context Protocol (MCP), an interoperability layer for tools and context. Connecting to a reviewed MCP server or exposing application-owned tools to MCP clients.
IHttpClientFactory Built-in .NET service for named/typed HTTP clients, connection management, and configured endpoints. Calling external REST APIs from a server-side tool. Pin the host in trusted application configuration.

This application already references Microsoft.Extensions.AI 10.11.0, Microsoft.Extensions.AI.OpenAI 10.11.0, OpenAI 2.14.0, Azure.AI.OpenAI 2.1.0, Anthropic 13.3.0, and Google.GenAI 1.28.0. Semantic Kernel, Agent Framework, and MCP are separate optional integrations. Add only the framework you need and check package/provider compatibility before relying on a particular tool feature.

CUSTOM .NET FUNCTIONS

Expose small, typed functions with AIFunctionFactory

AIFunctionFactory can turn an application method into a tool declaration. Descriptions help the model choose a function and construct arguments; they do not validate business rules or grant access. Add UseFunctionInvocation() to a chat pipeline when the selected provider adapter supports automatic function calling.

using Microsoft.Extensions.AI;
using System.ComponentModel;

[Description("Calculates a basic decimal operation.")]
static decimal Calculate(
    [Description("add, subtract, multiply, or divide")] string operation,
    decimal left,
    decimal right)
{
    return operation.ToLowerInvariant() switch
    {
        "add" => left + right,
        "subtract" => left - right,
        "multiply" => left * right,
        "divide" when right != 0 => left / right,
        "divide" => throw new DivideByZeroException(),
        _ => throw new ArgumentException("Unsupported operation.")
    };
}

IChatClient toolClient = chatClient.AsBuilder()
    .UseFunctionInvocation(configure: client =>
    {
        client.MaximumIterationsPerRequest = 5;
        client.MaximumConsecutiveErrorsPerRequest = 2;
    })
    .Build();

var options = new ChatOptions
{
    MaxOutputTokens = 1200,
    Tools = [AIFunctionFactory.Create(Calculate)]
};

ChatResponse response = await toolClient.GetResponseAsync(
    "What is 19.95 multiplied by 12?",
    options,
    cancellationToken);

The function-invocation middleware can make multiple model requests in one operation. Set an iteration cap, token limit, and cancellation timeout. For functions with side effects, do not use automatic invocation until the operation has an explicit approval and authorization design.

PLUGINS AND PROTOCOLS

Tools, plugins, skills, and MCP are related—not interchangeable

Concept What it means .NET example
Tool / function A callable operation with a name, description, and structured input. The application executes it. AIFunctionFactory.Create with IChatClient.
Plugin A named collection of related functions. A framework-specific organization and discovery mechanism. Semantic Kernel plugins group [KernelFunction] methods; do not assume all frameworks use the same plugin contract.
Skill Reusable instructions or a procedure that may describe a workflow and the tools it is allowed to use. Application-owned prompt/instruction resources with an allowlisted loader.
MCP A protocol for clients to discover and call tools exposed by a separate server, with additional resources and prompts. ModelContextProtocol client/server SDK; review and authorize each connected server and tool.
MCP standardizes transport and discovery, not trust. An MCP server can access data or perform actions with its own permissions. Pin the server identity and transport, authenticate it, restrict exposed tools, and authorize each operation as if it were an external service integration.
DESIGN AND SECURITY

Design tools for least privilege

Prefer read-only and narrow

Use a specific operation such as GetOrderStatus(orderId) rather than a generic database or HTTP tool. Restrict resource access to the signed-in user and return only fields the assistant needs.

Treat input and output as untrusted

Validate arguments in .NET, enforce authorization outside the model, sanitize output before rendering, and treat retrieved pages or files as untrusted data that may contain prompt injection.

Constrain external requests

Use named HttpClient instances with fixed HTTPS hosts, timeouts, response-size limits, and rate limits. Never let a model choose an arbitrary URL or forward provider credentials to a tool.

Observe and evaluate

Record which tool ran, validated inputs, duration, and outcome without logging secrets or unnecessary personal data. Test malicious, invalid, and boundary inputs as well as successful calls.

See the .NET LLM guide for deeper coverage of provider adapters, function invocation, approvals, MCP, and agent workflows, or the chat assistant guide for multi-turn chat design.

HANDS-ON · SERVER-SIDE .NET

Try .NET tools with an LLM

Choose a configured provider and ask it to use bounded .NET functions for Wikipedia article search, current weather, arithmetic, and UTC time.

Where the API key goes

Keys remain in this browser's saved AI Agent settings. When you send a message, the selected provider's key is transferred over this Interactive Server circuit to the server, where its .NET SDK makes the HTTPS request. The key is not written to server storage or returned with the answer. Use this demo only with a server you trust; production applications should authenticate users and use a server-side secret manager.

Available read-only tools

The model can choose to call these functions. Wikipedia receives a search query; Open-Meteo receives a city name. No provider credentials are sent to either service. Search results and weather values are external data, not trusted instructions. Do not include private or confidential information in a prompt that could be sent to a public API. OpenAI tool requests send the configured reasoning effort; some models require it to be set to None when using function tools with Chat Completions.

Wikipedia search Open-Meteo weather Decimal calculator UTC time
Loading AI Agent settings…
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.