Skip to content

fix: update GraphQL queries for Unraid API v4.21.0+#3

Open
abra5umente wants to merge 1 commit intojmagar:mainfrom
abra5umente:fix/graphql-schema-v4.21
Open

fix: update GraphQL queries for Unraid API v4.21.0+#3
abra5umente wants to merge 1 commit intojmagar:mainfrom
abra5umente:fix/graphql-schema-v4.21

Conversation

@abra5umente
Copy link
Copy Markdown

@abra5umente abra5umente commented Dec 8, 2025

Summary

Updates GraphQL queries to work with modern Unraid API schema (v4.21.0+, Unraid 7.1.4+).

  • Fix get_system_info query validation errors by removing deprecated fields and updating schema structure
  • Add new get_metrics tool for real-time CPU and memory utilization
  • Fix health_check query to remove deprecated version field

Changes

get_system_info query fixes:

  • Remove deprecated codepage field (replaced by codename)
  • Remove deprecated apps field (removed from schema)
  • Fix case sensitivity: speedMin/speedMaxspeedmin/speedmax, vendorName/productNamevendorname/productname
  • Update versions structure: now core { unraid api kernel } + packages { ... }
  • Remove memory stats from info query (moved to metrics)

New get_metrics tool:

  • Queries the new metrics endpoint for real-time utilization data
  • CPU: overall usage %, per-core stats (CpuLoad objects with user/system/idle breakdown)
  • Memory: total/used/free/available, swap stats, usage percentages

health_check fix:

  • Remove deprecated versions { unraid } field

Test plan

  • Verify get_system_info returns valid data without GraphQL errors
  • Verify new get_metrics tool returns CPU and memory utilization
  • Verify health_check completes without errors

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added real-time system metrics reporting for CPU, memory, and swap utilization.
    • Expanded system information surface with detailed API, kernel, and software version data, plus PCI device details.
  • Updates

    • Updated compatibility for Unraid API v4.21.0+ with removal of deprecated fields.

✏️ Tip: You can customize this high-level summary in your review settings.

Update queries to match modern Unraid API schema (v4.21.0+, Unraid 7.1.4+):

**get_system_info:**
- Remove deprecated fields: codepage (use codename), apps (removed)
- Fix case sensitivity: speedmin/speedmax, vendorname/productname
- Update versions structure: core.{unraid,api,kernel}, packages.*
- Remove memory stats (moved to metrics query)

**get_metrics (new tool):**
- Add new tool for real-time CPU and memory utilization
- Query metrics.cpu for overall and per-core usage (CpuLoad objects)
- Query metrics.memory for RAM and swap stats

**health_check:**
- Remove deprecated versions.unraid field

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 8, 2025

📝 Walkthrough

Walkthrough

The changes remove deprecated Unraid version field from health.py and restructure system information retrieval in system.py to align with Unraid API v4.21.0+. A new get_metrics() tool is added to expose real-time system metrics for CPU, memory, and swap data.

Changes

Cohort / File(s) Change Summary
API v4.21.0+ Compatibility
unraid_mcp/tools/health.py, unraid_mcp/tools/system.py
Removed deprecated versions.unraid field from GraphQL queries; restructured system info payload with new nested core/packages versioning and summary fields (unraid_version, api_version, kernel_version, software_versions).
New Metrics Tool
unraid_mcp/tools/system.py
Added get_metrics() tool function and _get_metrics() helper to fetch and format real-time CPU, memory, and swap metrics; registered in system tools registry.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • High-complexity areas requiring attention:
    • system.py: Verify the GraphQL query restructuring correctly maps to Unraid API v4.21.0+ response shape and that the new summary fields are accurately extracted.
    • system.py: Validate metrics formatting logic (CPU/memory/swap human-readable output) for correctness and edge cases.
    • Both files: Confirm deprecation of versions.unraid field and backward compatibility approach if clients still reference it.

Poem

🐰 The API hops forward to v4.21's delight,
Old metrics retire, new data takes flight,
With CPU and memory dancing in sight,
The Unraid rabbit bounds ever more bright! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: updating GraphQL queries to be compatible with Unraid API v4.21.0+, which is the core objective across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 90.91% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
unraid_mcp/tools/health.py (1)

150-155: Pre-existing bug: Latency threshold conditions are in wrong order.

The elif branch for > 10000 is unreachable because any value exceeding 10000 also exceeds 5000, triggering the first branch. A 12-second latency would be marked "warning" instead of "degraded".

This isn't introduced by this PR, but consider fixing while you're updating this file:

-            if api_latency > 5000:  # > 5 seconds
-                health_status = "warning"
-                issues.append(f"High API latency: {api_latency}ms")
-            elif api_latency > 10000:  # > 10 seconds
-                health_status = "degraded"
-                issues.append(f"Very high API latency: {api_latency}ms")
+            if api_latency > 10000:  # > 10 seconds
+                health_status = "degraded"
+                issues.append(f"Very high API latency: {api_latency}ms")
+            elif api_latency > 5000:  # > 5 seconds
+                health_status = "warning"
+                issues.append(f"High API latency: {api_latency}ms")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 67b775a and 510adf8.

📒 Files selected for processing (2)
  • unraid_mcp/tools/health.py (1 hunks)
  • unraid_mcp/tools/system.py (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
unraid_mcp/tools/system.py (3)
unraid_mcp/core/client.py (1)
  • make_graphql_request (51-133)
unraid_mcp/core/exceptions.py (1)
  • ToolError (10-18)
unraid_mcp/tools/storage.py (1)
  • format_bytes (241-249)
🪛 Ruff (0.14.7)
unraid_mcp/tools/system.py

252-252: Abstract raise to an inner function

(TRY301)


252-252: Avoid specifying long messages outside the exception class

(TRY003)


255-255: Dynamically typed expressions (typing.Any) are disallowed in b

(ANN401)


304-304: Consider moving this statement to an else block

(TRY300)


308-308: Avoid specifying long messages outside the exception class

(TRY003)


308-308: Use explicit conversion flag

Replace with conversion flag

(RUF010)

🔇 Additional comments (6)
unraid_mcp/tools/health.py (1)

35-36: LGTM on the API compatibility update.

The comments correctly document the removal of the deprecated versions.unraid field for Unraid API v4.21.0+ compatibility.

unraid_mcp/tools/system.py (5)

20-24: Good documentation of API schema changes.

These comments provide helpful context for future maintainers about the Unraid API v4.21.0+ migration.


30-32: Verify the memory id field is sufficient.

The query now only fetches memory { id }. Per the comment at line 24, memory stats moved to the metrics query, but confirm this minimal query still returns a valid response (some GraphQL schemas require at least one scalar field).


69-80: LGTM on versions processing.

The code correctly handles the new nested versions.core and versions.packages structure with proper null-safe access patterns.


272-283: LGTM on CPU metrics processing.

Good defensive checks with isinstance(cpus, list) and isinstance(c, dict). The fallback to "N/A" handles edge cases appropriately.


328-331: LGTM on the new get_metrics tool registration.

Follows the established pattern and the docstring clearly describes the tool's capabilities.

@abra5umente abra5umente closed this Dec 8, 2025
@abra5umente abra5umente deleted the fix/graphql-schema-v4.21 branch December 8, 2025 10:55
@abra5umente abra5umente restored the fix/graphql-schema-v4.21 branch December 8, 2025 10:55
@abra5umente abra5umente reopened this Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant