https://github.com/netboxlabs/netbox-mcp-server
Model Context Protocol (MCP) server for read-only interaction with NetBox data in LLMs
https://github.com/netboxlabs/netbox-mcp-server
mcp mcp-server netbox
Last synced: 4 months ago
JSON representation
Model Context Protocol (MCP) server for read-only interaction with NetBox data in LLMs
- Host: GitHub
- URL: https://github.com/netboxlabs/netbox-mcp-server
- Owner: netboxlabs
- License: apache-2.0
- Created: 2025-02-27T16:51:50.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-05-19T21:55:38.000Z (6 months ago)
- Last Synced: 2025-06-06T08:34:16.862Z (5 months ago)
- Topics: mcp, mcp-server, netbox
- Language: Python
- Homepage: https://netboxlabs.com/
- Size: 47.9 KB
- Stars: 41
- Watchers: 9
- Forks: 14
- Open Issues: 6
-
Metadata Files:
- Readme: README-client.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-mcp-servers - **netbox-mcp-server** - Model Context Protocol (MCP) server for read-only interaction with NetBox data in LLMs `python` `mcp` `mcp-server` `netbox` `server` `pip install git+https://github.com/netboxlabs/netbox-mcp-server` (🤖 AI/ML)
- awesome-mcp-servers - **netbox-mcp-server** - Model Context Protocol (MCP) server for read-only interaction with NetBox data in LLMs `python` `mcp` `mcp-server` `netbox` `server` `pip install git+https://github.com/netboxlabs/netbox-mcp-server` (AI/ML)
README
# NetBox Client Library
A Python client library for interacting with NetBox, providing both a base abstract class and a REST API implementation.
## Features
- Abstract base class with generic CRUD methods
- REST API implementation of the base class
- Support for both single and bulk operations
- Designed to be extensible for ORM-based implementations
## Installation
```bash
pip install -r requirements.txt
```
## Usage
### REST API Client
```python
from client import NetBoxRestClient
# Initialize the client
client = NetBoxRestClient(
url="https://netbox.example.com",
token="your_api_token_here",
verify_ssl=True
)
# Get all sites
sites = client.get("dcim/sites")
print(f"Found {len(sites)} sites")
# Get a specific site
site = client.get("dcim/sites", id=1)
print(f"Site name: {site.get('name')}")
# Example with pagination
# Get sites page by page
page = 1
limit = 50
while True:
sites_page = client.get("dcim/sites", params={
"limit": limit,
"offset": (page - 1) * limit
})
if not sites_page:
break
print(f"Processing page {page} with {len(sites_page)} sites")
for site in sites_page:
print(f"Site: {site.get('name')}")
page += 1
# Create a new site
new_site = client.create("dcim/sites", {
"name": "New Site",
"slug": "new-site",
"status": "active"
})
print(f"Created site: {new_site.get('name')} (ID: {new_site.get('id')})")
# Update a site
updated_site = client.update("dcim/sites", id=1, data={
"description": "Updated description"
})
# Delete a site
success = client.delete("dcim/sites", id=1)
if success:
print("Site deleted successfully")
# Bulk operations
new_sites = client.bulk_create("dcim/sites", [
{"name": "Site 1", "slug": "site-1", "status": "active"},
{"name": "Site 2", "slug": "site-2", "status": "active"}
])
updated_sites = client.bulk_update("dcim/sites", [
{"id": 1, "description": "Updated description 1"},
{"id": 2, "description": "Updated description 2"}
])
success = client.bulk_delete("dcim/sites", ids=[1, 2])
```
## Extending for ORM Implementation
The `NetBoxClientBase` abstract base class can be extended to create an ORM-based implementation for use within a NetBox plugin:
```python
from client import NetBoxClientBase
from django.db import transaction
class NetBoxOrmClient(NetBoxClientBase):
"""
NetBox client implementation using the ORM directly.
This would be used within a NetBox plugin.
"""
def __init__(self):
# No authentication needed as this would run within NetBox
pass
def get(self, endpoint, id=None, params=None):
# Implementation would use Django ORM to fetch objects
# Example (not implemented)
pass
# Other methods would be implemented similarly
```
## License
MIT