nanoFramework.WebServer 1.2.134

Prefix Reserved
dotnet add package nanoFramework.WebServer --version 1.2.134
                    
NuGet\Install-Package nanoFramework.WebServer -Version 1.2.134
                    
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="nanoFramework.WebServer" Version="1.2.134" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.WebServer" Version="1.2.134" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.WebServer" />
                    
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 nanoFramework.WebServer --version 1.2.134
                    
#r "nuget: nanoFramework.WebServer, 1.2.134"
                    
#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 nanoFramework.WebServer@1.2.134
                    
#: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=nanoFramework.WebServer&version=1.2.134
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.WebServer&version=1.2.134
                    
Install as a Cake Tool

Quality Gate Status Reliability Rating NuGet #yourfirstpr Discord

nanoFramework logo


.NET nanoFramework WebServer with Model Context Protocol (MCP)

Build status

Component Build Status NuGet Package
nanoFramework.WebServer Build Status NuGet
nanoFramework.WebServer.FileSystem Build Status NuGet
nanoFramework.WebServer.Mcp Build Status NuGet

Overview

This library provides a lightweight, multi-threaded HTTP/HTTPS WebServer for .NET nanoFramework with comprehensive Model Context Protocol (MCP) support for AI agent integration.

Key Features

  • Multi-threaded request handling
  • Static file serving with FileSystem support
  • RESTful API support with parameter handling
  • Route-based controllers with attribute decoration
  • Authentication support (Basic, API Key)
  • HTTPS/SSL support with certificates
  • Model Context Protocol (MCP) for AI agent integration
  • Automatic tool discovery and JSON-RPC 2.0 compliance

Quick Start

Basic Event Based WebServer

Using the Web Server is very straight forward and supports event based calls.

// You need to be connected to a Wi-Fi or ethernet connection with a proper IP Address
// Optionally you can pass a parameter with the IP address for the server to bind to

using (WebServer server = new WebServer(80, HttpProtocol.Http))
{
    server.CommandReceived += ServerCommandReceived;
    server.Start();
    Thread.Sleep(Timeout.Infinite);
}

private static void ServerCommandReceived(object source, WebServerEventArgs e)
{
    if (e.Context.Request.RawUrl.ToLower() == "/hello")
    {
        WebServer.OutputAsStream(e.Context.Response, "Hello from nanoFramework!");
    }
    else
    {
        WebServer.OutputHttpCode(e.Context.Response, HttpStatusCode.NotFound);
    }
}

Controller-Based WebServer

Controllers are supported including with parametarized routes like 'api/led/{id}/dosomething/{order}'.

using (WebServer server = new WebServer(80, HttpProtocol.Http, new Type[] { typeof(MyController) }))
{
    server.Start();
    Thread.Sleep(Timeout.Infinite);
}

public class MyController
{
    [Route("api/hello")]
    [Method("GET")]
    public void Hello(WebServerEventArgs e)
    {
        WebServer.OutputAsStream(e.Context.Response, "Hello from Controller!");
    }

    [Route("api/led/{id}")]
    [Method("GET")]
    public void LedState(WebServerEventArgs e)
    {
        string ledId = e.GetRouteParameter("id");
        WebServer.OutputAsStream(e.Context.Response, $"You selected Led {ledId}!");
    }
}

Model Context Protocol (MCP) Support

Enable AI agents to interact with your embedded devices through standardized tools and JSON-RPC 2.0 protocol.

Defining MCP Tools

public class IoTTools
{
    [McpServerTool("read_sensor", "Reads temperature from sensor")]
    public static string ReadTemperature()
    {
        // Your sensor reading code
        return "23.5°C";
    }

    [McpServerTool("control_led", "Controls device LED", "Uutput the statusof the LED")]
    public static string ControlLed(LedCommand command)
    {
        // Your LED control code
        return $"LED set to {command.State}";
    }
}

public class LedCommand
{
    [Description("LED state: on, off, or blink")]
    public string State { get; set; }
}

Defining MCP Prompts

You can define reusable, high-level prompts for AI agents using the McpServerPrompt attribute. Prompts encapsulate multi-step instructions or workflows that can be invoked by agents.

Here's a simple example:

using nanoFramework.WebServer.Mcp;

public class McpPrompts
{
    [McpServerPrompt("echo_sanity_check", "Echo test prompt")]
    public static PromptMessage[] EchoSanityCheck()
    {
        return new PromptMessage[]
        {
            new PromptMessage("Call Echo with the string 'Hello MCP world!' and return the response.")
        };
    }
}

Prompts can be discovered and invoked by AI agents in the same way as tools. You can also define prompts with parameters using the McpPromptParameter attribute.

Setting Up MCP Server

public static void Main()
{
    // Connect to WiFi first
    var connected = WifiNetworkHelper.ConnectDhcp(Ssid, Password, requiresDateTime: true);
    
    // Discover and register MCP tools
    McpToolRegistry.DiscoverTools(new Type[] { typeof(IoTTools) });

    // Discover and register MCP prompts
    McpPromptRegistry.DiscoverPrompts(new Type[] { typeof(McpPrompts) });
    
    // Start WebServer with MCP support
    using (var server = new WebServer(80, HttpProtocol.Http, new Type[] { typeof(McpServerController) }))
    {
        // Optional customization
        McpServerController.ServerName = "MyIoTDevice";
        McpServerController.Instructions = "IoT device with sensor and LED control capabilities.";
        
        server.Start();
        Thread.Sleep(Timeout.Infinite);
    }
}

AI Agent Integration

Once running, AI agents can discover and invoke your tools:

// Tool discovery
POST /mcp
{
    "jsonrpc": "2.0",
    "method": "tools/list",
    "id": 1
}

// Tool invocation
POST /mcp
{
    "jsonrpc": "2.0",
    "method": "tools/call",
    "params": {
        "name": "control_led",
        "arguments": {"State": "on"}
    },
    "id": 2
}

Documentation

Topic Description
Controllers and Routing Learn about route attributes, method decorations, and URL parameters
Authentication Configure Basic Auth, API Key, and custom authentication
HTTPS and Certificates Set up SSL/TLS encryption with certificates
File System Support Serve static files from storage devices
Model Context Protocol (MCP) Complete MCP guide for AI agent integration
REST API Development Build RESTful APIs with request/response handling
Event-Driven Programming Handle requests through events and status monitoring
Examples and Samples Working examples and code samples

Limitations

  • No compression support in request/response streams
  • MCP implementation supports server features only (no notifications or SSE)
  • No or single parameter limitation for MCP tools (use complex objects for multiple parameters)
  • Prompt parameters, when declared, are always mandatory.

Installation

Install 'nanoFramework.WebServer' for the Web Server without File System support. Install 'nanoFramework.WebServer.FileSystem' for file serving, so with devices supporting File System. Install 'nanoFramework.WebServer.Mcp' for MCP support. It does contains the full 'nanoFramework.WebServer' but does not include native file serving. You can add this feature fairly easilly by reusing the code function serving it.

Contributing

For documentation, feedback, issues and contributions, please refer to the Home repo.

Join our Discord community here.

Credits

The list of contributors to this project can be found at CONTRIBUTORS.

License

Licensed under the MIT license.

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behaviour in our community. For more information see the .NET Foundation Code of Conduct.

.NET Foundation

This project is supported by the .NET Foundation.

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
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 (2)

Showing the top 2 popular GitHub repositories that depend on nanoFramework.WebServer:

Repository Stars
nanoframework/Samples
🍬 Code samples from the nanoFramework team used in testing, proof of concepts and other explorational endeavours
nanoframework/nanoFramework.IoT.Device
📦 This repo includes .NET nanoFramework implementations for various sensors, chips, displays, hats and drivers
Version Downloads Last Updated
1.2.134 468 11/21/2025
1.2.133 314 11/13/2025
1.2.131 258 10/17/2025
1.2.130 179 10/15/2025
1.2.126 402 8/12/2025
1.2.125 284 7/7/2025
1.2.124 176 7/7/2025
1.2.123 185 6/27/2025
1.2.122 295 6/2/2025
1.2.121 342 4/25/2025
1.2.118 357 4/2/2025
1.2.117 214 4/2/2025
1.2.116 554 3/26/2025
1.2.115 539 3/26/2025
1.2.114 547 3/26/2025
1.2.112 261 3/12/2025
1.2.111 282 3/10/2025
1.2.110 219 3/10/2025
1.2.109 242 3/10/2025
1.2.108 252 3/10/2025
1.2.107 287 3/7/2025
1.2.106 221 3/3/2025
1.2.105 312 2/27/2025
1.2.104 184 2/27/2025
1.2.101 207 2/25/2025
1.2.97 189 2/25/2025
1.2.95 180 2/25/2025
1.2.93 349 2/5/2025
1.2.92 177 2/5/2025
1.2.89 207 2/4/2025
1.2.88 210 2/4/2025
1.2.87 194 1/31/2025
1.2.86 185 1/30/2025
1.2.85 182 1/30/2025
1.2.84 177 1/30/2025
1.2.83 147 1/30/2025
1.2.77 186 1/29/2025
1.2.74 298 1/10/2025
1.2.73 206 1/6/2025
1.2.72 203 1/2/2025
1.2.70 333 12/11/2024
1.2.69 158 12/11/2024
1.2.63 588 10/8/2024
1.2.60 254 9/26/2024
1.2.56 305 7/30/2024
1.2.55 249 7/24/2024
1.2.52 355 6/3/2024
1.2.48 262 5/17/2024
1.2.45 169 5/13/2024
1.2.43 260 5/10/2024
1.2.40 309 4/12/2024
1.2.38 203 4/9/2024
1.2.36 195 4/8/2024
1.2.34 218 4/5/2024
1.2.32 192 4/3/2024
1.2.30 194 4/3/2024
1.2.27 412 2/14/2024
1.2.25 186 2/12/2024
1.2.23 304 1/26/2024
1.2.21 197 1/26/2024
1.2.19 184 1/26/2024
1.2.17 226 1/24/2024
1.2.14 537 11/17/2023
1.2.12 241 11/10/2023
1.2.9 198 11/9/2023
1.2.7 238 11/8/2023
1.2.6 176 11/8/2023
1.2.3 337 10/27/2023
1.2.1 263 10/25/2023
1.1.79 274 10/10/2023
1.1.77 258 10/4/2023
1.1.75 510 8/8/2023
1.1.73 367 7/27/2023
1.1.71 233 7/27/2023
1.1.65 795 2/17/2023
1.1.63 529 1/24/2023
1.1.61 393 1/24/2023
1.1.59 462 1/24/2023
1.1.56 547 12/30/2022
1.1.54 436 12/28/2022
1.1.51 466 12/27/2022
1.1.47 854 10/26/2022
1.1.44 523 10/25/2022
1.1.41 517 10/24/2022
1.1.39 561 10/23/2022
1.1.36 570 10/10/2022
1.1.32 545 10/8/2022
1.1.29 608 9/22/2022
1.1.27 575 9/22/2022
1.1.25 571 9/22/2022
1.1.23 619 9/16/2022
1.1.21 626 9/15/2022
1.1.19 639 8/29/2022
1.1.17 661 8/6/2022
1.1.14 569 8/4/2022
1.1.12 539 8/3/2022
1.1.10 572 8/3/2022
1.1.8 568 8/3/2022
1.1.6 744 6/13/2022
1.1.4 637 6/8/2022
1.1.2 561 6/8/2022
1.1.1 606 5/30/2022
1.0.0 838 3/30/2022
1.0.0-preview.260 258 3/29/2022
1.0.0-preview.258 236 3/28/2022
1.0.0-preview.256 269 3/28/2022
1.0.0-preview.254 273 3/28/2022
1.0.0-preview.252 273 3/28/2022
1.0.0-preview.250 243 3/28/2022
1.0.0-preview.248 263 3/17/2022
1.0.0-preview.246 278 3/14/2022
1.0.0-preview.244 250 3/14/2022
1.0.0-preview.242 269 3/14/2022
1.0.0-preview.240 260 3/14/2022
1.0.0-preview.238 248 3/8/2022
1.0.0-preview.236 255 3/8/2022
1.0.0-preview.234 238 3/4/2022
1.0.0-preview.232 266 3/3/2022
1.0.0-preview.230 259 3/2/2022
1.0.0-preview.228 249 2/28/2022
1.0.0-preview.226 285 2/24/2022
1.0.0-preview.222 277 2/17/2022
1.0.0-preview.220 256 2/17/2022
1.0.0-preview.218 312 2/6/2022
1.0.0-preview.216 276 2/4/2022
1.0.0-preview.214 268 2/4/2022
1.0.0-preview.212 297 1/28/2022
1.0.0-preview.210 274 1/28/2022
1.0.0-preview.208 307 1/28/2022
1.0.0-preview.206 258 1/25/2022
1.0.0-preview.204 273 1/21/2022
1.0.0-preview.202 251 1/21/2022
1.0.0-preview.200 260 1/21/2022
1.0.0-preview.198 257 1/21/2022
1.0.0-preview.196 278 1/21/2022
1.0.0-preview.194 279 1/13/2022
1.0.0-preview.192 307 1/12/2022
1.0.0-preview.190 292 1/12/2022
1.0.0-preview.188 261 1/11/2022
1.0.0-preview.186 294 1/11/2022
1.0.0-preview.183 277 1/6/2022
1.0.0-preview.181 294 1/5/2022
1.0.0-preview.180 288 1/3/2022
1.0.0-preview.179 289 1/3/2022
1.0.0-preview.178 268 1/3/2022
1.0.0-preview.177 285 12/30/2021
1.0.0-preview.176 310 12/28/2021
1.0.0-preview.174 334 12/3/2021
1.0.0-preview.172 299 12/3/2021
1.0.0-preview.170 269 12/3/2021
1.0.0-preview.168 310 12/3/2021
1.0.0-preview.166 299 12/3/2021
1.0.0-preview.164 295 12/2/2021
1.0.0-preview.162 316 12/2/2021
1.0.0-preview.160 270 12/2/2021
1.0.0-preview.158 267 12/2/2021
1.0.0-preview.156 294 12/2/2021
1.0.0-preview.154 290 12/2/2021
1.0.0-preview.152 308 12/1/2021
1.0.0-preview.150 265 12/1/2021
1.0.0-preview.148 277 12/1/2021
1.0.0-preview.145 320 11/11/2021
1.0.0-preview.143 335 10/22/2021
1.0.0-preview.141 302 10/18/2021
1.0.0-preview.138 322 10/18/2021
1.0.0-preview.136 450 7/17/2021
1.0.0-preview.134 312 7/16/2021
1.0.0-preview.132 286 7/16/2021
1.0.0-preview.130 318 7/15/2021
1.0.0-preview.128 301 7/14/2021
1.0.0-preview.126 417 6/19/2021
1.0.0-preview.124 383 6/19/2021
1.0.0-preview.122 316 6/17/2021
1.0.0-preview.119 288 6/7/2021
1.0.0-preview.117 302 6/7/2021
1.0.0-preview.115 315 6/7/2021
1.0.0-preview.113 324 6/7/2021
1.0.0-preview.111 334 6/6/2021
1.0.0-preview.109 1,056 6/5/2021
1.0.0-preview.107 317 6/3/2021
1.0.0-preview.105 310 6/2/2021
1.0.0-preview.103 314 6/2/2021
1.0.0-preview.101 321 6/1/2021
1.0.0-preview.99 313 6/1/2021
1.0.0-preview.96 313 6/1/2021
1.0.0-preview.94 344 5/31/2021
1.0.0-preview.92 323 5/30/2021
1.0.0-preview.90 322 5/27/2021
1.0.0-preview.88 320 5/26/2021
1.0.0-preview.86 406 5/23/2021
1.0.0-preview.84 318 5/22/2021
1.0.0-preview.82 376 5/21/2021
1.0.0-preview.80 322 5/19/2021
1.0.0-preview.78 289 5/19/2021
1.0.0-preview.76 309 5/19/2021
1.0.0-preview.71 326 5/15/2021
1.0.0-preview.69 293 5/14/2021
1.0.0-preview.66 298 5/13/2021
1.0.0-preview.64 307 5/11/2021
1.0.0-preview.62 319 5/11/2021
1.0.0-preview.59 366 5/6/2021
1.0.0-preview.57 317 5/5/2021
1.0.0-preview.51 306 4/12/2021
1.0.0-preview.49 320 4/12/2021
1.0.0-preview.47 345 4/10/2021
1.0.0-preview.44 334 4/6/2021
1.0.0-preview.41 313 4/5/2021
1.0.0-preview.32 340 3/21/2021
1.0.0-preview.30 359 3/20/2021
1.0.0-preview.28 338 3/19/2021
1.0.0-preview.26 353 3/18/2021
1.0.0-preview.24 305 3/17/2021
1.0.0-preview.22 304 3/17/2021
1.0.0-preview.20 357 3/5/2021
1.0.0-preview.18 329 3/2/2021
1.0.0-preview.15 579 1/19/2021
1.0.0-preview.13 316 1/19/2021
1.0.0-preview.11 402 1/7/2021
1.0.0-preview.10 361 12/22/2020
1.0.0-preview.6 433 12/1/2020
1.0.0-preview.3 425 11/6/2020