[Bug] NetBox MCP tools fail JSON parsing despite valid API response #126

Closed
opened 2026-01-23 22:28:54 +00:00 by lmiranda · 2 comments
Owner

Diagnostic Report

Generated: 2026-01-23T22:30:00Z
Command Tested: /cmdb-assistant:cmdb-device (device listing)
Reporter: Claude Code via /debug-report
Plugin: cmdb-assistant

Project Context

Field Value
Repository bandit-den/serv-bandit-apps
Git Remote git@100.82.122.98:bandit-den/serv-bandit-apps.git
Working Directory /home/bandit/apps
Current Branch main

Configuration

NetBox credentials at ~/.config/claude/netbox.env:

NETBOX_API_URL=https://netbox.hotserv.cloud
NETBOX_API_TOKEN=<configured and valid>

Diagnostic Results

Test 1: MCP Tool - dcim_list_devices

Call: mcp__plugin_cmdb-assistant_netbox__dcim_list_devices()
Status: FAIL
Error:

Invalid JSON response from NetBox: Expecting value: line 8 column 1 (char 7). Status code: 200, Content length: 3511 bytes

Test 2: MCP Tool - dcim_list_sites

Call: mcp__plugin_cmdb-assistant_netbox__dcim_list_sites()
Status: FAIL
Error:

Invalid JSON response from NetBox: Expecting value: line 8 column 1 (char 7). Status code: 200, Content length: 3509 bytes

Test 3: Direct curl - Same endpoint

Call:

curl -s -H "Authorization: Token <token>" "https://netbox.hotserv.cloud/api/dcim/devices/"

Status: PASS
Response: Valid JSON with 3 devices returned (HTTP 200)

Test 4: Direct curl - Sites endpoint

Call:

curl -s -H "Authorization: Token <token>" "https://netbox.hotserv.cloud/api/dcim/sites/"

Status: PASS
Response: Valid JSON with 3 sites returned (HTTP 200)

Test 5: Direct curl - Services creation

Call: POST to /api/ipam/services/
Status: PASS (with field name adjustment)
Note: API requires parent_object_type + parent_object_id instead of device field

Summary

  • Total Tests: 5
  • MCP Tool Tests: 2 FAILED
  • Direct API Tests: 3 PASSED

Failed Tools

Tool Error
dcim_list_devices JSON parsing error at line 8 col 1
dcim_list_sites JSON parsing error at line 8 col 1

Error Category

  • Logic/Parsing - MCP server incorrectly parsing valid JSON response
  • Authentication
  • Network
  • Parameter Format

Key Observations

  1. HTTP 200 with valid content length - NetBox API is responding correctly
  2. Same error position - "line 8 column 1 (char 7)" suggests consistent parsing issue
  3. curl works perfectly - Same credentials, same endpoints, valid JSON returned
  4. Content exists - 3511 bytes for devices, 3509 bytes for sites

Hypothesis

The MCP server's HTTP client or JSON parser is:

  1. Possibly receiving chunked/streamed response and failing to reassemble before parsing
  2. Reading response headers as part of body - "line 8" could be where JSON actually starts after headers
  3. Encoding issue - UTF-8 BOM or similar causing parse offset
  4. Buffer/streaming issue - Not waiting for complete response before parsing

Additional Issue: Service API Schema

When creating services via curl, the API rejected device field:

{"parent_object_type":["This field is required."],"parent_object_id":["This field is required."]}

Solution: Use parent_object_type: "dcim.device" + parent_object_id: <id> instead.

This suggests the MCP server may be using outdated NetBox API schema.

Suggested Investigation

  1. Check mcp-servers/netbox/ - HTTP client implementation
  2. Check response handling - Is it parsing headers as body?
  3. Check JSON decoder - Is it handling chunked encoding?
  4. Verify NetBox API version compatibility
  5. Check if httpx or requests is used and how streaming is handled

Reproduction Steps

  1. Configure ~/.config/claude/netbox.env with valid NetBox credentials
  2. Run any cmdb-assistant command like /cmdb-device list
  3. Observe JSON parsing error despite API returning valid data
  4. Verify with direct curl that API works correctly

Workaround

Use direct curl calls instead of MCP tools:

curl -s -H "Authorization: Token $NETBOX_API_TOKEN" "$NETBOX_API_URL/api/dcim/devices/"

Generated by /debug-report - Labels: Type/Bug, Component/Backend

## Diagnostic Report **Generated**: 2026-01-23T22:30:00Z **Command Tested**: `/cmdb-assistant:cmdb-device` (device listing) **Reporter**: Claude Code via /debug-report **Plugin**: cmdb-assistant ## Project Context | Field | Value | |-------|-------| | Repository | `bandit-den/serv-bandit-apps` | | Git Remote | `git@100.82.122.98:bandit-den/serv-bandit-apps.git` | | Working Directory | `/home/bandit/apps` | | Current Branch | `main` | ## Configuration NetBox credentials at `~/.config/claude/netbox.env`: ``` NETBOX_API_URL=https://netbox.hotserv.cloud NETBOX_API_TOKEN=<configured and valid> ``` ## Diagnostic Results ### Test 1: MCP Tool - dcim_list_devices **Call**: `mcp__plugin_cmdb-assistant_netbox__dcim_list_devices()` **Status**: FAIL **Error**: ``` Invalid JSON response from NetBox: Expecting value: line 8 column 1 (char 7). Status code: 200, Content length: 3511 bytes ``` ### Test 2: MCP Tool - dcim_list_sites **Call**: `mcp__plugin_cmdb-assistant_netbox__dcim_list_sites()` **Status**: FAIL **Error**: ``` Invalid JSON response from NetBox: Expecting value: line 8 column 1 (char 7). Status code: 200, Content length: 3509 bytes ``` ### Test 3: Direct curl - Same endpoint **Call**: ```bash curl -s -H "Authorization: Token <token>" "https://netbox.hotserv.cloud/api/dcim/devices/" ``` **Status**: PASS **Response**: Valid JSON with 3 devices returned (HTTP 200) ### Test 4: Direct curl - Sites endpoint **Call**: ```bash curl -s -H "Authorization: Token <token>" "https://netbox.hotserv.cloud/api/dcim/sites/" ``` **Status**: PASS **Response**: Valid JSON with 3 sites returned (HTTP 200) ### Test 5: Direct curl - Services creation **Call**: POST to `/api/ipam/services/` **Status**: PASS (with field name adjustment) **Note**: API requires `parent_object_type` + `parent_object_id` instead of `device` field ## Summary - **Total Tests**: 5 - **MCP Tool Tests**: 2 FAILED - **Direct API Tests**: 3 PASSED ### Failed Tools | Tool | Error | |------|-------| | `dcim_list_devices` | JSON parsing error at line 8 col 1 | | `dcim_list_sites` | JSON parsing error at line 8 col 1 | ### Error Category - [x] **Logic/Parsing** - MCP server incorrectly parsing valid JSON response - [ ] Authentication - [ ] Network - [ ] Parameter Format ### Key Observations 1. **HTTP 200 with valid content length** - NetBox API is responding correctly 2. **Same error position** - "line 8 column 1 (char 7)" suggests consistent parsing issue 3. **curl works perfectly** - Same credentials, same endpoints, valid JSON returned 4. **Content exists** - 3511 bytes for devices, 3509 bytes for sites ### Hypothesis The MCP server's HTTP client or JSON parser is: 1. **Possibly receiving chunked/streamed response** and failing to reassemble before parsing 2. **Reading response headers as part of body** - "line 8" could be where JSON actually starts after headers 3. **Encoding issue** - UTF-8 BOM or similar causing parse offset 4. **Buffer/streaming issue** - Not waiting for complete response before parsing ### Additional Issue: Service API Schema When creating services via curl, the API rejected `device` field: ```json {"parent_object_type":["This field is required."],"parent_object_id":["This field is required."]} ``` **Solution**: Use `parent_object_type: "dcim.device"` + `parent_object_id: <id>` instead. This suggests the MCP server may be using outdated NetBox API schema. ### Suggested Investigation 1. Check `mcp-servers/netbox/` - HTTP client implementation 2. Check response handling - Is it parsing headers as body? 3. Check JSON decoder - Is it handling chunked encoding? 4. Verify NetBox API version compatibility 5. Check if `httpx` or `requests` is used and how streaming is handled ## Reproduction Steps 1. Configure `~/.config/claude/netbox.env` with valid NetBox credentials 2. Run any cmdb-assistant command like `/cmdb-device list` 3. Observe JSON parsing error despite API returning valid data 4. Verify with direct curl that API works correctly ## Workaround Use direct curl calls instead of MCP tools: ```bash curl -s -H "Authorization: Token $NETBOX_API_TOKEN" "$NETBOX_API_URL/api/dcim/devices/" ``` --- *Generated by /debug-report - Labels: Type/Bug, Component/Backend*
lmiranda added the Component/BackendType/Bug labels 2026-01-23 22:28:54 +00:00
Author
Owner

Root Cause Identified & Fix Proposed

Problem: The /cmdb-assistant:initial-setup command was generating NETBOX_API_URL without the /api suffix.

  • Generated: https://netbox.hotserv.cloud
  • Should be: https://netbox.hotserv.cloud/api

The validation test in the setup wizard incorrectly appended /api/ to the URL, making it pass even though the saved config was wrong. The actual MCP server then failed because it used the URL as-is.

Fix: PR #132 updates the setup wizard to:

  1. Show correct example URL with /api suffix
  2. Add instruction to auto-append /api if user forgets
  3. Fix validation test to be consistent with actual usage

Immediate Workaround: Edit ~/.config/claude/netbox.env and append /api to NETBOX_API_URL.


Investigated via /debug-review

## Root Cause Identified & Fix Proposed **Problem:** The `/cmdb-assistant:initial-setup` command was generating `NETBOX_API_URL` without the `/api` suffix. - Generated: `https://netbox.hotserv.cloud` - Should be: `https://netbox.hotserv.cloud/api` The validation test in the setup wizard incorrectly appended `/api/` to the URL, making it pass even though the saved config was wrong. The actual MCP server then failed because it used the URL as-is. **Fix:** PR #132 updates the setup wizard to: 1. Show correct example URL with `/api` suffix 2. Add instruction to auto-append `/api` if user forgets 3. Fix validation test to be consistent with actual usage **Immediate Workaround:** Edit `~/.config/claude/netbox.env` and append `/api` to `NETBOX_API_URL`. --- *Investigated via /debug-review*
Author
Owner

Fix merged via PR #132. Closing issue.

Lesson learned captured: Setup Wizard URL Format Mismatch

Fix merged via PR #132. Closing issue. **Lesson learned captured:** [Setup Wizard URL Format Mismatch](https://gitea.hotserv.cloud/personal-projects/leo-claude-mktplace/wiki/lessons%2Fpatterns%2Fsetup-wizard-url-format-mismatch.-)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: personal-projects/leo-claude-mktplace#126