Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

541 Commits

Repository files navigation

Quality Gate StatusReliability RatingNuGet#yourfirstprDiscord

nanoFramework logo


.NET nanoFramework WebServer with Model Context Protocol (MCP) and Skills Discovery

Build status

ComponentBuild StatusNuGet Package
nanoFramework.WebServerBuild StatusNuGet
nanoFramework.WebServer.FileSystemBuild StatusNuGet
nanoFramework.WebServer.McpBuild StatusNuGet
nanoFramework.WebServer.SkillsBuild StatusNuGet

Overview

This library provides a lightweight, multi-threaded HTTP/HTTPS WebServer for .NET nanoFramework with comprehensive Model Context Protocol (MCP) support and AI Agent Skills Discovery (A2A-compatible) 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
  • AI Agent Skills Discovery with A2A-compatible Agent Card
  • 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 tousing(WebServerserver=newWebServer(80,HttpProtocol.Http)){server.CommandReceived+=ServerCommandReceived;server.Start();Thread.Sleep(Timeout.Infinite);}privatestaticvoidServerCommandReceived(objectsource,WebServerEventArgse){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(WebServerserver=newWebServer(80,HttpProtocol.Http,newType[]{typeof(MyController)})){server.Start();Thread.Sleep(Timeout.Infinite);}publicclassMyController{[Route("api/hello")][Method("GET")]publicvoidHello(WebServerEventArgse){WebServer.OutputAsStream(e.Context.Response,"Hello from Controller!");}[Route("api/led/{id}")][Method("GET")]publicvoidLedState(WebServerEventArgse){stringledId=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

publicclassIoTTools{[McpServerTool("read_sensor","Reads temperature from sensor")]publicstaticstringReadTemperature(){// Your sensor reading codereturn"23.5°C";}[McpServerTool("control_led","Controls device LED","Output the status of the LED")]publicstaticstringControlLed(LedCommandcommand){// Your LED control codereturn$"LED set to {command.State}";}}publicclassLedCommand{publicstringState{[Description("LED state: on, off, or blink")]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:

usingnanoFramework.WebServer.Mcp;publicclassMcpPrompts{[McpServerPrompt("echo_sanity_check","Echo test prompt")]publicstaticPromptMessage[]EchoSanityCheck(){returnnewPromptMessage[]{newPromptMessage("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

publicstaticvoidMain(){// Connect to WiFi firstvarconnected=WifiNetworkHelper.ConnectDhcp(Ssid,Password,requiresDateTime:true);// Discover and register MCP toolsMcpToolRegistry.DiscoverTools(newType[]{typeof(IoTTools)});// Discover and register MCP promptsMcpPromptRegistry.DiscoverPrompts(newType[]{typeof(McpPrompts)});// Start WebServer with MCP supportusing(varserver=newWebServer(80,HttpProtocol.Http,newType[]{typeof(McpServerController)})){// Optional customizationMcpServerController.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 discoveryPOST /mcp
{
"jsonrpc": "2.0",
"method": "tools/list",
"id": 1
}
// Tool invocationPOST /mcp
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "control_led",
"arguments": {"State": "on"}
},
"id": 2
}

AI Agent Skills Discovery

Expose device capabilities as discoverable skills for AI agents using the A2A (Agent2Agent) protocol conventions.

Defining Skills

usingnanoFramework.WebServer.Skills;[Skill("climate","Climate Control","HVAC management for building zones")][SkillTag("temperature")][SkillTag("hvac")][SkillExample("What is the current temperature?")]publicclassClimateSkill{[SkillAction("GetTemperature","Reads current room temperature")]publicstaticdoubleGetTemperature(){return22.5;}[SkillAction("SetTarget","Sets the target temperature")]publicstaticboolSetTarget(TargetInputinput){returntrue;}}publicclassTargetInput{publicdoubleTemperature{[Description("Target temperature in Celsius")]get;set;}}

Setting Up Skills Server

publicstaticvoidMain(){// Connect to WiFi firstvarconnected=WifiNetworkHelper.ConnectDhcp(Ssid,Password,requiresDateTime:true);// Discover and register skillsSkillRegistry.DiscoverSkills(newType[]{typeof(ClimateSkill)});// Start WebServer with Skills Discovery supportusing(varserver=newWebServer(80,HttpProtocol.Http,newType[]{typeof(SkillDiscoveryController)})){// Optional customizationSkillDiscoveryController.AgentName="SmartThermostat";SkillDiscoveryController.AgentDescription="Embedded HVAC controller with sensor capabilities";server.Start();Thread.Sleep(Timeout.Infinite);}}

AI Agent Integration

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

GET /.well-known/agent-card.json
{
"name": "SmartThermostat",
"description": "Embedded HVAC controller with sensor capabilities",
"version": "1.0.0",
"skills": [
{
"id": "climate",
"name": "Climate Control",
"tags": ["temperature", "hvac"],
"actions": [
{ "name": "GetTemperature", "description": "Reads current room temperature" },
{ "name": "SetTarget", "description": "Sets the target temperature" }
]
}
]
}
POST /skills/invokeContent-Type: application/json
{ "skill": "climate", "action": "GetTemperature", "arguments": {} }

Documentation

TopicDescription
Controllers and RoutingLearn about route attributes, method decorations, and URL parameters
AuthenticationConfigure Basic Auth, API Key, and custom authentication
HTTPS and CertificatesSet up SSL/TLS encryption with certificates
File System SupportServe static files from storage devices
Model Context Protocol (MCP)Complete MCP guide for AI agent integration
AI Agent Skills DiscoveryA2A-compatible skills discovery and invocation
REST API DevelopmentBuild RESTful APIs with request/response handling
Event-Driven ProgrammingHandle requests through events and status monitoring
Examples and SamplesWorking 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 and Skills actions (use complex objects for multiple parameters)
  • Prompt parameters, when declared, are always mandatory.
  • Skills Discovery implements A2A discovery and invocation only (no task lifecycle)

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. Install 'nanoFramework.WebServer.Skills' for A2A-compatible AI Agent Skills Discovery. Like MCP, it includes the core 'nanoFramework.WebServer' and can be used alongside MCP.

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.

About

📦 Web server for .NET nanoFramework packed with features: REST api using attributes, multithread requests, parameters in query URL, static files serving.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

38 stars

Watchers

3 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages