Skip to content

Instantly share code, notes, and snippets.

@craigarms
Created November 21, 2025 15:33
Show Gist options
  • Select an option

  • Save craigarms/0172d63f404f117020cd7f0ad7671627 to your computer and use it in GitHub Desktop.

Select an option

Save craigarms/0172d63f404f117020cd7f0ad7671627 to your computer and use it in GitHub Desktop.
# Import the FastMCP module
from mcp.server.fastmcp import FastMCP
# Import the Needed Netmiko modules
from netmiko import (
ConnectHandler,
NetmikoTimeoutException,
NetmikoAuthenticationException,
)
# Create an instance of the FastMCP Class
# Which creates the server
mcp = FastMCP(
name="Network Access and Configuration Tool",
stateless_http=True,
)
# Hardcode the credentials, that I don't use except for in labs
username = 'admin'
password = 'cisco'
# Create the actual tool that Claude can use
@mcp.tool()
def send_show_command(device: str, commands: list[str]) -> dict:
"""
This command sends a list of commands to a device
and returns the output.
Device argument should be the Management IP address of the device.
Commands argument should be a list of commands to send to the device.
"""
# Same as the interactive test, just variabilized for reuse
remote_device = {'device_type': 'cisco_ios',
'host': device,
'username': username,
'password': password}
# Since the commands is a list of commands we'll cycle through them
# And create a dictionary with the response
result = {}
try:
with ConnectHandler(**remote_device) as ssh:
ssh.enable()
for command in commands:
output = ssh.send_command(command)
result[command] = output
return result
except (NetmikoTimeoutException,
NetmikoAuthenticationException) as error:
return {"error": str(error)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment