Cisco NX-OS CLI MCP Server

Cisco NX-OS CLI MCP Server

Enables interaction with Cisco NX-OS devices through CLI commands via NX-API. Supports single and multi-device command execution with text or JSON output, authentication from .env, and comprehensive error handling.

Category
访问服务器

README

Cisco NX-OS CLI MCP Server

A Model Context Protocol (MCP) server that lets you interact with Cisco NX-OS devices. You can send arbitrary CLI commands to one or more switches via their NX-API interface. This server exposes MCP tools for executing commands on one or more devices with comprehensive error handling. The output format can also be selected (text or JSON).

Features

  • Single Device Commands: Execute CLI commands on individual NX-OS switches
  • Multi-Device Commands: Execute the same commands across multiple switches concurrently
  • Text-Based I/O: Commands are sent as text (cli_show_ascii), responses default to text format
  • JSON Option: Optional JSON response format for structured parsing
  • Simple Authentication: Credentials collected from .env file or on a per-request override
  • Error Handling: Clear, actionable error messages
  • Batch Operations: Execute up to 100 commands per request
  • Concurrent Execution: Parallel command execution on multiple devices (up to 50)

Requirements

  • Python 3.10 or higher
  • Cisco NX-OS devices with NX-API enabled (feature nxapi)
  • Network connectivity between the MCP host (Claude Desktop, etc.) to target devices via HTTPS

Installation

Prerequisites

  • Python 3.10 or higher
  • uv - Fast Python package installer (recommended)
  • Cisco NX-OS devices with NX-API enabled (feature nxapi)
  • Network connectivity to target devices via HTTPS

Setup

  1. Install uv (if not already installed):
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
  1. Install dependencies using uv:
# With uv and pyproject.toml (recommended)
uv sync
  1. Set up authentication credentials:

Create a .env file from the template:

cp .env.example .env

Edit .env and add your credentials:

NXOS_USERNAME=admin
NXOS_PASSWORD=your_secure_password

Important: Never commit your production .env file to version control. .gitignore is configured to prevent this but be cautious!

Registering with MCP Hosts

Claude Desktop

macOS:

Edit the Claude Desktop configuration file:

code ~/Library/Application\ Support/Claude/claude_desktop_config.json

Add the NX-OS CLI MCP server to the mcpServers section:

{
  "mcpServers": {
    "nxos-cli": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/nxos-cli-mcp",
        "run",
        "nxos_cli_mcp.py"
      ]
    }
  }
}

Windows:

Edit the Claude Desktop configuration file:

notepad %APPDATA%\Claude\claude_desktop_config.json

Add the NX-OS CLI MCP server to the mcpServers section:

{
  "mcpServers": {
    "nxos-cli": {
      "command": "uv",
      "args": [
        "--directory",
        "C:\\absolute\\path\\to\\nxos-cli-mcp",
        "run",
        "nxos_cli_mcp.py"
      ]
    }
  }
}

After saving, restart Claude Desktop for the changes to take effect.

Visual Studio Code

macOS:

Edit the VS Code MCP settings file:

code ~/Library/Application\ Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json

Add the server configuration:

{
  "mcpServers": {
    "nxos-cli": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/nxos-cli-mcp",
        "run",
        "nxos_cli_mcp.py"
      ]
    }
  }
}

Windows:

Edit the VS Code MCP settings file:

notepad %APPDATA%\Code\User\globalStorage\rooveterinaryinc.roo-cline\settings\cline_mcp_settings.json

Add the server configuration:

{
  "mcpServers": {
    "nxos-cli": {
      "command": "uv",
      "args": [
        "--directory",
        "C:\\absolute\\path\\to\\nxos-cli-mcp",
        "run",
        "nxos_cli_mcp.py"
      ]
    }
  }
}

After saving, reload the VS Code window (Command/Ctrl + Shift + P → "Developer: Reload Window").

Important Notes:

  • Replace /absolute/path/to/nxos-cli-mcp (or C:\absolute\path\to\nxos-cli-mcp) with the actual full path to your project directory
  • Ensure the .env file with your credentials is in the project directory
  • The server will automatically load credentials from the .env file when started by the MCP client

Available Tools

1. nxos_execute_commands

Execute CLI commands on a single NX-OS device.

Parameters:

  • ip_address (required): IP address or hostname of the device
  • commands (required): List of CLI commands to execute
  • response_format (optional): "text" (default, human-readable) or "json" (structured data)
  • username (optional): Username for authentication
  • password (optional): Password for authentication
  • timeout (optional): Request timeout in seconds (default: 30)

2. nxos_execute_commands_multi

Execute the same CLI commands on multiple NX-OS devices concurrently.

Parameters:

  • ip_addresses (required): List of device IP addresses or hostnames (max 50)
  • commands (required): List of CLI commands to execute on all devices
  • response_format (optional): "text" (default, human-readable) or "json" (structured data)
  • username (optional): Username for authentication
  • password (optional): Password for authentication
  • timeout (optional): Request timeout in seconds per device (default: 30)
  • continue_on_error (optional): Continue executing on other devices if one fails (default: true)

NX-API Configuration

Before using this MCP server, ensure NX-API is enabled on your NX-OS devices:

configure terminal
feature nxapi
nxapi http port 80
nxapi https port 443

Verify NX-API is running:

show nxapi

Security Considerations

  1. Credentials: Store credentials in the .env file, never commit the file to version control
  2. File Permissions: Ensure .env has restricted permissions (chmod 600 .env on Unix systems)
  3. HTTPS: This MCP server talks HTTPS to NX-API (with verification disabled for self-signed certificates; change this for production!)

Output Formats

How Commands Are Sent

All commands are sent to NX-OS devices as text using the cli_show_ascii API type. This ensures consistent behavior with the CLI experience you're familiar with.

Response Formats

  • text (default): Plain text output, identical to what you see in a CLI session

    • Easy to read in Claude Desktop or VS Code
    • Preserves formatting from the device
    • Best for interactive use
  • json: Structured JSON response with detailed metadata, possibly better for MCP Hosts (experiment)

    • Includes success/failure status per device
    • Command execution results
    • Error details when applicable
    • Useful for programmatic parsing or complex workflows

Error Handling

The server provides detailed error messages for common scenarios:

  • Authentication Failures: "Authentication failed. Check username and password."
  • Permission Denied: "Permission denied. User may not have sufficient privileges."
  • NX-API Not Found: "NX-API endpoint not found. Verify the device supports NX-API."
  • Timeouts: "Request timed out after X seconds"
  • Command Errors: Includes command-specific error codes and messages from NX-OS

Limitations

  • Maximum 50 devices per multi-device command execution
  • Maximum 100 commands per request
  • Timeout range: 1-300 seconds
  • SSL certificate verification is disabled (assumes self-signed certificates), change this in production!

Troubleshooting

Connection Refused

  • Verify NX-API is enabled on the device: show nxapi
  • Check network connectivity: ping <device-ip>
  • Verify HTTPS port is accessible (default: 443)

Authentication Failed

  • Verify credentials in .env file are correct
  • Check .env file exists in the project root directory
  • Ensure .env file has proper format (no spaces around =)
  • Verify the user account exists on the device
  • Test credentials by SSH'ing to the device

Command Execution Errors

  • Verify command syntax is correct for NX-OS
  • Check user has sufficient privileges for the command
  • Review NX-OS command output for specific error details

Timeout Issues

  • Increase the timeout parameter for slow commands
  • Check network latency to devices
  • Consider splitting large command batches

Testing

Run with MCP Inspector

npx @modelcontextprotocol/inspector uv run nxos_cli_mcp.py

License

This MCP server is provided as-is under the MIT license.

Contributing

Contributions are welcome! Please ensure:

  • Code follows existing patterns and conventions
  • All functions have comprehensive docstrings
  • Input validation is handled by Pydantic models
  • Error messages are clear and actionable

Support

For issues related to:

  • NX-API: Consult Cisco NX-OS documentation
  • MCP Protocol: Visit https://modelcontextprotocol.io
  • This Server: Review error messages and troubleshooting section

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选