Skip to main content

A Model Context Protocol (MCP) server for BACnet.

Project description

BACnet MCP Server

test codecov PyPI - Version

A lightweight Model Context Protocol (MCP) server that connects LLM agents to BACnet devices in a secure, standardized way, enabling seamless integration of AI-driven workflows with Building Automation (BAS), Building Management (BMS) and Industrial Control (ICS) systems, allowing agents to monitor real-time sensor data, actuate devices, and orchestrate complex automation tasks.

Getting Started

Use uv to add and manage the BACnet MCP server as a dependency in your project, or install it directly via uv pip install or pip install. See the Installation section of the documentation for full installation instructions and more details.

uv add bacnet-mcp

The server can be embedded in and run directly from your application. By default, it exposes a Streamable HTTP endpoint at http://127.0.0.1:8000/mcp/.

# app.py
from bacnet_mcp import BACnetMCP

mcp = BACnetMCP()

if __name__ == "__main__":
    mcp.run(transport="http")

It can also be launched from the command line using the provided CLI without modifying the source code.

bacnet-mcp

Or in an ephemeral, isolated environment using uvx. Check out the Using tools guide for more details.

uvx bacnet-mcp

Configuration

For the use cases where most operations target a specific device, such as a Programmable Logic Controller (PLC) or BACnet gateway, its connection settings (host and port) can be specified at runtime using environment variables so that all prompts that omit explicit connection parameters will be routed to this device.

export BACNET_MCP_BACNET__HOST=10.0.0.1
export BACNET_MCP_BACNET__PORT=47808

These settings can also be specified in a .env file in the working directory.

# .env
bacnet_mcp_bacnet__host=10.0.0.1
bacnet_mcp_bacnet__port=47808

When interacting with multiple devices, each device’s connection parameters (host, port) can be defined with a unique name in a devices.json file in the working directory. Prompts can then refer to devices by name.

{
  "devices": [
    {"name": "Boiler", "host": "10.0.0.3", "port": 47808},
    {"name": "Valve", "host": "10.0.0.4", "port": 47808}
  ]
}

MCP Inspector

To confirm the server is up and running and explore available resources and tools, run the MCP Inspector and connect it to the BACnet MCP server at http://127.0.0.1:8000/mcp/. Make sure to set the transport to Streamable HTTP.

npx @modelcontextprotocol/inspector

s01

Core Concepts

The BACnet MCP server leverages FastMCP 2.0's core building blocks - resource templates, tools, and prompts - to streamline BACnet read and write operations with minimal boilerplate and a clean, Pythonic interface.

Read Properties

Each object on a device is mapped to a resource (and exposed as a tool) and resource templates are used to specify connection details (host, port) and read parameters (instance, property).

@mcp.resource("udp://{host}:{port}/{obj}/{instance}/{prop}")
@mcp.tool(
    annotations={
        "title": "Read Property",
        "readOnlyHint": True,
        "openWorldHint": True,
    }
)
async def read_property(
    host: str = settings.bacnet.host,
    port: int = settings.bacnet.port,
    obj: str = "analogValue",
    instance: str = "1",
    prop: str = "presentValue",
) -> str:
    """Reads the content of a BACnet object property on a remote unit."""
    ...

Write Properties

Write operations are exposed as a tool, accepting the same connection details (host, port) and allowing to set the content of an object property in a single, atomic call.

@mcp.tool(
    annotations={
        "title": "Write Property",
        "readOnlyHint": False,
        "openWorldHint": True,
    }
)
async def write_property(
    host: str = settings.bacnet.host,
    port: int = settings.bacnet.port,
    obj: str = "analogValue,1",
    prop: str = "presentValue",
    data: str = "1.0",
) -> str:
    """Writes a BACnet object property on a remote device."""
    ...

Authentication

To enable Bearer Token authentication for the Streamable HTTP transport, provide the RSA public key in PEM format in the .env file. Check out the Bearer Token Authentication section for more details.

Interactive Prompts

Structured response messages are implemented using prompts that help guide the interaction, clarify missing parameters, and handle errors gracefully.

@mcp.prompt(name="bacnet_help", tags={"bacnet", "help"})
def bacnet_help() -> list[Message]:
    """Provides examples of how to use the BACnet MCP server."""
    ...

Here are some example text inputs that can be used to interact with the server.

Read the presentValue property of analogInput,1 at 10.0.0.4.
Fetch the units property of analogInput 2.
Write the value 42 to analogValue instance 1.
Set the presentValue of binaryOutput 3 to True.

Examples

The examples folder contains sample projects showing how to integrate with the BACnet MCP server using various client APIs to provide tools and context to LLMs.

Docker

The BACnet MCP server can be deployed as a Docker container as follows:

docker run -d \
  --name bacnet-mcp \
  --restart=always \
  -p 8080:8000 \
  --env-file .env \
  ghcr.io/ezhuk/bacnet-mcp:latest

This maps port 8080 on the host to the MCP server's port 8000 inside the container and loads settings from the .env file, if present.

License

The server is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bacnet_mcp-0.2.1.tar.gz (140.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bacnet_mcp-0.2.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file bacnet_mcp-0.2.1.tar.gz.

File metadata

  • Download URL: bacnet_mcp-0.2.1.tar.gz
  • Upload date:
  • Size: 140.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bacnet_mcp-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0cbb8cda0f4be64a5e53617ba92411a3583cea1600abbd0056b2da70632bfc9e
MD5 74bc2cb5273eabb1afd33f51b5cf3fff
BLAKE2b-256 588707eabaa04093e95f62f21136260aa342422daa757fed8f0bab7d24a03a59

See more details on using hashes here.

Provenance

The following attestation bundles were made for bacnet_mcp-0.2.1.tar.gz:

Publisher: pypi.yml on ezhuk/bacnet-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bacnet_mcp-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: bacnet_mcp-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bacnet_mcp-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 230b730ebfd60326cfbfcfa13f590dafdc86549b2fec6071e605de653c422ce8
MD5 328b3d4a1b586773ebcf0d1746db9168
BLAKE2b-256 48a497c35587aa5bfe3edd327b50bf1808acf39656640a96059896615f5d93aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for bacnet_mcp-0.2.1-py3-none-any.whl:

Publisher: pypi.yml on ezhuk/bacnet-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page