MCP Server Hello World

Browse source code on GitHub

Overview

The sample defines two tools: an LED-control tool, which allows MCP clients to turn on, turn off or toggle an on-board LED, and a delayed response tool, which triggers a delayed response mechanism to show users how the server behaves in such scenarios.

Once the server connects to a network and receives an IP address, it becomes available either under the assigned IP or through the mDNS address, like http://mcp-hello-world.local:8080/mcp.

Requirements

  • A board with networking support

  • A board with an LED connected to the led0 alias (optional, for LED control)

Wiring

No special wiring requirements.

Building and Running

Build and flash the sample as follows:

west build -b <board_name> samples/net/mcp/mcp_server_hello_world
west flash

Replace <board_name> with your target board.

Testing

Once the server is running, it listens for MCP client connections over HTTP. You can connect using any MCP-compatible client and invoke the registered tools. The sample is configured to use DHCP and mDNS by default, so the MCP server is accessible under the URL http://mcp-hello-world.local:8080/mcp.

Sample Output

Initializing...
LED initialized successfully
Registering Tool #1: Delayed response tool...
Tool #1 registered.
Registering Tool #2: LED Control...
Tool #2 registered.
Starting...
MCP Server running...

When tools are invoked, you will see output similar to:

Delayed response tool executed with arguments: {"message":"test"}, token: <uuid>
LED control tool executed with arguments: {"action":"on"}, token: <uuid>

References

See also

MCP Server API