element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Blog Connecting AI to the Physical World with MCP and a Pi Pico W
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: shabaz
  • Date Created: 22 Sep 2026 5:39 AM Date Created
  • Views 62 views
  • Likes 5 likes
  • Comments 3 comments
  • Model Context Protocol
  • rpiintermediate
  • mcp
  • Gemini
  • antigravity
  • raspberry_pi_projects
  • pi pico
Related
Recommended

Connecting AI to the Physical World with MCP and a Pi Pico W

shabaz
shabaz
22 Sep 2026

Table of Contents

  • Introduction
  • MCP Explained
  • Working with MCP
  • Using a Simple MCP Server Library
  • Building and Running the Code
  • Connecting the Agent
  • Summary

Introduction

AI agents can be extremely useful, but it would often be helpful if they could directly interact with the physical world. For instance, one might develop a control system, and then get the AI to fine-tune it automatically, by adjusting outputs and taking measurements. You could connect an oscilloscope to the AI, and let it take measurements, modify controls, and inspect the ‘scope screenshots.

There’s a fairly crude but useful thing called Master Control Program Model Context Protocol (MCP) which many AI agents can work with, if the user provides functionality in a server that listens and responds to MCP. There are ready-made MCP servers for a load of useful scenarios. I decided to implement one in a microcontroller (Pi Pico W).

MCP Explained

MCP is ridiculously simple in theory. The AI agent (which acts as the client) can be configured with the server details (such as IP address), and then on startup, the agent will send a server/discover message to learn what categories of things the server supports. The server responds back with “capabilities” which are essentially “tools” and “resources”.

Next, the client asks for a list of tools and the server provides that in a response. An example tool could be as simple as a relay.

The client then asks for a list of resources - a sensor could be a resource.

Later, when the agent wishes to activate a tool (a relay in this example) the agent (client) will send a “tools/call” message with the required relay state, and the server responds accordingly. If the agent was curious to know the resource value (such as temperature) then it will send a “resources/read” message for the server to respond to.

That’s it pretty much. The secret to why this works as well as it can, is that the responses to the tools and resources list requests contain verbose descriptions about what the tools and resources are about. It gives the agent useful information it can stick in its context, and include that when making decisions.

There are a few more MCP messages not mentioned here (there's a ping-pong diagram of real network traffic later), but the important ones are covered.

As far as the MCP server creator is concerned, they need to be creative in describing their sensors and actuators in a description field which will get populated in the list responses, and then attach their GPIO or whatever to their server callbacks for when the appropriate messages come across from the AI. That is it, and let’s believe everything is perfectly fine; none of this is crude and half-baked.

I’m sure there are some business opportunities in this area; surely someone must be working on some sort of gateway, to enforce some rules so that real-world equipment isn’t destroyed when the machines take over. In the meantime, that’s all on the MCP server implementor.

Working with MCP

The best way to work with MCP is to find an MCP library for the programming language you’re comfortable with, and then the majority of the hard work is done for you, it’s just a matter of integration. In my case, I wanted to use a small microcontroller with WiFi capability, and there isn’t a suitable library for that.

With some experimentation, it was found that plain HTTP can work. The MCP client (agent) sends a HTTP POST request to the MCP server (microcontroller), and the server returns a response containing JSON content, and closes the connection. The agent simply opens another connection for the next request. This is very convenient on a small embedded system because the server doesn't need to maintain a persistent connection. I have only tested this implementation with Antigravity, so other MCP clients may behave differently.I am sure someone will eventually come up with a more robust MCP server library for microcontrollers, but for now at least something works.

Using a Simple MCP Server Library

I placed code in a pico_w_mcp repository, which can be easily used with a Pi Pico W, which has 2.4 GHz WiFi built-in. The code is in just one source file mcp_server.cpp, and it has a header file of course.

Here’s how to use the server in custom projects.

First, create an object of class MCPServer (the name you pass it here might need to be the name you later register with the agent too):

MCPServer mcp(“pico_w_mcp”);

Then, define some callbacks for all the tools and resources (i.e. actuators and sensors). A tool callback (setMotorPWM in this example below) receives arguments supplied by the agent and performs an action. A resource callback such as readHumidity simply supplies the requested data:

static bool setMotorPWM(MCPArgs &args, char *out, size_t out_size, void *) {
float pwm = args.getFloat("pwm");
set_motor_pwm(pwm); 
snprintf(out, out_size, "Motor PWM set to %.1f%%", pwm); 
return true; 
}

static bool readHumidity(char *out, size_t out_size, void *) { 
	// assume value is in float humidity
snprintf(out, out_size, "%.1f percent", humidity); 
return true;
}

Then, register all the tool callbacks:

MCPServer::MCPTool motor = mcp.tool(
"set_motor_pwm", "Set the motor PWM duty cycle from 0.0 to 100.0 percent.", setMotorPWM);

motor.param<float>( "pwm", "PWM duty cycle in percent, from 0.0 to 100.0." );

And register all the resource callbacks:

mcp.resource("sensor://humidity", "humidity", "Current relative humidity in percent.", readHumidity );

Then, start up the MCP server!

mcp.begin(8000);

Building and Running the Code

The repository has a complete demo project, and to use it, the Pi Pico C/C++ SDK needs to be installed. Follow the build instructions in the SDK documentation. In my case, I use a PowerShell script (it is in the GitHub repo) although if anyone wants to use that, it will need to be edited since it has hard-coded paths to suit my set-up.

For the demo project, the WLAN SSID and password either need to be typed into the main.cpp code, or provided as parameters during the build process. It’s just a demo, you wouldn’t do this for a real project of course.

Once the code is built, the firmware is transferred to the Pi Pico W in the usual way (hold down the BOOTSEL button on the Pi Pico W and insert the USB cable, then release the button, then drag the firmware file onto the drive letter that appears on the PC, and then the firmware will upload and immediately begin running).

A serial port will appear on the PC, which can provide debug information if required. You can check your network tools to see what IP address the Pi Pico W got assigned from the router.

Connecting the Agent

Consult the documentation for the system you’re using. With Antigravity CLI, all that needs to be done is to type the following in a Linux shell or Windows PowerShell (change the IP address to match the Pi Pico, and notice that the pico_w_mcp name that was used in the source code is used; I’m not sure if that is essential, but it’s what I did):

agy mcp add --type http pico_w_mcp http://192.168.1.159:8000/mcp

Next, run Antigravity, and try typing in something that needs interaction with the MCP server.

image

If you’re curious, run WireShark at the same time. The diagram here shows the interaction I saw on my PC (click to enlarge).

image

Here's what the serial console revealed from the Pi Pico point of view:

image

Summary

A simple HTTP server can provide enough MCP functionality to allow an embedded device to interact directly with an AI agent. A simple demo was illustrated using a Pi Pico and a cut-down minimal MCP server implementation mainly just to get the idea of how to use the protocol, and if you’re using a more powerful device, then it would certainly be better to use an established MCP server library.

I can’t guarantee the simple library described here will work for you, but if you ever give it a try I’d be interested to hear how it goes.

Thanks for reading.

image

  • Sign in to reply
  • shabaz
    shabaz 4 hours ago in reply to Fred27

    I was watching the recent Jensen Huang CBS interview the other day, the interviewer pressed him several times regarding AI dangers but he was comfortably reassuring.

    It reminded me we are now at the Emma Thompson scene in I Am Legend; the point that was reached when she modestly agrees she has cured cancer : )

    You don't have permission to edit metadata of this video.
    Edit media
    x
    image
    Upload Preview
    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • BigG
    BigG 12 hours ago

    Wow! Awesome work. This is a great use case.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Fred27
    Fred27 12 hours ago

    "Connecting AI to the Physical World"

    Don't do it! It won't end well. Haven't you seen Terminator?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube