MCP-DT: LLM-Driven Algorithm Synthesis for Cyber-Physical Systems Through Digital Twin Safety Enforcement
Abstract
Designing control algorithms for cyber-physical systems (CPS) requires balancing performance objectives against hard safety constraints. This design process currently relies on expert manual tuning or evolutionary optimization methods that treat the problem as a black-box search, requiring a very high number of evaluations with no insight into why candidates fail. Large Language Models (LLMs) can generate and reason about algorithmic code, but they may lack awareness of physical safety boundaries, especially during runtime. We present MCP-DT (Model Context Protocol-Digital Twin), a domain-agnostic framework in which an LLM iteratively synthesizes control algorithms by conversing with a physicsbased Digital Twin through the Model Context Protocol. During a candidate algorithm runs, if a constraint violation occurs, the Digital Twin returns enriched feedback, identifying which constraint was violated, at what system state, and what the safe operating boundary is, enabling the LLM to make targeted, reasoning-driven corrections. The engineer specifies only a goal, declarative safety constraints, and an algorithm interface. The paper validates MCP-DT on a battery fast-charging case study, demonstrating convergence into a feasible working solution.