Skip to main content

On This Page

Interfacing 3D Printers with LLMs: Building a Secure MCP Server for the Flashforge AD5M

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

I Wrote an MCP Server for My 3D Printer

Developer Nic Lydon created a TypeScript MCP server to control his Flashforge Adventurer 5M 3D printer through Claude. The system successfully managed a print job lasting over 19 hours by bridging modern JSON APIs with legacy G-code protocols.

Why This Matters

Integrating physical hardware with LLMs requires strict semantic boundaries to prevent catastrophic failures, such as accidental extrusion cancellations or incorrect temperature settings. Technical reality often reveals that legacy protocols, like the AD5M’s TCP port 8899, maintain higher reliability during high-load printing cycles compared to modern HTTP/JSON interfaces which may time out.

Key Insights

  • Dual-Protocol Interface: The Flashforge AD5M exposes both a JSON HTTP API on port 8898 and a legacy length-prefixed TCP G-code port on 8899.
  • Security via Constraint: Stateful tools like kiln_control are strictly restricted to prevent LLMs from sending dangerous commands like M104 (set extruder temp) during status queries.
  • Local 3D Pipeline: The kiln_image2mesh tool uses rembg and TripoSG on a local iGPU to convert images to printable STLs without relying on cloud services.
  • API Reliability Disparity: During long print jobs, the printer’s modern HTTP server timed out (8000ms), while the legacy TCP port remained responsive for telemetry.
  • Semantic Definition: Implementing MCP forces the developer to resolve disagreements between APIs regarding units, retry behavior, and state definitions.

Working Examples

Example output from the kiln_progress tool showing active print status and layer telemetry.

{
"status": "printing",
"file": "looki_l1_tests.gcode",
"layer": 257,
"target_layer": 315,
"progress": 0.9112598299980164,
"print_duration_s": 69192
}

Real-time temperature telemetry for the nozzle and heat bed returned by the kiln_temps tool.

{
"nozzle": { "temp": 219.67, "target": 220 },
"bed": { "temp": 59.53, "target": 60 },
"chamber": { "temp": 0, "target": 0 }
}

Practical Applications

  • Use Case: Automated telemetry monitoring via kiln_temps allows real-time nozzle and bed temperature tracking to ensure print stability.
  • Pitfall: Over-reliance on modern JSON APIs; the AD5M’s HTTP server can become unresponsive during complex jobs, causing tool timeouts.
  • Use Case: Zero-cloud 3D modeling using the Modly service and TripoSG to generate printable meshes from 2D images entirely on local hardware.
  • Pitfall: Unfiltered tool access; granting LLMs raw M-code access can lead to unintended state changes like accidental extruder temperature adjustments.

References:

Continue reading

Next article

Building a Multi-Target Compiler Backend Without LLVM

Related Content