Examples¶
This page provides real-world examples of using the Nautobot MCP Server with GitHub Copilot.
Basic Examples¶
Example 1: Discovering API Endpoints¶
Scenario: You want to find endpoints related to IP address management.
Query to Copilot:
What Happens:
- Copilot uses
nautobot_openapi_api_request_schematool - Semantic search finds relevant endpoints
- Returns ranked list with descriptions
Expected Response:
I found several endpoints for IP address management:
1. GET /api/ipam/ip-addresses/
List all IP addresses
2. POST /api/ipam/ip-addresses/
Create a new IP address
3. GET /api/ipam/ip-addresses/{id}/
Retrieve a specific IP address
4. PATCH /api/ipam/ip-addresses/{id}/
Update an IP address
5. DELETE /api/ipam/ip-addresses/{id}/
Delete an IP address
Example 2: Querying Nautobot Data¶
Scenario: You need to see all active devices in a specific location.
Query to Copilot:
What Happens:
- Copilot uses
nautobot_dynamic_api_requesttool - Constructs GET request with filters
- Executes against your Nautobot instance
- Formats response
Expected Response:
Found 15 active devices in Main DC:
1. core-switch-01 (Cisco Catalyst 9300)
2. core-switch-02 (Cisco Catalyst 9300)
3. access-switch-01 (Cisco Catalyst 2960)
...
Example 3: Knowledge Base Search¶
Scenario: You want to learn about Nautobot jobs.
Query to Copilot:
What Happens:
- Copilot uses
nautobot_kb_semantic_searchtool - Searches indexed documentation and code
- Returns relevant sections with sources
Expected Response:
Based on the Nautobot documentation, here's how to create a custom job:
1. Create a job class inheriting from `Job`:
```python
from nautobot.extras.jobs import Job
class MyCustomJob(Job):
class Meta:
name = "My Custom Job"
description = "Description of what this job does"
def run(self, *args, **kwargs):
# Your job logic here
self.logger.info("Job is running")
- Place the file in your app's
jobs.pyor jobs directory - Register it in Nautobot
Source: nautobot/nautobot/docs/user-guides/jobs.md
---
## Intermediate Examples
### Example 4: Creating Resources
**Scenario:** Create a new device in Nautobot.
**Query to Copilot:**
**What Happens:**
1. Copilot finds the appropriate endpoint
2. Constructs POST request with required fields
3. Executes the API call
4. Returns the created resource
**Expected Interaction:**
Using POST /api/dcim/devices/ with the following data: { "name": "test-switch-01", "device_type": "cisco-catalyst-3850", "location": "main-dc", "status": "active" }
✅ Device created successfully! ID: 12345 Name: test-switch-01 Status: active Location: Main DC
---
### Example 5: Updating Resources
**Scenario:** Change a device's status to maintenance mode.
**Query to Copilot:**
**What Happens:**
1. Query device to get ID
2. Use PATCH to update status
3. Confirm the change
**Expected Response:**
Step 1: Finding device ID... Found: core-switch-01 (ID: 789)
Step 2: Updating status to maintenance... PATCH /api/dcim/devices/789/
✅ Status updated successfully! Device: core-switch-01 Previous Status: active New Status: maintenance
---
### Example 6: Complex Queries with Filters
**Scenario:** Find all Cisco switches in active status across all locations.
**Query to Copilot:**
**What Happens:**
1. Query devices with manufacturer and status filters
2. Group results by location
3. Format output
**Expected Response:**
Main DC (15 switches): - core-switch-01 (Catalyst 9300) - core-switch-02 (Catalyst 9300) - access-switch-01 (Catalyst 2960) ...
Branch Office 1 (6 switches): - branch1-switch-01 (Catalyst 2960) ...
Branch Office 2 (3 switches): - branch2-switch-01 (Catalyst 2960) ...
---
## Advanced Examples
### Example 7: Multi-Step Workflow
**Scenario:** Onboard a new device with IP assignment.
**Query to Copilot:**
Step 1: Creating device... POST /api/dcim/devices/ ✅ Device created (ID: 1001)
Step 2: Creating interface... POST /api/dcim/interfaces/ { "device": 1001, "name": "GigabitEthernet1/0/1", "type": "1000base-t" } ✅ Interface created (ID: 5001)
Step 3: Assigning IP address... POST /api/ipam/ip-addresses/ { "address": "192.168.1.10/24", "assigned_object_type": "dcim.interface", "assigned_object_id": 5001 } ✅ IP address assigned
Summary: - Device: new-switch-01 (ID: 1001) - Interface: GigabitEthernet1/0/1 (ID: 5001) - IP: 192.168.1.10/24
Device onboarding complete!
---
### Example 8: Data Validation
**Scenario:** Validate device configuration before deployment.
**Query to Copilot:**
**What Happens:**
1. Fetch device details
2. Validate each requirement
3. Report findings
**Expected Response:**
✅ Device Role: core-switch (Valid) ❌ Power Connections: 1 found, 2 required ✅ Primary IP: 10.0.0.1 (Assigned)
Validation Result: 2/3 checks passed
Recommendation: Add a second power connection to meet requirements.
---
### Example 9: Documentation Research
**Scenario:** Research before implementing a feature.
**Query to Copilot:**
**What Happens:**
1. Search knowledge base for GraphQL docs
2. Find authentication patterns
3. Locate example code
**Expected Response:**
Documentation:¶
The GraphQL API is available at /api/graphql/ and provides a flexible way to query Nautobot data... (Source: nautobot/nautobot/docs/user-guides/graphql.md)
Authentication:¶
GraphQL uses the same token authentication as the REST API:
(Source: nautobot/nautobot/docs/user-guides/graphql.md)Example Query:¶
query {
devices(name: "core-switch-01") {
id
name
device_type {
model
manufacturer {
name
}
}
location {
name
}
}
}
Python Example:¶
import requests
url = "http://nautobot/api/graphql/"
headers = {"Authorization": "Token your-token"}
query = """
{
devices {
name
status
}
}
"""
response = requests.post(url, json={"query": query}, headers=headers)
---
### Example 10: Repository Management
**Scenario:** Add custom plugin to knowledge base.
**Query to Copilot:**
**What Happens:**
1. Copilot uses `nautobot_kb_add_repo` tool
2. Repository is cloned
3. Content is indexed
4. Confirms completion
**Expected Response:**
Adding: myorg/nautobot-custom-plugin Cloning repository... ✓ Indexing files... ✓ Creating embeddings... ✓
Repository added successfully! - Documents indexed: 45 - File types: .py, .md, .rst - Time taken: 32s
You can now search this repository's content using knowledge base queries.
---
## Integration Examples
### Example 11: VS Code Workflow
**Scenario:** Using MCP while developing code.
**In VS Code:**
1. **Write code with inline suggestions:**
```python
# Comment: Get all devices from Nautobot
# Copilot suggests:
import pynautobot
nb = pynautobot.api(url="http://nautobot", token="token")
devices = nb.dcim.devices.all()
```
2. **Ask in Chat:**
```
What's the correct way to filter devices by location in pynautobot?
```
3. **Get contextual help:**
```
Copilot searches knowledge base and returns:
devices = nb.dcim.devices.filter(location="main-dc")
# Or using location ID:
devices = nb.dcim.devices.filter(location_id="uuid-here")
(Source: pynautobot documentation)
```
---
### Example 12: Testing API Endpoints
**Scenario:** Test an endpoint before using it in code.
**Query:**
Response (200 OK):
{
"count": 150,
"next": "http://nautobot/api/dcim/devices/?limit=3&offset=3",
"previous": null,
"results": [
{
"id": "uuid1",
"name": "core-switch-01",
"device_type": {...},
"location": {...},
"status": "active",
"primary_ip": {...}
},
// ... 2 more devices
]
}
The response structure shows: - Pagination info (count, next, previous) - Results array with device objects - Each device has id, name, device_type, location, status, primary_ip
---
## Real-World Scenarios
### Scenario 1: Network Audit
**Task:** Audit all devices for compliance.
**Queries:**
Tips for Effective Use¶
Be Specific¶
❌ "Tell me about devices" ✅ "Show me all Cisco devices in active status with their IP addresses"
Provide Context¶
❌ "Create a device" ✅ "Create a device named 'switch-01', type 'cisco-3850', in 'Main DC', status 'active'"
Chain Operations¶
❌ Multiple separate queries ✅ "First find the location ID for 'Main DC', then create a device in that location"
Verify Before Destructive Operations¶
Always review before: - DELETE operations - Bulk updates - Production changes
Next Steps¶
- Tools Reference - Detailed tool documentation
- Troubleshooting - Common issues
- Architecture - How it works