
NetBox MCP
io.github.mhajder由 GitHub 账号 mhajder 发布v0.3.0更新于 Nov 7, 2026
MCP server for NetBox DCIM/IPAM with read-only and dry-run modes
概览
本地 MCP 服务器,让助手以结构化方式读写 NetBox DCIM/IPAM 实例,并提供只读与试运行保护。
- 可以做什么
- 列出、筛选、搜索并读取任意 NetBox 对象类型(含插件类型),查看变更日志与服务器状态
- 执行只读 GraphQL 查询,并在写入前查看对象类型的可写字段与可选值
- 查找空闲 IP、前缀、VLAN 和 ASN,追踪线缆路径,渲染设备配置,计算前缀利用率并寻找机柜空间
- 单个或批量创建、更新、删除对象,分配下一个空闲资源,连接线缆并运行自定义脚本
- 可选地把改动暂存到 netbox-branching 分支而非主分支
- 适用场景
- 适合助手需要回答网络资产问题或在 NetBox 中进行受控变更的场景,例如审计设备与 IP 空间、规划分配,或准备供人工审核的改动。只读或试运行模式便于在开放写入前先做探索性使用。
- 运行要求
- 本地 Python 3.11 至 3.15 运行环境(用 uvx 或 pip 运行)或 Docker 镜像;可访问的 NetBox 4.2 或更新版本;NETBOX_URL 以及具备所需权限的 NetBox API 令牌(NETBOX_TOKEN)。可选设置涵盖 SSL 校验、超时、限流、插件发现、分支、HTTP 传输与 Sentry。
安装
在 SourceWeft 中
- 打开 控制台中的 NetBox MCP,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
NetBox MCP Server
Give AI agents structured access to NetBox, your network source of truth
NetBox MCP Server is a Python-based Model Context Protocol (MCP) server that gives AI assistants structured access to NetBox - the source of truth for network infrastructure (DCIM and IPAM). A small set of generic tools covers all 139 core object types of NetBox 4.7 (and plugin types, if enabled), plus specialised tools for search, change logs, GraphQL, free IP/prefix/VLAN allocation, prefix utilization, free rack space, cable tracing and connecting, config rendering, custom scripts and (optionally) netbox-branching. Writes can be hidden entirely (read-only mode) or simulated (dry-run mode).
✨ Features
Core Features
- Query any NetBox object type with filtering, ordering and pagination through one tool
- Keep responses small with
fields,omitandbrief- the tools steer the model to use them - Search many object types at once, with explicit reporting of failed and truncated types
- Read the change log (who changed what, when) and NetBox status/version/plugins
- Run read-only GraphQL queries for nested data in one round trip
- List free IPs, prefixes, VLANs and ASNs; trace cable paths; render device configs
- Compute prefix utilization (as the NetBox UI shows it) and find racks with room for a device
Management Operations
- Create, update and delete any object type, singly or in bulk (NetBox runs a bulk write as one transaction)
- Allocate the next free IP, prefix, VLAN or ASN atomically
- Connect ports with a cable, naming them by device and port name
- Run NetBox custom scripts (changes rolled back unless
commitis set) - Optionally stage changes in a netbox-branching branch instead of main
- Describe an object type's writable fields and choices before writing
Advanced Capabilities
- Read-only mode hides every write tool; dry-run mode turns every write into a preview
- NetBox v2 (
Bearer nbt_...) and legacy v1 (Token ...) API tokens - Plugin object type discovery (e.g.
netbox_dns.zone) - Filter validation that rejects filters NetBox would silently ignore (
__in, multi-hop lookups) - Retries on 429/5xx without ever replaying a create after a server error
- Tag-based tool filtering, optional tool-search transform, rate limiting and response size limit
- Bearer token authentication for HTTP transport
- Multiple transport options (STDIO, SSE, HTTP)
- Optional Sentry integration for error tracking
🚀 Installation
Prerequisites
- Python 3.11 to 3.15
- A NetBox instance, version 4.2 or newer. Features added later (
omit, v2 tokens,/api/authentication-check/) are used when the server detects them - A NetBox API token with the permissions you want the assistant to have. The token is the real security boundary: a read-only token cannot write, whatever this server's settings are
Quick Install from PyPI
The easiest way to get started is to install from PyPI:
Remember to configure the environment variables for your NetBox instance before running the server:
Install from Source
- Clone the repository:
- Install dependencies:
- Configure environment variables:
- Run the server:
Using Docker
A Docker image is available on GitHub Packages for easy deployment.
Development Setup
For development with additional tools:
🔧 Configuration
Environment Variables
🧰 Available Tools
Object types are named app.model, as NetBox itself names them (dcim.device, ipam.prefix, virtualization.virtualmachine). API paths such as dcim/devices are accepted too. With branching enabled, every tool that reads or writes objects also takes an optional branch argument.
Objects (read)
Specialised (read)
Write
Tool Tags
Every tool is tagged netbox plus a group tag, which DISABLED_TAGS can switch off: objects, search, changelog, status, graphql, ipam, dcim, config, branching, scripts, write and delete. Read tools also carry read-only.
🔒 Security & Safety Features
Read-Only Mode
Read-only mode hides every write tool - the client only sees the 13 read tools (14 with branching enabled):
Dry-Run Mode
Dry-run mode keeps the write tools visible, but none of them changes NetBox. Each one resolves and validates its target, then returns the request it would have sent, flagged "dry_run": true. Updates and deletes also fetch the current object, so the preview shows the values that would change and exactly what would be deleted:
READ_ONLY_MODE takes precedence: when both are set, write tools are hidden.
NetBox Branching
With the netbox-branching plugin, changes can be staged in a branch and reviewed before they are merged into main. Branching support is off by default, so a NetBox without the plugin gets no branch tools and no branch argument. Enable it with:
This adds netbox_list_branches and netbox_create_branch, and a branch argument (a branch name or its schema ID) to every other tool. To send every call to one branch by default:
Setting NETBOX_BRANCH without NETBOX_BRANCHING_ENABLED=true is a configuration error: the server refuses to start rather than silently writing to main.
Branch names are resolved to the schema ID that the X-NetBox-Branch header needs. Merging, syncing and reverting are deliberately not exposed as tools - they belong in a human review step.
Plugin Discovery
The first time a call names an unknown type (or netbox_list_object_types runs), the server reads /api/core/object-types/ and adds every plugin model with a REST endpoint (for example netbox_dns.zone). Plugin types never shadow core types. If discovery fails, the core types keep working.
Tag-Based Tool Filtering
You can disable specific categories of tools by setting disabled tags. For example, allow creates and updates but never deletes:
Response Size Limit
Large NetBox objects add up quickly. RESPONSE_MAX_SIZE truncates any tool response above the given number of bytes:
Tool Search for Large Toolsets
FastMCP tool search can reduce prompt size for servers with many tools.
When enabled, list_tools returns two synthetic tools:
search_tools: Finds matching tools and returns their full schemascall_tool: Executes any discovered tool by name
Enable it with:
bm25 supports natural language queries, while regex uses a regex
pattern input for deterministic matching.
Tool search respects existing visibility controls (read-only mode and disabled tags).
Rate Limiting
The server supports rate limiting to control API usage and prevent abuse. If enabled, requests are limited per client using a sliding window algorithm.
Enable rate limiting by setting the following environment variables in your .env file:
If RATE_LIMIT_ENABLED is set to true, the server will apply rate limiting middleware. Adjust RATE_LIMIT_MAX_REQUESTS and RATE_LIMIT_WINDOW_MINUTES as needed for your environment.
Sentry Error Tracking & Monitoring (Optional)
The server optionally supports Sentry for error tracking, performance monitoring, and debugging. Sentry integration is completely optional and only initialized if configured.
Installation
To enable Sentry monitoring, install the optional dependency:
Configuration
Enable Sentry by setting the SENTRY_DSN environment variable in your .env file:
Features
When enabled, Sentry automatically captures:
- Exceptions & Errors: All unhandled exceptions with full context
- Performance Metrics: Request/response times and traces
- MCP Integration: Detailed MCP server activity and interactions
- Logs & Breadcrumbs: Application logs and event trails for debugging
- Context Data: Environment, client info, and request parameters
Getting a Sentry DSN
- Create a free account at sentry.io
- Create a new Python project
- Copy your DSN from the project settings
- Set it in your
.envfile
Disabling Sentry
Sentry is completely optional. If you don't set SENTRY_DSN, the server will run normally without any Sentry integration, and no monitoring data will be collected.
SSL/TLS Configuration
The server supports SSL certificate verification and custom timeout settings:
Certificates are verified against the operating system trust store, so a NetBox behind an internal CA works as soon as that CA is trusted by the OS. SSL_CERT_FILE or SSL_CERT_DIR take precedence when set.
Transport Configuration
The server supports multiple transport mechanisms for the MCP protocol:
STDIO Transport (Default)
The default transport uses standard input/output for communication. This is ideal for local usage and integration with tools that communicate via stdin/stdout:
HTTP SSE Transport (Server-Sent Events)
For network-based deployments, you can use HTTP with Server-Sent Events. This allows the MCP server to be accessed over HTTP with real-time streaming:
When using SSE transport with a bearer token, clients must include the token in their requests:
HTTP Streamable Transport
The HTTP Streamable transport provides HTTP-based communication with request/response streaming. This is ideal for web integrations and tools that need HTTP endpoints:
When using streamable transport with a bearer token:
Per-user NetBox tokens
By default every client shares the server's NETBOX_TOKEN, so NetBox sees one user. With NETBOX_TOKEN_PASSTHROUGH=true, each client sends its own NetBox API token instead. NetBox applies that user's permissions and the changelog records the real user:
- Requests without a token, or with a token NetBox rejects, get HTTP 401. If NetBox cannot be reached to check a token within 10 seconds (or
NETBOX_TIMEOUT, if lower), the request gets HTTP 503 withRetry-After, so clients retry instead of logging in again. The 503 passes on NetBox's ownRetry-Afterwhen NetBox sends one. Accepted tokens are cached for 60 seconds. After that, the token is still accepted right away for up to 10 minutes while the server re-checks it with NetBox in the background, so a known user never waits on a check, even during a NetBox outage. A revoked token is dropped once its re-check comes back; until then it only reaches tools that don't call NetBox (such as the tool list), because NetBox refuses the token on every call that does. Rejected tokens are cached for 30 seconds, so a token just created in NetBox may be refused for up to 30 seconds if it was tried before it existed. At most 8 token checks reach NetBox at once; requests with a token the server hasn't seen yet wait for a free slot, and get HTTP 503 if the wait exceeds the check timeout. - v2 (
nbt_...) and legacy v1 tokens both work; the server sends each to NetBox with the right scheme. NETBOX_TOKENis ignored. Only thehttpandssetransports are supported, and the server refuses to start ifMCP_HTTP_BEARER_TOKENis set too, since both use theAuthorizationheader.- With
RATE_LIMIT_ENABLED=true, each NetBox user gets their own rate-limit window (each token on NetBox before 4.5), so the limit no longer caps the server's total load on NetBox. - With
NETBOX_PLUGIN_DISCOVERY=true, plugin types found with any user's token are added to one shared list.rediscoverreplaces that list with what the calling user can see, which drops uninstalled plugins; another user's call that names a type only they can see rediscovers it with their token. - Clients send their NetBox tokens to this server, so put it behind HTTPS.
Note: The HTTP transport requires proper JSON-RPC formatting with jsonrpc and id fields. The server may also require session initialization for some operations.
Health Endpoint
Both HTTP transports (sse and http) serve GET /health, which answers 200 ok
when the server is handling requests. It needs no bearer token and does not
contact NetBox, so a NetBox outage does not mark the MCP server unhealthy.
The Docker image's HEALTHCHECK uses it:
For more information on FastMCP transports, see the FastMCP documentation.
🤝 Contributing
Contributions are welcome. See CONTRIBUTING.md for the dev setup, checks and commit message format, and use the issue templates for bugs and feature requests.
Found a security problem? Please report it privately as described in SECURITY.md.
📜 License
MIT License - see LICENSE for details.
来源:README.md,提交 3240808
工具
0版本历史
4- v0.3.0最新Nov 7, 2026
- v0.2.1Oct 23, 2026
- v0.2.0Oct 19, 2026
- v0.1.0Sep 27, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分