Skip to content

Commit 80b51fb

Browse files
authored
Merge pull request #45 from netboxlabs/support_brief
feat(tools): add support for brief to netbox_get_objects and netbox_get_object_by_id
2 parents 3a3f6f9 + b69c717 commit 80b51fb

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

server.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def netbox_get_objects(
269269
object_type: str,
270270
filters: dict,
271271
fields: list[str] | None = None,
272+
brief: bool = False,
272273
limit: Annotated[int, Field(default=5, ge=1, le=100)] = 5,
273274
offset: Annotated[int, Field(default=0, ge=0)] = 0,
274275
ordering: str | list[str] | None = None,
@@ -307,6 +308,9 @@ def netbox_get_objects(
307308
Uses NetBox's native field filtering via ?fields= parameter.
308309
**Always specify only the fields you actually need.**
309310
311+
brief: returns only a minimal representation of each object in the response.
312+
This is useful when you need only a list of available objects without any related data.
313+
310314
limit: Maximum results to return (default 5, max 100)
311315
Start with default, increase only if needed
312316
@@ -444,6 +448,9 @@ def netbox_get_objects(
444448
if fields:
445449
params["fields"] = ",".join(fields)
446450

451+
if brief:
452+
params["brief"] = "1"
453+
447454
if ordering:
448455
if isinstance(ordering, list):
449456
ordering = ",".join(ordering)
@@ -456,7 +463,7 @@ def netbox_get_objects(
456463

457464
@mcp.tool
458465
def netbox_get_object_by_id(
459-
object_type: str, object_id: int, fields: list[str] | None = None
466+
object_type: str, object_id: int, fields: list[str] | None = None, brief: bool = False
460467
):
461468
"""
462469
Get detailed information about a specific NetBox object by its ID.
@@ -478,6 +485,8 @@ def netbox_get_object_by_id(
478485
479486
Uses NetBox's native field filtering via ?fields= parameter.
480487
**Always specify only the fields you actually need.**
488+
brief: returns only a minimal representation of the object in the response.
489+
This is useful when you need only a summary of the object without any related data.
481490
482491
Returns:
483492
Object dict (complete or with only requested fields based on fields parameter)
@@ -494,6 +503,9 @@ def netbox_get_object_by_id(
494503
if fields:
495504
params["fields"] = ",".join(fields)
496505

506+
if brief:
507+
params["brief"] = "1"
508+
497509
return netbox.get(endpoint, params=params)
498510

499511

tests/test_brief.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""Tests for brief parameter validation and behavior."""
2+
3+
from unittest.mock import patch
4+
5+
from server import netbox_get_object_by_id, netbox_get_objects
6+
7+
8+
@patch("server.netbox")
9+
def test_brief_false_omits_parameter_get_objects(mock_netbox):
10+
"""When brief=False (default), should not include brief in API params for netbox_get_objects."""
11+
mock_netbox.get.return_value = {"count": 0, "results": [], "next": None, "previous": None}
12+
13+
netbox_get_objects.fn(object_type="sites", filters={}, brief=False)
14+
15+
call_args = mock_netbox.get.call_args
16+
params = call_args[1]["params"]
17+
18+
# brief should not be in params when False
19+
assert "brief" not in params
20+
21+
22+
@patch("server.netbox")
23+
def test_brief_default_omits_parameter_get_objects(mock_netbox):
24+
"""When brief not specified (uses default False), should not include brief in API params."""
25+
mock_netbox.get.return_value = {"count": 0, "results": [], "next": None, "previous": None}
26+
27+
netbox_get_objects.fn(object_type="sites", filters={})
28+
29+
call_args = mock_netbox.get.call_args
30+
params = call_args[1]["params"]
31+
32+
# brief should not be in params when using default
33+
assert "brief" not in params
34+
35+
36+
@patch("server.netbox")
37+
def test_brief_true_includes_parameter_get_objects(mock_netbox):
38+
"""When brief=True, should pass 'brief': '1' to API params for netbox_get_objects."""
39+
mock_netbox.get.return_value = {"count": 0, "results": [], "next": None, "previous": None}
40+
41+
netbox_get_objects.fn(object_type="sites", filters={}, brief=True)
42+
43+
call_args = mock_netbox.get.call_args
44+
params = call_args[1]["params"]
45+
46+
assert params["brief"] == "1"
47+
48+
49+
@patch("server.netbox")
50+
def test_brief_false_omits_parameter_get_by_id(mock_netbox):
51+
"""When brief=False (default), should not include brief in API params for netbox_get_object_by_id."""
52+
mock_netbox.get.return_value = {"id": 1, "name": "Test Site"}
53+
54+
netbox_get_object_by_id.fn(object_type="sites", object_id=1, brief=False)
55+
56+
call_args = mock_netbox.get.call_args
57+
params = call_args[1]["params"]
58+
59+
# brief should not be in params when False
60+
assert "brief" not in params
61+
62+
63+
@patch("server.netbox")
64+
def test_brief_default_omits_parameter_get_by_id(mock_netbox):
65+
"""When brief not specified (uses default False), should not include brief in API params."""
66+
mock_netbox.get.return_value = {"id": 1, "name": "Test Site"}
67+
68+
netbox_get_object_by_id.fn(object_type="sites", object_id=1)
69+
70+
call_args = mock_netbox.get.call_args
71+
params = call_args[1]["params"]
72+
73+
# brief should not be in params when using default
74+
assert "brief" not in params
75+
76+
77+
@patch("server.netbox")
78+
def test_brief_true_includes_parameter_get_by_id(mock_netbox):
79+
"""When brief=True, should pass 'brief': '1' to API params for netbox_get_object_by_id."""
80+
mock_netbox.get.return_value = {"id": 1, "url": "http://example.com/api/dcim/sites/1/"}
81+
82+
netbox_get_object_by_id.fn(object_type="sites", object_id=1, brief=True)
83+
84+
call_args = mock_netbox.get.call_args
85+
params = call_args[1]["params"]
86+
87+
assert params["brief"] == "1"

0 commit comments

Comments
 (0)