ui-network-mcp
CLAUDE.md1 starsChanged 15 days agoMITView on GitHub
The repository root is also a Claude Code plugin (unifi) and a marketplace (ui-network-mcp), in .claude-plugin/. plugin.json declares the options (userConfig) and the MCP server. The MCP server is inline in plugin.json, because a .mcp.json at the root would also be a project MCP server for each person who opens this repository. The server starts with uv run --project ${CLAUDE_PLUGIN_ROOT}, so the server always has the same version as the skills. An unset option gives an empty environment variable, which…
- Reads credentials
In this repository4 other files it gives its agents.
- client-troubleshootingSkill
- firewall-auditSkill
- firewall-changeSkill
- health-checkSkill
The file
We split this CLAUDE.md into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 37
Put the tool in the server/tools/ module of its tag.
- Very specific: line 38
Use the SiteId, Filter, Limit, and Offset annotated types for parameters.
- Very specific: line 39
Use the site_page and site_item helpers for site-scoped endpoints.
≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Commands
uv run pytest # all tests
uv run pytest tests/test_server.py::test_name # one test
uv run ruff check && uv run ruff format # lint and format
uv run ui-network-mcp # start the server (stdio), needs the UNIFI_* variables
claude plugin validate . --strict # check the plugin and the marketplace manifests
claude --plugin-dir . plugin details unifi # show the skills and their token costPlugin
The repository root is also a Claude Code plugin (unifi) and a marketplace (ui-network-mcp), in .claude-plugin/. plugin.json declares the options (userConfig) and the MCP server. The MCP server is inline in plugin.json, because a .mcp.json at the root would also be a project MCP server for each person who opens this repository. The server starts with uv run --project ${CLAUDE_PLUGIN_ROOT}, so the server always has the same version as the skills. An unset option gives an empty environment variable, which Settings ignores.
The skills in skills/ name the tools and the fields of the tool results. When you rename a tool or a result field, update the skills. Keep the version in plugin.json equal to the version in pyproject.toml. For a release, follow the "Release" section of README.md.
Architecture
This project is a FastMCP server for the UniFi Network integration API, version 11.0.97. Most tools are read-only. The write tools have the write tag, and build_server hides them unless allow_writes is true (UNIFI_ALLOW_WRITES). The full API specification is in network_v11.0.97_openapi.json. Git ignores that file, because Ubiquiti owns it. If the file is missing, download it from https://developer.ui.com/network/v11.0.97/openapi.json into the repository root. Search that file for an endpoint schema before you add a tool. Do not read the whole file, because it is large.
The package in src/ui_network_mcp/ has these layers. Each file holds one type or one group of related functions:
config.py:Settings(pydantic-settings) reads theUNIFI_*variables. The user must set exactly one ofUNIFI_HOST,UNIFI_CONSOLE_ID, orUNIFI_BASE_URL.resolved_base_urlmakes the local-console URL or the cloud-connector URL from that value. The settings come only from the environment. The server does not read a.envfile, because MCP hosts give the settings as environment variables.client/:UniFiClient(unifi_client.py) is a thin wrapper aroundhttpx.AsyncClient. It removesNonequery parameters. It changes all HTTP errors and transport errors intoUniFiAPIError(errors.py), a subclass ofToolError, so that FastMCP sends the message to the MCP client.get_allfollows the pagination (page size 200).gather_limitedsends parallel requests with a semaphore.post,put, andpatchremoveNonekeys from the body. The client replaces each secret in a response with***REDACTED***(redaction.py), and refuses a write body that contains this placeholder. A 401 or 403 error on a write request adds a hint about the write access of the API key. The package__init__.pyexportsJSON,MAX_PAGE_SIZE,UniFiAPIError, andUniFiClient.server/:app.pyhasbuild_server(client_factory, default_site_id, allow_writes)andcreate_server(). The lifespan creates the client and puts it inctx.lifespan_context.create_server()is the production entry point, andmain()in__init__.pycalls it.parameters.pyhas the shared parameter types,WRITE_TAG, and the annotationsREAD_ONLY,ADDITIVE_WRITE, andDESTRUCTIVE_WRITE.sites.pyhasclient_of,resolve_site,site_page, andsite_item.server/tools/: one module for each tag. Each module has aregister(mcp)function that defines its tools as closures.tools/__init__.pycalls eachregisterfunction inregister_all.models/: pydantic models for the request bodies of the write tools.ApiModeluses the camelCase API names as aliases and forbids unknown keys, so an agent can copy fields from a GET result.request_body(**fields)makes a body withoutNonevalues. The specification is wrong about protocol names: the console uses the uppercase keys of the discriminator mapping (TCP,ICMPV6), not the lowercase enum.reports/: pure functions that make one summary from many API responses, for the combined tools. One file for each report.
Patterns to follow when you add a tool:
- Put the tool in the
server/tools/module of its tag. For a new tag, add a module and add it toregister_all. - Use the
SiteId,Filter,Limit, andOffsetannotated types for parameters. - Use the
site_pageandsite_itemhelpers for site-scoped endpoints. They callresolve_site, which uses the givensite_id, then the configured default, then the only site of the console.resolve_sitekeeps the result of the lookup in the lifespan context. - Give each tool
annotations=READ_ONLYand atagsset. get_topologyis a combined tool. It reads all devices, the details of each device, and all clients. The pure functionbuild_topologyinreports/topology.pythen makes the tree from theuplink.deviceIdof each device.- A combined tool reads only the data it needs. For example,
get_wifi_overviewandget_switch_port_reportread the details only of the devices whoseinterfaceslist includesradiosorports. A combined tool that reads statistics or references for each item usesgather_limited(..., return_errors=True), so that one failed item does not stop the report.
Patterns to follow when you add a write tool:
- Give the tool the
WRITE_TAGtag and theADDITIVE_WRITEorDESTRUCTIVE_WRITEannotation. - Model a nested body in
models/with discriminated unions. For a flat body, give the fields as tool parameters withFieldconstraints, and make the body withrequest_body. Seecreate_vouchers. Check the models against the real objects of a console: each GET result must parse, andrequest_bodymust give back the same JSON. A read-only API key is sufficient for this check. - A PUT endpoint needs the full object. An update tool takes optional fields, reads the object, removes
id,index, andmetadata, adds the changes, and sends the result. Seeupdate_firewall_policy. An object with a secret, such as a WiFi broadcast with a passphrase, needs a read without redaction for this step. - FastMCP inlines each
$refof a tool schema. Thus large models make a large schema:create_firewall_policyhas about 48 KB.
Tests
The tests use respx to mock the HTTP API at BASE and the in-memory FastMCP Client to call tools. make_server() calls build_server with a client factory that does not need settings. pytest-asyncio runs in auto mode, so async tests need no marker.
test_tools_are_read_only checks the number of read-only tools, and test_write_tools_need_allow_writes checks the number of all tools. Update these numbers when you add or remove a tool. Also update the tool table in README.md.
Writing style
The README, docstrings, comments, and error messages use Simplified Technical English: short sentences, active voice, no contractions. Keep this style in new text.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

