Connect Agents toAny External Service.
Full Model Context Protocol client implementation with a comprehensive library of built-in tools across 8 categories. Define custom tools with ITool or [LMFunction], connect to MCP servers for external capabilities, and compose tool chains with JSON Schema validation and parallel execution.
Model Context Protocol
Built-in Tool Categories
Two Ways to Extend Your Agents
Use the Model Context Protocol to connect agents to any external service, or define your own local tools with a simple C# interface. Both approaches integrate seamlessly into the agent runtime with JSON Schema validation and parallel execution.
MCP Protocol
Full Model Context Protocol client implementation. Connect to any MCP server over Stdio transport and discover tools, resources, and prompts at runtime with human-in-the-loop approval.
Local Tools
Define tools with the ITool interface or annotate static methods with [LMFunction]. Tools get automatic JSON Schema generation, typed result handling, parallel execution, and policy-based invocation controls.
public class WeatherTool : ITool { public string Name => "get_weather"; public string Description => "Returns the current weather for a given city."; public JsonSchema InputSchema => new JsonSchemaBuilder() .Property("city", new JsonSchemaBuilder().Type(SchemaValueType.String)) .Required("city") .Build(); public async Task<ToolResult> InvokeAsync(ToolInput input, CancellationToken ct) { var city = input.GetArgument<string>("city"); var data = await FetchWeather(city, ct); return ToolResult.FromJson(data); } }
public static class MathTools { [LMFunction("Calculates the sum of two numbers.")] public static double Add(double a, double b) { return a + b; } [LMFunction("Converts a temperature from Celsius to Fahrenheit.")] public static double CelsiusToFahrenheit(double celsius) { return celsius * 9.0 / 5.0 + 32; } } // Register with the agent var agent = Agent.CreateBuilder(model) .WithTools(tools => tools.Register<MathTools>()) .Build();
// Connect to an MCP server over Stdio transport var mcpClient = new McpClient("npx", "-y @modelcontextprotocol/server-filesystem"); await mcpClient.InitializeAsync(); // Discover available tools from the MCP server var tools = await mcpClient.ListToolsAsync(); foreach (var tool in tools) Console.WriteLine($"Tool: {tool.Name} - {tool.Description}"); // Register MCP tools with the agent var agent = Agent.CreateBuilder(model) .WithTools(tools => tools.ImportFromMcp(mcpClient)) .Build(); // The agent can now use tools from the MCP server var response = await agent.RunAsync("List the files in the /docs directory.");
6 Web Search Providers Built In
Equip agents with web search out of the box. Choose from free providers like DuckDuckGo or connect premium APIs for higher quality results. All providers share the same interface and can be swapped with a single line of code.
DuckDuckGo No Key
Free HTML scraping. Default provider, works out of the box with no configuration required.
Brave API Key
High-quality search results with a generous free tier available for development and small workloads.
Tavily API Key
AI-optimized search engine designed specifically for RAG pipelines and agentic workflows.
Serper API Key
Google search results delivered via a fast API with structured JSON responses.
SearXNG No Key
Self-hosted meta-search engine. Full privacy control, aggregates results from multiple sources.
Custom Optional
Bring your own search endpoint. Implement a custom provider with the shared interface.
// Default provider: DuckDuckGo, no API key required var webSearch = BuiltInTools.WebSearch; // Premium providers with API keys var braveSearch = BuiltInTools.CreateWebSearch(WebSearchTool.Provider.Brave, "your-api-key"); var tavilySearch = BuiltInTools.CreateWebSearch(WebSearchTool.Provider.Tavily, "your-api-key"); // Register with the agent var agent = Agent.CreateBuilder(model) .WithTools(tools => tools.Register(braveSearch)) .Build();
Ready-to-Run Demo Projects
Explore working examples that demonstrate MCP integration, custom tool creation, and built-in tool usage in real-world scenarios.
MCP Integration
Connect to MCP servers using HTTP/SSE transport for tool discovery and invocation in an interactive chat loop.
MCPMCP Stdio Integration
Use Stdio transport to connect to local MCP servers running as child processes with full protocol support.
ToolsTool Calling Assistant
Build a custom tool-calling agent that implements ITool for weather, calculations, and data lookup.
Built-in ToolsDocument Processing Agent
Use built-in PdfSplit, Ocr, and document tools to process PDFs and images in an automated pipeline.
ToolsMulti-Turn Chat with Tools
Interactive multi-turn conversation where the agent calls tools automatically based on user queries.
MCPMulti-Turn Chat with MCP
Multi-turn chat session that dynamically discovers and invokes tools from connected MCP servers.
Step-by-Step Implementation Guides
Follow detailed walkthroughs to implement MCP connections, custom tools, function calling, and web search in your .NET applications.
Key API Classes
Core classes for MCP integration, tool registration, and agent orchestration. Each links directly to the full API documentation.
McpClient
MCP protocol client for server connections
ToolRegistry
Central registry for tool management
BuiltInTools
Factory for production-ready built-in tools
WebSearchTool
Multi-provider web search integration
Agent
Core agent runtime and execution engine
AgentBuilder
Fluent builder for agent configuration
Key Concepts
Learn about the foundational concepts behind MCP, tool calling, agent execution, and AI safety guardrails.
Connect Your Agents to Anything
Build agents that interact with any external service through MCP, call custom tools, and leverage a comprehensive library of built-in capabilities. All running locally on your infrastructure.
Need expert guidance? Talk to our team