🧠 Talking to Routers with AI


1. Introduction

Modern infrastructure is programmable, but not always intelligent.

Networking, in particular lives in a world of:
- Manual SSH sessions
- Vendor-specific CLI commands
- Fragmented automation scripts
- Human-heavy workflows

Even today, managing routers often looks like this:

ssh admin@router
show ip route
show running-config

That works, but it does not scale well when you want AI-assisted operations.

🚧 The Problem

AI models:
- Do not natively understand SSH
- Cannot directly execute CLI commands
- Do not automatically keep router/session context
- Need custom glue code every time

So each integration becomes:
- Hardcoded
- Non-reusable
- Difficult to maintain at scale

In simple terms: AI is smart at reasoning, but it still needs a safe, structured bridge to act on real systems.


💡 Enter MCP (Model Context Protocol)

MCP is a standardized protocol that lets AI systems interact with external tools and systems in a structured, reliable way.

Instead of writing one-off integrations for every use case, MCP lets you:
- Expose capabilities as tools
- Let AI discover and call those tools
- Keep a clean separation between AI logic and infrastructure logic

Think of it as a universal adapter between natural language and real-world operations.


🚀 What I Built

To explore MCP in a realistic networking workflow, I built:

A custom MCP server that connects to routers and enables conversational interaction

This makes workflows possible like:

"Show me all routes going through 10.0.0.1"
"Which interfaces are down on R1?"
"Give me the running config of the edge router"


2. What is MCP (Model Context Protocol)?

At a high level, MCP is:

🧩 A standardized interface between AI and external systems

It defines how tools are described, how requests are sent, and how responses come back in machine-friendly formats.

🔑 Core Concepts

1. MCP Client

The AI system (for example: ChatGPT, Codex or any local agent):
- Understands user intent
- Chooses the right tool
- Interprets the returned data

2. MCP Server

Your integration layer:
- Exposes tools
- Executes backend logic (SSH/API/scripts)
- Returns structured results

3. Tools

Tools are callable functions the AI can use.

Examples:
- read_file
- get_weather
- show_ip_route (networking example)

4. Context Exchange

MCP standardizes:
- Request format
- Response format
- Session/tool context flow

This consistency is exactly what makes integrations reusable.

Instead of guessing how to use each system, AI gets clear tool definitions and predictable inputs/outputs.


3. Why MCP Matters

✅ Standardization

Avoid building a new custom integration every time.

🔌 Plug-and-Play AI

Add new capabilities by exposing new tools, without retraining the model.

🔄 Decoupling

AI does not need to understand:
- SSH internals
- API details
- Vendor-specific quirks

🏢 Enterprise Readiness

  • Reusable integration patterns
  • Safer abstraction layers
  • Better operational scalability

4. MCP in Action (Simple Example)

Let us start with a basic tool: read a file.

📌 Tool Definition

{
  "name": "read_file",
  "description": "Read contents of a file",
  "input_schema": {
    "type": "object",
    "properties": {
      "path": { "type": "string" }
    },
    "required": ["path"]
  }
}

📥 Request

{
  "tool": "read_file",
  "arguments": {
    "path": "/etc/hosts"
  }
}

📤 Response

{
  "content": "127.0.0.1 localhost"
}

🧩 What Happened?

  1. AI needed file content.
  2. It selected read_file from available tools.
  3. MCP server executed the logic.
  4. It returned structured output the AI can reason on.

The same pattern scales from small utilities to network operations.


5. 🚀 My Custom MCP Server for Routers

This is the core implementation.

5.1 Problem Statement

Router automation is complex because:

CLI Complexity

Different vendors use different commands:
- Cisco: show ip route
- Juniper: show route

SSH-Driven Workflows

You must handle:
- Session lifecycle
- Authentication
- Retries/timeouts

Unstructured Output

Gig0/1 is down, line protocol is down

Raw CLI is human-readable, but hard for AI to analyze reliably.

No Conversational Layer

Operators cannot directly ask:

"What is broken in my network right now?"


5.2 My MCP Server Approach

I built a Python MCP server that:

🔌 1. Connects to Routers

Using:
- SSH (Paramiko / Netmiko)
- Optional APIs when available

🧩 2. Exposes Router Capabilities as Tools

Example tools:

{
  "name": "show_ip_route",
  "description": "Get routing table from router"
}
{
  "name": "check_interfaces",
  "description": "Get interface status"
}

🧠 3. Enables Natural Language Interaction

User:

"Which interfaces are down on core router?"

AI flow:
- Maps query to check_interfaces
- Calls MCP server
- Applies filters and formatting

🔄 4. Returns Structured Data

Instead of returning only raw CLI:

Gig0/1 is down
Gig0/2 is up

Return normalized JSON:

{
  "interfaces": [
    { "name": "Gig0/1", "status": "down" },
    { "name": "Gig0/2", "status": "up" }
  ]
}

This makes downstream reasoning, alerting, and automation much easier.


5.3 🔧 MCP Configuration (Important)

Example config.toml:

[mcp_servers.network_fetch]
command = "/Users/akhilsudhakaran/venv/bin/python"
args = ["./fetch_mcp_server.py"]

🔍 Explanation

mcp_servers.network_fetch

  • Registers an MCP server named network_fetch.

command

command = "/Users/aksudhak/venv/bin/python"
  • Uses a dedicated virtual environment interpreter.
  • Helps guarantee dependency consistency.

args

args = ["./fetch_mcp_server.py"]
  • Launches your MCP server entry script.
  • That script registers tools and handles tool requests.

🧠 Why This Matters

This setup provides:
- Reproducibility
- Environment isolation
- Cleaner operations across machines


5.4 🔄 End-to-End Flow

🗣️ User Query

"Show me the routing table on edge router"

⚙️ Execution Flow

  1. MCP client (AI) selects show_ip_route.
  2. MCP server opens SSH session.
  3. Server runs:
    bash show ip route
  4. Output is parsed and normalized.
  5. Structured JSON is returned to AI.

📤 Example Output

{
  "routes": [
    {
      "network": "0.0.0.0/0",
      "next_hop": "10.0.0.1",
      "protocol": "static"
    },
    {
      "network": "192.168.1.0/24",
      "next_hop": "connected",
      "protocol": "connected"
    }
  ]
}

6. 🔐 Design Considerations

Security

  • Use secret managers or vaults for credentials
  • Apply role-based access control (RBAC)
  • Restrict allowed commands per tool

Parsing

  • Convert CLI output to JSON
  • Normalize fields across vendors

Performance

  • Reuse SSH connections where possible
  • Cache safe read-heavy responses

Extensibility

  • Add new tools without changing core AI behavior

7. Key Takeaways

  • MCP enables standardized AI-to-system integrations.
  • Your MCP server acts as a capability layer.
  • Structured outputs are critical for reliable reasoning.
  • Networking workflows become AI-accessible.

🚀 Final Thought

With MCP and a custom router server, we move from:

show ip route

to:

💬 "How is my network routing traffic right now?"

That is AI Network Infrastructure.