mcpField
N
netbox-review-integration

netbox-review-integration

github.com/netboxlabsTesting & quality2149 installsUpdated 2w ago
Repository

About netbox-review-integration

A checklist skill for reviewing code that calls NetBox APIs, aimed at developers maintaining NetBox integrations. It emphasizes version-aware checks for authentication, pagination, performance, error handling, and data integrity, with evidence-based findings.

Key features

  1. 01Authentication and token checks
  2. 02REST and GraphQL pagination checks
  3. 03API performance review
  4. 04Error and job handling checks
  5. 05Data integrity and update checks

Use cases

  1. 01Reviewing a NetBox API integration pull request
  2. 02Finding missing pagination or unsafe updates
  3. 03Checking version-specific API behavior
  4. 04Assessing API error and retry handling

MCP support

The skill mentions using a configured NetBox MCP server to verify object schemas and filter availability.

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/netboxlabs/skills --skill netbox-review-integration

After installing, type/netbox-review-integrationin Claude Code to confirm it loaded.

Details

From the project README

NetBox Integration Code Review

Your knowledge of NetBox APIs may be outdated. Verify specific API behaviors, limits, and patterns against current documentation before flagging issues.

Target: NetBox 4.5–4.7 (current 4.7.3). Several rules flip between 4.6 and 4.7 — establish the target version (GET /api/status/ → netbox-version, or the project's pin) before applying version-tagged rules.

Retrieval Sources

SourceURL / MethodUse for
NetBox REST API docshttps://netboxlabs.com/docs/netbox/integrations/rest-api/Current endpoint behavior
pynetbox repohttps://github.com/netbox-community/pynetboxSDK method signatures
Diode Python SDKhttps://github.com/netboxlabs/diode-sdk-pythonIngestion API patterns
NetBox MCP serverIf configured — verify object schemas and filter availabilityField validation

Review Workflow

Follow this checklist when reviewing NetBox integration code:

  1. Verify retrieval — Check current API docs for any endpoints/patterns you're unsure about
  2. Read the full file — understand the integration's intent before flagging issues
  3. Check authentication — token format, header usage, credential storage
  4. Check pagination — all list endpoints must handle pagination
  5. Check performance — config_context handling (version-dependent), brief mode / field selection, filter specificity
  6. Check error handling — HTTP errors, rate limits, timeouts, partial failures
  7. Check data integrity — correct use of PATCH vs PUT, bulk operation atomicity
  8. Provide evidence — reference specific line numbers and explain why something is wrong

Critical Rules

Authentication (AUTH)
IDRuleSeverity
AUTH-1Use nbt_-prefixed v2 tokens on NetBox 4.5+High
AUTH-2Never hardcode tokens in source — use env vars or secrets managerCritical
AUTH-3Use Bearer prefix in Authorization header (not Token on 4.5+)High
AUTH-4Verify token has required permissions for all accessed endpointsMedium
AUTH-5Flag reliance on v1 (Token <plaintext>) tokens — deprecated in 4.6, removed in v5.0; migrate to v2. On 4.6.1+ the v2 plaintext is shown once at creation, in the response token field (key is only the public identifier) — capture it thenHigh
AUTH-6Never create tokens with ?background=true (4.7.0/4.7.1 recorded plaintexts in job results; 4.7.2 returns 400), and never rely on a client-chosen token value on create (ignored on 4.7+)High
AUTH-7Executing custom scripts via POST /api/extras/scripts/<id>/ on 4.7+ requires a write-enabled token — flag read-only tokens used for itMedium
Pagination (PAG)
IDRuleSeverity
PAG-1All list endpoint calls MUST handle pagination (follow next links)Critical
PAG-2Never assume all results fit in one response — even small collections growHigh
PAG-3Set explicit limit parameter — don't rely on server default (50)Medium
PAG-4GraphQL queries MUST include pagination: {limit: N} at every list levelCritical
PAG-5Nested GraphQL lists need their own pagination parametersHigh
PAG-6Prefer cursor pagination over deep offsets for large reads — REST ?start=<id> (4.6+), GraphQL pagination: {start: N, limit: M} (4.5.2+); flag deep ?offset= scansMedium
Performance (PERF)
IDRuleSeverity
PERF-14.5–4.6: device/VM list queries MUST send ?omit=config_context (4.5.2+) or ?exclude=config_context. 4.7.0–4.7.2: config context is cached and always loaded; ?exclude= is silently ignored — do not flag its absence; flag code that depends on it for payload size and suggest ?fields=/?omit=/?brief=True. 4.7.3+: ?omit=config_context/?fields=/?brief=True skip the config-context DB annotation again — flag list reads that load config_context they never use. ?exclude= is a no-op on every 4.7.x; ?omit=config_context is the version-portable formCritical (4.5–4.6) / Low (4.7.0–4.7.2) / Medium (4.7.3+)
PERF-2Use ?brief=True for reference lookups and dropdownsHigh
PERF-3Use specific filters (name__ic=, site_id=) instead of ?q= at scaleHigh
PERF-4Use ?fields= to select only needed fieldsMedium
PERF-5Parallelize independent API calls — don't serialize unrelated requestsMedium
PERF-6Use bulk endpoints (POST/PATCH/DELETE arrays) instead of per-object callsHigh
PERF-7GraphQL depth must stay ≤ 3, never exceed 5High
Error Handling (ERR)
IDRuleSeverity
ERR-1Handle HTTP 4xx/5xx responses — don't assume successCritical
ERR-2Implement retry with backoff for 429 (rate limit) and 5xx errorsHigh
ERR-3Handle bulk failures — all-or-nothing on every version. On 4.7+ the body is {"detail", "errors": [{"index" or "id", "errors"}]}: map errors back to submitted objects (index for creates and malformed entries, id for updates/deletes) and resubmit only those; on 4.5–4.6 only the first failure's field errors are returnedMedium
ERR-4Check response.errors on Diode ingestion responsesHigh
ERR-5Handle branch async job failures (poll until terminal status)High
ERR-6?background=true (4.7+): 202 is accepted, not succeeded — code must poll job.url to a terminal status and check data.status_code. Flag 202 treated as success, If-Match combined with background (400), missing 503 handling (no worker), and — on 4.7.0–4.7.2 — ?background=true combined with X-NetBox-Branch (header dropped; write lands in main; fixed in 4.7.3)High
Data Integrity (DATA)
IDRuleSeverity
DATA-1Use PATCH for updates — PUT replaces entire objects, clearing omitted fieldsCritical
DATA-2Include id in each object for bulk PATCH/DELETE operationsHigh
DATA-3Use natural keys (slug/name) for readability but be aware of uniqueness constraintsMedium
DATA-4Validate dependency order for REST creates (parent before child)High
DATA-5IPAddress values MUST include CIDR prefix length (/24, not bare IP)High
DATA-6For tag edits, prefer write-only add_tags/remove_tags (4.6+) over read-modify-write of the full tags list — the latter clobbers concurrent writers' tagsMedium
DATA-7For read-modify-write on a single object under concurrency, use ETag + If-Match (4.6+); a 412 response means the object changed — re-fetch and retry rather than blind overwriteMedium
DATA-8On 4.7+, selection/multi-selection custom fields read as {"value", "label"} objects — flag custom_fields["x"] == "raw" comparisons and code that writes the read object back (fails validation); write the raw valueHigh
DATA-9Services: use port_mappings (["tcp/80"]) over the deprecated protocol/ports pair on 4.7+ (removed in 5.0); flag protocol__ic-style and port__empty filters (gone in 4.7)Medium

Anti-Patterns to Flag

Anti-PatternWhy It MattersFix
No pagination loopSilently drops data beyond first pageFollow next links until null
?q= for bulk filteringFull-text search is slow at scaleUse specific filter expressions
PUT for partial updatesClears fields you didn't intend to changeUse PATCH
Hardcoded token in sourceSecurity vulnerabilityUse environment variable
Sequential single-object creates100x slower than bulkUse array POST to list endpoint
Loading config_context on list queries that never use it10-100x slower on 4.5–4.6; extra DB annotation on 4.7.3+; payload bloat only on 4.7.0–4.7.2Add ?omit=config_context (4.5.2+, version-portable); ?exclude= works on 4.5–4.6 only and is ignored on every 4.7.x
Treating HTTP 202 from ?background=true as success (4.7+)Validation and the write happen later in the workerPoll the job URL; check status and data.status_code
custom_fields["env"] == "prod" on 4.7+Selection values are {"value", "label"} dicts — the comparison is always FalseCompare ["value"]; unwrap defensively for mixed 4.6/4.7 fleets
Creating API tokens via ?background=truePlaintext lands in job results (4.7.0/4.7.1); 400 on 4.7.2+Create tokens synchronously; run ≥ 4.7.3 (4.7.0/4.7.1 token leak; 4.7.3 adds branch-safe background writes and the config-context omit optimisation)
?background=true sent with X-NetBox-Branch on 4.7.0–4.7.2Branch header is dropped in the worker — the bulk write lands in main (or is rejected by Changes protect_main)Synchronous bulk writes in branch context on ≤ 4.7.2; carried correctly on 4.7.3+
Catching bare Exception on API callsHides real errorsCatch requests.HTTPError specifically
No timeout on HTTP requestsHangs indefinitely on network issuesSet timeout=30
GraphQL without pagination paramsOmitting pagination returns all rows; pagination without limit returns Strawberry's default 100 (not the REST default of 50) — both silently differ from expectationsAlways pass pagination: {limit: N} explicitly
Polling branch jobs without backoffWastes API calls, may trigger rate limitsExponential backoff (1s → 30s)

Version Notes

NetBox 4.7.3 (2026-10-13)
  • PERF-1 severity rises to Medium: ?omit=config_context/?fields=/?brief=True skip the config-context DB annotation again (?exclude= still a no-op). ERR-6's branch caveat closes: ?background=true now carries X-NetBox-Branch into the worker. Recommend ≥ 4.7.3 (4.7.0/4.7.1 token leak; 4.7.3 adds branch-safe background writes and the config-context omit optimisation).

Scope

This skill covers code that calls NetBox APIs. It does NOT cover:

Principles

  • Be certain. Retrieve current API docs before flagging version-specific issues.
  • Provide evidence. Reference line numbers and explain the actual failure mode.
  • Focus on correctness. A working integration that's slightly verbose is better than a broken clever one.
  • Severity matters. Critical issues break functionality. High issues degrade performance or reliability. Medium issues affect maintainability.
  • Don't over-flag. If code works correctly for its specific use case (e.g., small dataset that fits in one page), note the limitation but don't mark it critical.

Comments

Markdown supported