Go Unifi Mcp

io.github.claytono由 GitHub 帳號 claytono 發布v0.3.1更新於 Oct 24, 2026

Manage UniFi sites, devices, clients, networks, port forwarding, DNS, and firewall

概覽

AI 產生的概覽

面向 UniFi Network Controller 的 MCP 伺服器,讓助理檢視與管理站點、裝置、用戶端、網路、防火牆規則、DNS 及連接埠轉送。

可以做什麼
透過工具索引、直接執行或平行批次呼叫檢索並調度 UniFi 操作(lazy 模式以 3 個中繼工具涵蓋 252 項操作)。列出並檢視站點、裝置、用戶端、網路及其他控制器資源,可將不透明 ID 解析為可讀名稱。對清單結果依欄位篩選、全文搜尋與欄位投影。建立、更新與刪除網路、防火牆規則、DNS、連接埠轉送等 UniFi 設定。可切換為 eager 模式直接註冊全部 252 個工具。
適用情境
適合讓 AI 助理檢視或修改 UniFi 網路:稽核裝置與用戶端、檢查防火牆規則,或編輯網路、DNS 與連接埠轉送,而不必在控制器介面中逐項操作。
執行需求
以本機程序執行(二進位檔、Homebrew、Nix、Docker 映像或 go install),支援 macOS 與 Linux。需要能連線至 UniFi Network Controller 的網路,並提供 UNIFI_API_KEY,或同時提供 UNIFI_USERNAME 與 UNIFI_PASSWORD,以及 UNIFI_HOST。選用:UNIFI_SITE、UNIFI_VERIFY_SSL、UNIFI_LOG_LEVEL、UNIFI_TOOL_MODE。
安裝前請注意
需要控制器憑證:API 金鑰或本機管理員使用者名稱與密碼,透過環境變數傳入。此伺服器可建立、更新與刪除網路設定,出錯會影響實際基礎設施。更新採讀取-修改-寫入流程且非原子性,並行修改可能競爭並以最後寫入為準。停用 SSL 驗證會降低連線安全性。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Go Unifi Mcp,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

go-unifi-mcp

A Model Context Protocol (MCP) server for UniFi Network Controller, written in Go.

Overview

go-unifi-mcp provides an MCP interface to UniFi Network Controller, enabling AI assistants and other MCP clients to interact with your UniFi infrastructure.

Why this exists

I couldn’t find an MCP server that supported both v1 and v2 firewall rules and IPv6, so I built one. This wraps the go-unifi library (which I trust from my Terraform provider experience) and leans on its generated API surface. The server is generated from the controller’s own API definitions, which makes it much easier to keep tool coverage up to date as UniFi evolves.

UniFi controller versioning

This project generates tools against the same UniFi Controller version pinned by go-unifi. When go-unifi updates its supported controller version, we regenerate our field definitions and tool metadata to match. We support the same controller range; see their controller support range.

Installation

Binary (GitHub Releases)

Download pre-built binaries from the Releases page. Binaries are available for macOS and Linux (amd64/arm64).

bash
# macOS (Apple Silicon)curl -L https://github.com/claytono/go-unifi-mcp/releases/latest/download/go-unifi-mcp_darwin_arm64.tar.gz | tar xzsudo mv go-unifi-mcp /usr/local/bin/
# macOS (Intel)curl -L https://github.com/claytono/go-unifi-mcp/releases/latest/download/go-unifi-mcp_darwin_amd64.tar.gz | tar xzsudo mv go-unifi-mcp /usr/local/bin/
# Linux (amd64)curl -L https://github.com/claytono/go-unifi-mcp/releases/latest/download/go-unifi-mcp_linux_amd64.tar.gz | tar xzsudo mv go-unifi-mcp /usr/local/bin/
# Linux (arm64)curl -L https://github.com/claytono/go-unifi-mcp/releases/latest/download/go-unifi-mcp_linux_arm64.tar.gz | tar xzsudo mv go-unifi-mcp /usr/local/bin/

Homebrew

Available from the claytono/homebrew-tap tap:

bash
brew install claytono/tap/go-unifi-mcp

Nix

bash
# Run without installingnix run github:claytono/go-unifi-mcp
# Install to your profilenix profile install github:claytono/go-unifi-mcp

Docker

Multi-architecture images (amd64/arm64) are published to GitHub Container Registry.

bash
# Latest (pinned to most recent release, rebuilt on base image updates)docker pull ghcr.io/claytono/go-unifi-mcp:latest
# Edge (built from main on every merge, unstable)docker pull ghcr.io/claytono/go-unifi-mcp:edge

Go Install

bash
go install github.com/claytono/go-unifi-mcp/cmd/go-unifi-mcp@latest

Configuration

UniFi Credentials

The server requires access to a UniFi Network Controller. Two authentication methods are supported:

  1. API Key (preferred): Create an API key in your UniFi controller under Settings > Control Plane > Integrations. Set UNIFI_HOST and UNIFI_API_KEY.

  2. Username/Password: Use a local admin account. Set UNIFI_HOST, UNIFI_USERNAME, and UNIFI_PASSWORD.

Claude Desktop

Add to your claude_desktop_config.json:

Using the binary:

json
{  "mcpServers": {    "unifi": {      "command": "/usr/local/bin/go-unifi-mcp",      "env": {        "UNIFI_HOST": "https://your-controller:443",        "UNIFI_API_KEY": "your-api-key"      }    }  }}

Using Docker:

json
{  "mcpServers": {    "unifi": {      "command": "docker",      "args": [        "run",        "-i",        "--rm",        "-e",        "UNIFI_HOST",        "-e",        "UNIFI_API_KEY",        "ghcr.io/claytono/go-unifi-mcp:latest"      ],      "env": {        "UNIFI_HOST": "https://your-controller:443",        "UNIFI_API_KEY": "your-api-key"      }    }  }}

Claude Code

bash
claude mcp add unifi -- go-unifi-mcp

Then set the required environment variables in your shell before running claude.

Environment Variables

VariableRequiredDefaultDescription
UNIFI_HOSTYes—UniFi controller URL
UNIFI_API_KEY*—API key (preferred auth method)
UNIFI_USERNAME*—Username for password auth
UNIFI_PASSWORD*—Password for password auth
UNIFI_SITENodefaultUniFi site name
UNIFI_VERIFY_SSLNotrueWhether to verify SSL certs
UNIFI_LOG_LEVELNoerrorgo-unifi client log level
UNIFI_TOOL_MODENolazyTool registration mode

* Either UNIFI_API_KEY or both UNIFI_USERNAME and UNIFI_PASSWORD must be set.

Log Levels

The UNIFI_LOG_LEVEL variable controls logging from the underlying go-unifi client library. The default is error because the client otherwise emits INFO messages to stderr, which can interfere with tools like mcp-cli that parse JSON on stdout/stderr.

LevelDescription
disabledNo logging
traceMost verbose, including wire details
debugDebug messages
infoInformational messages
warnWarnings only
errorErrors only (default)

Tool Modes

The server supports two tool registration modes, following the pattern established by unifi-network-mcp:

ModeToolsContext SizeDescription
lazy3~200 tokensMeta-tools only (default, recommended for LLMs)
eager252~55K tokensAll tools registered directly

Lazy mode (default) registers only 3 meta-tools that provide access to 252 UniFi operations (generated from the controller API):

  • tool_index - Search/filter the tool catalog by category or resource
  • execute - Execute any tool by name with arguments
  • batch - Execute multiple tools in parallel

This dramatically reduces context window usage while preserving full functionality. The LLM first queries the index to find relevant tools, then executes them via the dispatcher.

Eager mode registers all 252 tools directly, which may be useful for non-LLM clients or debugging but consumes significant context.

Update semantics: Updates use a read-modify-write flow against the controller API. We fetch the current resource, merge your fields, and submit the full object. This avoids clearing unspecified fields, but it is not atomic and concurrent updates can race (last write wins) because the UniFi API does not expose etags or revision IDs. In practice this is unlikely to be an issue, but it's something to be aware of.

ID Resolution

Responses from the UniFi API contain opaque ID references (e.g. network_id, usergroup_id, networkconf_id). By default, the server resolves these to human-readable names by looking up the referenced resource and injecting a sibling _name field:

json
{  "src_networkconf_id": "609fbf24e3ae433962e000de",  "src_networkconf_name": "IOT"}

Resolution uses a per-request cache, so listing 100 firewall rules that reference networks only makes one additional ListNetwork API call. Typical overhead is 10-40ms depending on how many distinct resource types are referenced.

To disable resolution for a specific call, pass "resolve": false in the tool arguments.

Query Parameters

All list operations support optional post-processing parameters for filtering and projecting results.

filter — Match items by field values. Supports three operators:

jsonc
// Exact match{"filter": {"type": "usw"}}
// Substring match (case-insensitive){"filter": {"name": {"contains": "office"}}}
// Regular expression (RE2 syntax: https://github.com/google/re2/wiki/Syntax){"filter": {"name": {"regex": "^ap-.*"}}}
// Multiple conditions (ANDed together){"filter": {"type": "uap", "name": {"contains": "echo"}}}

search — Case-insensitive full-text search across all string field values:

json
{ "search": "living room" }

fields — Project the response to include only specific keys:

json
{ "fields": ["name", "ip", "mac"] }

Parameters can be combined. Execution order is filter → search → fields, so you can filter on fields that are excluded from the output:

json
{  "filter": { "type": "uap" },  "search": "echo",  "fields": ["name", "ip"]}

Development

Prerequisites

  • Nix with flakes enabled
  • direnv (optional but recommended)

Developing

bash
# Clone the repositorygit clone https://github.com/claytono/go-unifi-mcp.gitcd go-unifi-mcp
# Enter the development environmentnix develop# Or with direnv:direnv allow
# Install pre-commit hookspre-commit install
# Run linterstask lint
# Run teststask test
# Run tests with coveragetask coverage

Available Tasks

bash
task lint        # Run linters via pre-committask test        # Run teststask coverage    # Run tests with coverage checkstask build       # Build the binarytask generate    # Run go generate

Testing with mcp-cli

The development environment includes mcp-cli for interactive testing of the MCP server.

  1. Create .envrc.local with your UniFi credentials (not tracked in git):

    bash
    export UNIFI_HOST="https://your-controller:443"export UNIFI_API_KEY="your-api-key"# Or use username/password:# export UNIFI_USERNAME="admin"# export UNIFI_PASSWORD="password"
  2. Build the binary:

    bash
    task build
  3. Test with mcp-cli:

    The .mcp_servers.json config provides two server entries:

    • go-unifi-mcp - eager mode (252 tools)
    • go-unifi-mcp-lazy - lazy mode (3 meta-tools)

    Eager mode (direct tool access):

    bash
    # List tools (shows all 252)mcp-cli info go-unifi-mcp
    # Call a tool directlymcp-cli call go-unifi-mcp list_device '{}'mcp-cli call go-unifi-mcp list_network '{"site": "default"}'

    Lazy mode (meta-tools):

    bash
    # List tools (shows only 3 meta-tools)mcp-cli info go-unifi-mcp-lazy
    # Query the tool indexmcp-cli call go-unifi-mcp-lazy tool_index '{}'mcp-cli call go-unifi-mcp-lazy tool_index '{"category": "list"}'mcp-cli call go-unifi-mcp-lazy tool_index '{"resource": "network"}'
    # Execute a tool via the dispatchermcp-cli call go-unifi-mcp-lazy execute '{"tool": "list_device", "arguments": {}}'
    # Batch execute multiple toolsmcp-cli call go-unifi-mcp-lazy batch '{"calls": [{"tool": "list_network", "arguments": {}}, {"tool": "list_device", "arguments": {}}]}'

Credits

This project builds upon:

  • go-unifi - Go client library for UniFi Network Controller
  • unifi-network-mcp - Python MCP server for UniFi that inspired this project
  • mcp-go - Go SDK for Model Context Protocol

License

MPL-2.0

來源:README.md,提交 3a442b9

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.3.1最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分