nanoFramework.WebServer.FileSystem 1.2.124

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package nanoFramework.WebServer.FileSystem --version 1.2.124
                    
NuGet\Install-Package nanoFramework.WebServer.FileSystem -Version 1.2.124
                    
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.FileSystem" Version="1.2.124" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.WebServer.FileSystem" Version="1.2.124" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.WebServer.FileSystem" />
                    
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.FileSystem --version 1.2.124
                    
#r "nuget: nanoFramework.WebServer.FileSystem, 1.2.124"
                    
#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.
#addin nuget:?package=nanoFramework.WebServer.FileSystem&version=1.2.124
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.WebServer.FileSystem&version=1.2.124
                    
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 wifi or ethernet connection with a proper IP Address

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.OutPutStream(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.OutPutStream(e.Context.Response, "Hello from Controller!");
    }

    [Route("api/led/{id}")]
    [Method("GET")]
    public void LedState(WebServerEventArgs e)
    {
        string ledId = e.GetRouteParameter("id");
        WebServer.OutPutStream(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; }
}

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) });
    
    // 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)

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 (1)

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

Repository Stars
nanoframework/Samples
🍬 Code samples from the nanoFramework team used in testing, proof of concepts and other explorational endeavours
Version Downloads Last Updated
1.2.125 90 7/7/2025
1.2.124 83 7/7/2025
1.2.123 110 6/27/2025
1.2.122 175 6/2/2025
1.2.121 216 4/25/2025
1.2.118 217 4/2/2025
1.2.117 179 4/2/2025
1.2.116 281 3/26/2025
1.2.115 490 3/26/2025
1.2.114 494 3/26/2025
1.2.112 197 3/12/2025
1.2.111 186 3/10/2025
1.2.110 187 3/10/2025
1.2.109 194 3/10/2025
1.2.108 194 3/10/2025
1.2.107 236 3/7/2025
1.2.106 134 3/3/2025
1.2.105 164 2/27/2025
1.2.104 121 2/27/2025
1.2.101 122 2/25/2025
1.2.97 124 2/25/2025
1.2.95 121 2/25/2025
1.2.93 203 2/5/2025
1.2.92 124 2/5/2025
1.2.89 131 2/4/2025
1.2.88 125 2/4/2025
1.2.87 129 1/31/2025
1.2.86 133 1/30/2025
1.2.85 119 1/30/2025
1.2.84 118 1/30/2025
1.2.83 106 1/30/2025
1.2.77 126 1/29/2025
1.2.74 172 1/10/2025
1.2.73 141 1/6/2025
1.2.72 143 1/2/2025
1.2.70 213 12/11/2024
1.2.69 123 12/11/2024
1.2.63 331 10/8/2024
1.2.60 176 9/26/2024
1.2.56 159 7/30/2024
1.2.55 160 7/24/2024
1.2.52 191 6/3/2024
1.2.48 156 5/17/2024
1.2.45 150 5/13/2024
1.2.43 231 5/10/2024
1.2.40 222 4/12/2024
1.2.38 160 4/9/2024
1.2.36 155 4/8/2024
1.2.34 168 4/5/2024
1.2.32 160 4/3/2024
1.2.30 160 4/3/2024
1.2.27 240 2/14/2024
1.2.25 157 2/12/2024
1.2.23 177 1/26/2024
1.2.21 136 1/26/2024
1.2.19 143 1/26/2024
1.2.17 168 1/24/2024
1.2.14 352 11/17/2023
1.2.12 155 11/10/2023
1.2.9 147 11/9/2023
1.2.7 142 11/8/2023
1.2.6 154 11/8/2023
1.2.3 230 10/27/2023