netbox_update_object
Modify existing NetBox objects by specifying object type, ID, and update data to maintain accurate infrastructure records.
Instructions
Update an existing object in NetBox.
Args: object_type: String representing the NetBox object type (e.g. "devices", "ip-addresses") object_id: The numeric ID of the object to update data: Dict containing the object data to update (only changed fields needed)
Returns: The updated object as a dict
Example: To update a site's description: netbox_update_object("sites", 1, {"description": "Updated description"})
To change a device's status: netbox_update_object("devices", 5, {"status": "offline"})
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | ||
| object_id | Yes | ||
| object_type | Yes |
Implementation Reference
- server.py:318-347 (handler)The main handler function for the 'netbox_update_object' MCP tool. It validates the object_type against NETBOX_OBJECT_TYPES, constructs the endpoint, and delegates the update to the NetBoxRestClient.update method.@mcp.tool() def netbox_update_object(object_type: str, object_id: int, data: dict): """ Update an existing object in NetBox. Args: object_type: String representing the NetBox object type (e.g. "devices", "ip-addresses") object_id: The numeric ID of the object to update data: Dict containing the object data to update (only changed fields needed) Returns: The updated object as a dict Example: To update a site's description: netbox_update_object("sites", 1, {"description": "Updated description"}) To change a device's status: netbox_update_object("devices", 5, {"status": "offline"}) """ # Validate object_type exists in mapping if object_type not in NETBOX_OBJECT_TYPES: valid_types = "\n".join(f"- {t}" for t in sorted(NETBOX_OBJECT_TYPES.keys())) raise ValueError(f"Invalid object_type. Must be one of:\n{valid_types}") # Get API endpoint from mapping endpoint = NETBOX_OBJECT_TYPES[object_type] # Make API call return netbox.update(endpoint, object_id, data)
- server.py:5-98 (helper)Global mapping dictionary of NetBox object types to their corresponding API endpoints. Used by the handler for validation and endpoint resolution.# Mapping of simple object names to API endpoints NETBOX_OBJECT_TYPES = { # DCIM (Device and Infrastructure) "cables": "dcim/cables", "console-ports": "dcim/console-ports", "console-server-ports": "dcim/console-server-ports", "devices": "dcim/devices", "device-bays": "dcim/device-bays", "device-roles": "dcim/device-roles", "device-types": "dcim/device-types", "front-ports": "dcim/front-ports", "interfaces": "dcim/interfaces", "inventory-items": "dcim/inventory-items", "locations": "dcim/locations", "manufacturers": "dcim/manufacturers", "modules": "dcim/modules", "module-bays": "dcim/module-bays", "module-types": "dcim/module-types", "platforms": "dcim/platforms", "power-feeds": "dcim/power-feeds", "power-outlets": "dcim/power-outlets", "power-panels": "dcim/power-panels", "power-ports": "dcim/power-ports", "racks": "dcim/racks", "rack-reservations": "dcim/rack-reservations", "rack-roles": "dcim/rack-roles", "regions": "dcim/regions", "sites": "dcim/sites", "site-groups": "dcim/site-groups", "virtual-chassis": "dcim/virtual-chassis", # IPAM (IP Address Management) "asns": "ipam/asns", "asn-ranges": "ipam/asn-ranges", "aggregates": "ipam/aggregates", "fhrp-groups": "ipam/fhrp-groups", "ip-addresses": "ipam/ip-addresses", "ip-ranges": "ipam/ip-ranges", "prefixes": "ipam/prefixes", "rirs": "ipam/rirs", "roles": "ipam/roles", "route-targets": "ipam/route-targets", "services": "ipam/services", "vlans": "ipam/vlans", "vlan-groups": "ipam/vlan-groups", "vrfs": "ipam/vrfs", # Circuits "circuits": "circuits/circuits", "circuit-types": "circuits/circuit-types", "circuit-terminations": "circuits/circuit-terminations", "providers": "circuits/providers", "provider-networks": "circuits/provider-networks", # Virtualization "clusters": "virtualization/clusters", "cluster-groups": "virtualization/cluster-groups", "cluster-types": "virtualization/cluster-types", "virtual-machines": "virtualization/virtual-machines", "vm-interfaces": "virtualization/interfaces", # Tenancy "tenants": "tenancy/tenants", "tenant-groups": "tenancy/tenant-groups", "contacts": "tenancy/contacts", "contact-groups": "tenancy/contact-groups", "contact-roles": "tenancy/contact-roles", # VPN "ike-policies": "vpn/ike-policies", "ike-proposals": "vpn/ike-proposals", "ipsec-policies": "vpn/ipsec-policies", "ipsec-profiles": "vpn/ipsec-profiles", "ipsec-proposals": "vpn/ipsec-proposals", "l2vpns": "vpn/l2vpns", "tunnels": "vpn/tunnels", "tunnel-groups": "vpn/tunnel-groups", # Wireless "wireless-lans": "wireless/wireless-lans", "wireless-lan-groups": "wireless/wireless-lan-groups", "wireless-links": "wireless/wireless-links", # Extras "config-contexts": "extras/config-contexts", "custom-fields": "extras/custom-fields", "export-templates": "extras/export-templates", "image-attachments": "extras/image-attachments", "jobs": "extras/jobs", "saved-filters": "extras/saved-filters", "scripts": "extras/scripts", "tags": "extras/tags", "webhooks": "extras/webhooks", }
- netbox_client.py:221-239 (helper)The update method of NetBoxRestClient class, which performs the actual HTTP PATCH request to the NetBox REST API to update the specified object.def update(self, endpoint: str, id: int, data: Dict[str, Any]) -> Dict[str, Any]: """ Update an existing object in NetBox via the REST API. Args: endpoint: The API endpoint (e.g., 'dcim/sites', 'ipam/prefixes') id: ID of the object to update data: Object data to update Returns: The updated object as a dict Raises: requests.HTTPError: If the request fails """ url = self._build_url(endpoint, id) response = self.session.patch(url, json=data, verify=self.verify_ssl) response.raise_for_status() return response.json()