{"id":19244366,"url":"https://github.com/nanoframework/nanoframework.webserver","last_synced_at":"2026-05-06T03:03:42.889Z","repository":{"id":37978518,"uuid":"304084607","full_name":"nanoframework/nanoFramework.WebServer","owner":"nanoframework","description":":package: Web server for nanoFramework packed with features: REST api using attributes, multithread requests, parameters in query URL, static files serving.","archived":false,"fork":false,"pushed_at":"2024-10-23T00:41:26.000Z","size":671,"stargazers_count":34,"open_issues_count":1,"forks_count":19,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-10-29T21:06:16.652Z","etag":null,"topics":["csharp","dotnet","esp32","nanoframework","nxp","rest","rest-api","restful-api","restful-webservices","stm32","webserver"],"latest_commit_sha":null,"homepage":"https://www.nanoframework.net","language":"C#","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nanoframework.png","metadata":{"funding":{"open_collective":"nanoframework","github":"nanoframework"},"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-14T17:14:44.000Z","updated_at":"2024-10-26T13:29:04.000Z","dependencies_parsed_at":"2023-10-11T19:37:31.539Z","dependency_job_id":"b37b21f4-b026-4809-b383-6e4b52cf08cd","html_url":"https://github.com/nanoframework/nanoFramework.WebServer","commit_stats":{"total_commits":445,"total_committers":12,"mean_commits":"37.083333333333336","dds":0.3932584269662921,"last_synced_commit":"30ff89806eef7e5617e0e812b9f71a2343575775"},"previous_names":[],"tags_count":188,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoframework%2FnanoFramework.WebServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoframework%2FnanoFramework.WebServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoframework%2FnanoFramework.WebServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoframework%2FnanoFramework.WebServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nanoframework","download_url":"https://codeload.github.com/nanoframework/nanoFramework.WebServer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247242680,"owners_count":20907134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","esp32","nanoframework","nxp","rest","rest-api","restful-api","restful-webservices","stm32","webserver"],"created_at":"2024-11-09T17:23:05.786Z","updated_at":"2026-05-06T03:03:42.862Z","avatar_url":"https://github.com/nanoframework.png","language":"C#","funding_links":["https://opencollective.com/nanoframework","https://github.com/sponsors/nanoframework"],"categories":[],"sub_categories":[],"readme":"﻿[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nanoframework_lib-nanoframework.WebServer\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=nanoframework_lib-nanoframework.WebServer) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=nanoframework_lib-nanoframework.WebServer\u0026metric=reliability_rating)](https://sonarcloud.io/dashboard?id=nanoframework_lib-nanoframework.WebServer) [![NuGet](https://img.shields.io/nuget/dt/nanoFramework.WebServer.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.WebServer/) [![#yourfirstpr](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](https://github.com/nanoframework/Home/blob/main/CONTRIBUTING.md) [![Discord](https://img.shields.io/discord/478725473862549535.svg?logo=discord\u0026logoColor=white\u0026label=Discord\u0026color=7289DA)](https://discord.gg/gCyBu8T)\n\n![nanoFramework logo](https://raw.githubusercontent.com/nanoframework/Home/main/resources/logo/nanoFramework-repo-logo.png)\n\n-----\n\n# .NET nanoFramework WebServer with Model Context Protocol (MCP)\n\n## Build status\n\n| Component | Build Status | NuGet Package |\n|:-|---|---|\n| nanoFramework.WebServer | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.WebServer/_apis/build/status/nanoFramework.WebServer?repoName=nanoframework%2FnanoFramework.WebServer\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.WebServer/_build/latest?definitionId=65\u0026repoName=nanoframework%2FnanoFramework.WebServer\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.WebServer.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.WebServer/) |\n| nanoFramework.WebServer.FileSystem | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.WebServer/_apis/build/status/nanoFramework.WebServer?repoName=nanoframework%2FnanoFramework.WebServer\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.WebServer/_build/latest?definitionId=65\u0026repoName=nanoframework%2FnanoFramework.WebServer\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.WebServer.FileSystem.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.WebServer.FileSystem/) |\n| nanoFramework.WebServer.Mcp | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.WebServer/_apis/build/status/nanoFramework.WebServer?repoName=nanoframework%2FnanoFramework.WebServer\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.WebServer/_build/latest?definitionId=65\u0026repoName=nanoframework%2FnanoFramework.WebServer\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.WebServer.Mcp.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.WebServer.Mcp/) |\n\n## Overview\n\nThis library provides a lightweight, multi-threaded HTTP/HTTPS WebServer for .NET nanoFramework with comprehensive **Model Context Protocol (MCP)** support for AI agent integration.\n\n### Key Features\n\n- **Multi-threaded request handling**\n- **Static file serving** with FileSystem support\n- **RESTful API support** with parameter handling\n- **Route-based controllers** with attribute decoration\n- **Authentication support** (Basic, API Key)\n- **HTTPS/SSL support** with certificates\n- **Model Context Protocol (MCP)** for AI agent integration\n- **Automatic tool discovery** and JSON-RPC 2.0 compliance\n\n## Quick Start\n\n### Basic Event Based WebServer\n\nUsing the Web Server is very straight forward and supports event based calls.\n\n```csharp\n// You need to be connected to a Wi-Fi or ethernet connection with a proper IP Address\n// Optionally you can pass a parameter with the IP address for the server to bind to\n\nusing (WebServer server = new WebServer(80, HttpProtocol.Http))\n{\n    server.CommandReceived += ServerCommandReceived;\n    server.Start();\n    Thread.Sleep(Timeout.Infinite);\n}\n\nprivate static void ServerCommandReceived(object source, WebServerEventArgs e)\n{\n    if (e.Context.Request.RawUrl.ToLower() == \"/hello\")\n    {\n        WebServer.OutputAsStream(e.Context.Response, \"Hello from nanoFramework!\");\n    }\n    else\n    {\n        WebServer.OutputHttpCode(e.Context.Response, HttpStatusCode.NotFound);\n    }\n}\n```\n\n### Controller-Based WebServer\n\nControllers are supported including with parametarized routes like 'api/led/{id}/dosomething/{order}'.\n\n```csharp\nusing (WebServer server = new WebServer(80, HttpProtocol.Http, new Type[] { typeof(MyController) }))\n{\n    server.Start();\n    Thread.Sleep(Timeout.Infinite);\n}\n\npublic class MyController\n{\n    [Route(\"api/hello\")]\n    [Method(\"GET\")]\n    public void Hello(WebServerEventArgs e)\n    {\n        WebServer.OutputAsStream(e.Context.Response, \"Hello from Controller!\");\n    }\n\n    [Route(\"api/led/{id}\")]\n    [Method(\"GET\")]\n    public void LedState(WebServerEventArgs e)\n    {\n        string ledId = e.GetRouteParameter(\"id\");\n        WebServer.OutputAsStream(e.Context.Response, $\"You selected Led {ledId}!\");\n    }\n}\n```\n\n## Model Context Protocol (MCP) Support\n\nEnable AI agents to interact with your embedded devices through standardized tools and JSON-RPC 2.0 protocol.\n\n### Defining MCP Tools\n\n```csharp\npublic class IoTTools\n{\n    [McpServerTool(\"read_sensor\", \"Reads temperature from sensor\")]\n    public static string ReadTemperature()\n    {\n        // Your sensor reading code\n        return \"23.5°C\";\n    }\n\n    [McpServerTool(\"control_led\", \"Controls device LED\", \"Output the status of the LED\")]\n    public static string ControlLed(LedCommand command)\n    {\n        // Your LED control code\n        return $\"LED set to {command.State}\";\n    }\n}\n\npublic class LedCommand\n{\n    public string State\n    {\n        [Description(\"LED state: on, off, or blink\")]\n        get;\n        set;\n    }\n}\n```\n\n### Defining MCP Prompts\n\nYou 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.\n\nHere's a simple example:\n\n```csharp\nusing nanoFramework.WebServer.Mcp;\n\npublic class McpPrompts\n{\n    [McpServerPrompt(\"echo_sanity_check\", \"Echo test prompt\")]\n    public static PromptMessage[] EchoSanityCheck()\n    {\n        return new PromptMessage[]\n        {\n            new PromptMessage(\"Call Echo with the string 'Hello MCP world!' and return the response.\")\n        };\n    }\n}\n```\n\nPrompts 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.\n\n### Setting Up MCP Server\n\n```csharp\npublic static void Main()\n{\n    // Connect to WiFi first\n    var connected = WifiNetworkHelper.ConnectDhcp(Ssid, Password, requiresDateTime: true);\n    \n    // Discover and register MCP tools\n    McpToolRegistry.DiscoverTools(new Type[] { typeof(IoTTools) });\n\n    // Discover and register MCP prompts\n    McpPromptRegistry.DiscoverPrompts(new Type[] { typeof(McpPrompts) });\n    \n    // Start WebServer with MCP support\n    using (var server = new WebServer(80, HttpProtocol.Http, new Type[] { typeof(McpServerController) }))\n    {\n        // Optional customization\n        McpServerController.ServerName = \"MyIoTDevice\";\n        McpServerController.Instructions = \"IoT device with sensor and LED control capabilities.\";\n        \n        server.Start();\n        Thread.Sleep(Timeout.Infinite);\n    }\n}\n```\n\n### AI Agent Integration\n\nOnce running, AI agents can discover and invoke your tools:\n\n```json\n// Tool discovery\nPOST /mcp\n{\n    \"jsonrpc\": \"2.0\",\n    \"method\": \"tools/list\",\n    \"id\": 1\n}\n\n// Tool invocation\nPOST /mcp\n{\n    \"jsonrpc\": \"2.0\",\n    \"method\": \"tools/call\",\n    \"params\": {\n        \"name\": \"control_led\",\n        \"arguments\": {\"State\": \"on\"}\n    },\n    \"id\": 2\n}\n```\n\n## Documentation\n\n| Topic | Description |\n|-------|-------------|\n| [Controllers and Routing](./doc/controllers-routing.md) | Learn about route attributes, method decorations, and URL parameters |\n| [Authentication](./doc/authentication.md) | Configure Basic Auth, API Key, and custom authentication |\n| [HTTPS and Certificates](./doc/https-certificates.md) | Set up SSL/TLS encryption with certificates |\n| [File System Support](./doc/file-system.md) | Serve static files from storage devices |\n| [Model Context Protocol (MCP)](./doc/model-context-protocol.md) | Complete MCP guide for AI agent integration |\n| [REST API Development](./doc/rest-api.md) | Build RESTful APIs with request/response handling |\n| [Event-Driven Programming](./doc/event-driven.md) | Handle requests through events and status monitoring |\n| [Examples and Samples](./doc/examples.md) | Working examples and code samples |\n\n## Limitations\n\n- No compression support in request/response streams\n- MCP implementation supports server features only (no notifications or SSE)\n- No or single parameter limitation for MCP tools (use complex objects for multiple parameters)\n- Prompt parameters, when declared, are always mandatory.\n\n## Installation\n\nInstall 'nanoFramework.WebServer' for the Web Server without File System support. Install 'nanoFramework.WebServer.FileSystem' for file serving, so with devices supporting File System.\nInstall '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.\n\n## Contributing\n\nFor documentation, feedback, issues and contributions, please refer to the [Home repo](https://github.com/nanoframework/Home).\n\nJoin our Discord community [here](https://discord.gg/gCyBu8T).\n\n## Credits\n\nThe list of contributors to this project can be found at [CONTRIBUTORS](https://github.com/nanoframework/Home/blob/main/CONTRIBUTORS.md).\n\n## License\n\nLicensed under the [MIT license](LICENSE.md).\n\n## Code of Conduct\n\nThis project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behaviour in our community.\nFor more information see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).\n\n## .NET Foundation\n\nThis project is supported by the [.NET Foundation](https://dotnetfoundation.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoframework%2Fnanoframework.webserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanoframework%2Fnanoframework.webserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoframework%2Fnanoframework.webserver/lists"}