Skip to content

Digital Twin and MCP: standards for AI in Smart Cities

April 2, 2025 | 12:10 PM

Developing Digital Twins for cities requires the integration and synchronization of many technologies, services and large volumes of real-time data (for example, traffic sensors, weather information, or energy control systems). This is where MCP (Model Context Protocol) comes into play, acting as a unified framework for connecting external data and services with language models. By standardizing how applications communicate information to LLMs, MCP enables the seamless orchestration of all data sources and tools required for the digital twin to reflect the city’s current state, facilitate predictive simulations, and enable AI-driven decision-making. As a result, urban management is optimized and innovation is propelled in the smart city ecosystem.

Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect your devices to various peripherals and accessories, MCP provides a standardized way to connect AI models to different data sources and tools.

Table of contents

Open Table of contents

General architecture

To enable more complex and varied use cases within a Digital Twins environment, it is essential to have a decoupled architecture that allows adding new services or functionalities without altering the main structure. An MCP (Model Context Protocol)-based component precisely serves this purpose, offering a standardized connection point among various data sources, tools, and services.

Overall, this MCP-based approach helps build a flexible and modular Digital Twins ecosystem that can quickly adapt to new challenges and opportunities in the smart city space. Each component, like a “Lego brick,” can be added or replaced without compromising overall functionality, enabling the design of robust and scalable workflows.

cognitive-functions

MCP Building Blocks

Decoupled architecture principle

Data Flow in the Digital Twin

Imagine you have a language model (LLM) that can converse and reason about text, but on its own, it cannot perform certain specialized tasks (for example, getting the latest real-time traffic data or controlling smart street lighting). You need a way for the LLM to “ask for help” from external tools.

The Model Context Protocol (MCP) is, in simple terms, a way for the LLM and external tools to communicate through an intermediate server.

  1. Tools as “Services”: the tools (such as a traffic data service, a weather API, or a streetlight controller) are published or exposed on an MCP server. Each tool is described and registered with a name or a way to invoke it.

  2. The LLM generates requests: when the LLM realizes during a conversation or reasoning process that it needs assistance from a tool (for example to get current traffic flow on a particular road), it constructs a structured message (often in JSON format) indicating which tool to use and with what parameters.

  3. MCP Server receives the request: LLM “speaks” to the MCP server by sending this structured message. The MCP server reads the request and decides which specific tool should handle it.

  4. Tool executes the task: MCP server calls the appropriate tool, providing it with the necessary data (for example, the location or the specific city zone) so it can perform its task.

  5. MCP server returns the response to the LLM: once the tool finishes its job (for example returning the real-time congestion data), it sends the response back to the MCP server, which then relays the information to the LLM.

  6. LLM integrates the result: LLM upon receiving the tool’s response, combines it with its own reasoning and continues the conversation or decision-making process, now enriched by the external data.

MongoDB MCP Server example

MongoDB Lens is a local Model Context Protocol (MCP) server with full featured access to MongoDB databases using natural language via LLMs to perform queries, run aggregations, optimize performance, and more.

MongoDB Lens MCP can be integrated with an LLM in a city environment to centralize and query data from multiple sources (traffic sensors, weather, public services, etc.) in a unified manner. By posing natural language questions, the LLM instructs MongoDB Lens MCP to perform queries, run aggregations on the database, optimize performance, and return clear, actionable answers. This approach helps urban administrators make faster, more accurate decisions based on real-time information, ultimately enhancing efficiency and quality of life throughout the city.

Example tools invocation

Tools in MCP allow servers to expose executable functions that can be invoked by clients and used by LLMs to perform actions. Tools are called from LLM using endpoints, where servers perform the requested operation and return results.